Skip to content

Commit

Permalink
Fix SplitHugeSwitchPass off-by-one
Browse files Browse the repository at this point in the history
Summary: The determination to split and the computation of splits should match.

Reviewed By: thezhangwei

Differential Revision: D45091645

fbshipit-source-id: 9179dbfab61cedbeefaae8f139f23e482169b835
  • Loading branch information
agampe authored and facebook-github-bot committed Apr 18, 2023
1 parent e18a3e1 commit f8953b5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
3 changes: 2 additions & 1 deletion opt/split_huge_switches/SplitHugeSwitchPass.cpp
Expand Up @@ -523,7 +523,7 @@ AnalysisData analyze(DexMethod* m,
data.no_code = false;

auto size = code->sum_opcode_sizes();
if (size < insn_threshold) {
if (size <= insn_threshold) {
data.under_insn_threshold = true;
return data;
}
Expand Down Expand Up @@ -555,6 +555,7 @@ AnalysisData analyze(DexMethod* m,
data.no_easy_expr = false;

size_t nr_splits = (size_t)std::ceil(((float)size) / insn_threshold);
redex_assert(nr_splits > 1);
auto switch_range =
get_switch_range(*scoped_cfg, switch_it.block(), nr_splits);
if (switch_range.cases < nr_splits) {
Expand Down
11 changes: 11 additions & 0 deletions test/unit/SplitHugeSwitchTest.cpp
Expand Up @@ -468,3 +468,14 @@ TEST_F(SplitHugeSwitchTest, Split3) {
});
EXPECT_TRUE(res);
}

TEST_F(SplitHugeSwitchTest, NoSplitExactThreshold) {
auto res = test("(I)V",
SRC,
28,
0,
method_profiles::MethodProfiles(),
0.0,
{pair("", SRC)});
EXPECT_TRUE(res);
}

0 comments on commit f8953b5

Please sign in to comment.