Skip to content

Commit

Permalink
taking out "return" statements from aggregation optimization
Browse files Browse the repository at this point in the history
Differential Revision: D62334013

fbshipit-source-id: 10ab17eb8eeb03346d914f8593c4890722cf0a66
  • Loading branch information
Nikolai Tillmann authored and facebook-github-bot committed Sep 11, 2024
1 parent a731fdf commit ecb219e
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 0 deletions.
14 changes: 14 additions & 0 deletions opt/outliner/MethodClosures.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,20 @@ std::shared_ptr<const ReducedControlFlowGraph> reduce_cfg(
DexMethod* method, std::optional<uint64_t> split_block_size) {
auto code = method->get_code();
auto& cfg = code->cfg();
for (auto* block : cfg.blocks()) {
auto* goes_to_block = block->goes_to_only_edge();
if (goes_to_block == nullptr) {
continue;
}
auto first_insn_it = goes_to_block->get_first_insn();
if (first_insn_it == goes_to_block->end()) {
continue;
}
if (opcode::is_a_return(first_insn_it->insn->opcode())) {
block->push_back(new IRInstruction(*first_insn_it->insn));
cfg.delete_succ_edges(block);
}
}
cfg.remove_unreachable_blocks();
if (split_block_size) {
split_blocks(method, cfg, *split_block_size);
Expand Down
88 changes: 88 additions & 0 deletions test/unit/MethodSplittingTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -862,3 +862,91 @@ TEST_F(MethodSplitterTest, DontSplitLoadParamChains) {
ASSERT_EQ(m->get_code()->cfg().blocks().size(), 1);
m->get_code()->clear_cfg();
}

TEST_F(MethodSplitterTest, UndupReturns) {
auto before = R"(
(
(load-param v0)
(add-int v0 v0 v0)
(add-int v0 v0 v0)
(switch v0 (:a :b :c :d))
(:common)
(return v0)
(:a 0)
(add-int v0 v0 v0)
(add-int v0 v0 v0)
(add-int v0 v0 v0)
(add-int v0 v0 v0)
(goto :common)
(:b 1)
(add-int v0 v0 v0)
(add-int v0 v0 v0)
(add-int v0 v0 v0)
(goto :common)
(:c 2)
(add-int v0 v0 v0)
(add-int v0 v0 v0)
(goto :common)
(:d 3)
(add-int v0 v0 v0)
(goto :common)
))";
auto after = R"(
(
(load-param v0)
(add-int v0 v0 v0)
(add-int v0 v0 v0)
(switch v0 (:b :a))
(.pos:dbg_0 "LFoo;.bar:(I)I" RedexGenerated 0)
(invoke-static (v0) "LFoo;.bar$split$cold0:(I)I")
(move-result v0)
(return v0)
(:b 1)
(invoke-static (v0) "LFoo;.bar$split$cold2:(I)I")
(move-result v0)
(return v0)
(:a 0)
(invoke-static (v0) "LFoo;.bar$split$cold1:(I)I")
(move-result v0)
(return v0)
))";
auto split0cd = R"(
(
(load-param v0)
(switch v0 (:d :c))
(return v0)
(:d 3)
(add-int v0 v0 v0)
(return v0)
(:c 2)
(add-int v0 v0 v0)
(add-int v0 v0 v0)
(return v0)
))";
auto split1a = R"(
(
(load-param v0)
(add-int v0 v0 v0)
(add-int v0 v0 v0)
(add-int v0 v0 v0)
(add-int v0 v0 v0)
(return v0)
))";
auto split2b = R"(
(
(load-param v0)
(add-int v0 v0 v0)
(add-int v0 v0 v0)
(add-int v0 v0 v0)
(return v0)
))";
auto res =
test("(I)I",
before,
defaultConfig(),
{std::make_pair<std::string, std::string>("", after),
std::make_pair<std::string, std::string>("split$cold0", split0cd),
std::make_pair<std::string, std::string>("split$cold1", split1a),
std::make_pair<std::string, std::string>("split$cold2", split2b)});
ASSERT_TRUE(res);
}

0 comments on commit ecb219e

Please sign in to comment.