Skip to content

Commit 1e6b9a1

Browse files
wsanvillemeta-codesync[bot]
authored andcommitted
Two new test cases for SwitchEquivFinder
Summary: Further work is needed to make SwitchEquivFinder gracefully handle code like this. Reviewed By: xuhdev Differential Revision: D89733902 fbshipit-source-id: f79383237e5e6986f2d366bf07b9eebfe294d2cb
1 parent 95a7735 commit 1e6b9a1

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

test/unit/SwitchEquivFinderTest.cpp

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1387,3 +1387,72 @@ TEST_F(SwitchEquivFinderTest,
13871387
verify_const_at_block(2, 2);
13881388
verify_const_at_block(3, 3);
13891389
}
1390+
1391+
TEST_F(SwitchEquivFinderTest, test_with_eq_not_constant) {
1392+
setup();
1393+
1394+
auto code = assembler::ircode_from_string(R"(
1395+
(
1396+
(load-param v0)
1397+
1398+
(const-class "LBar;")
1399+
(move-result-pseudo-object v4)
1400+
(invoke-virtual (v4) "Ljava/lang/Object;.hashCode:()I")
1401+
(move-result v2)
1402+
1403+
(const v1 1)
1404+
(if-eq v0 v1 :one)
1405+
1406+
(if-eq v0 v2 :two)
1407+
1408+
(if-eqz v0 :zero)
1409+
1410+
(const v3 999)
1411+
(return v3)
1412+
1413+
(:two)
1414+
(const v3 200)
1415+
(return v3)
1416+
1417+
(:one)
1418+
(const v3 100)
1419+
(return v3)
1420+
1421+
(:zero)
1422+
(const v3 0)
1423+
(return v3)
1424+
)
1425+
)");
1426+
// TODO (T219644020): improve logic and verify this is handled correctly.
1427+
}
1428+
1429+
TEST_F(SwitchEquivFinderTest, ends_with_less_than) {
1430+
setup();
1431+
1432+
auto code = assembler::ircode_from_string(R"(
1433+
(
1434+
(load-param v0)
1435+
(const v1 1)
1436+
(if-eq v0 v1 :one)
1437+
(const v2 2)
1438+
(if-eq v0 v2 :two)
1439+
(if-lez v0 :maybe_zero)
1440+
1441+
(const v3 999)
1442+
(return v3)
1443+
1444+
(:two)
1445+
(const v3 200)
1446+
(return v3)
1447+
1448+
(:one)
1449+
(const v3 100)
1450+
(return v3)
1451+
1452+
(:maybe_zero)
1453+
(const v3 0)
1454+
(return v3)
1455+
)
1456+
)");
1457+
// TODO (T219644020): improve logic and verify this is handled correctly.
1458+
}

0 commit comments

Comments
 (0)