@@ -899,7 +899,7 @@ public void testInlineAnnotation() throws IOException {
899899 String inlined = Files .toString (new File ("test-output/OptimizerTests_testInlineAnnotation_inl.j" ), Charsets .UTF_8 );
900900 assertFalse (inlined .contains ("function bar" ));
901901 assertFalse (inlined .contains ("function over9000" ));
902- assertTrue ( inlined . contains ( "function over9001" ));
902+ // Non-annotated over9001 may be inlined depending on heuristic tuning.
903903 assertTrue (inlined .contains ("function noot" ));
904904 }
905905
@@ -925,6 +925,53 @@ public void inlinerSupportsMultiReturn() throws IOException {
925925 "Expected multi-return function calls to be inlined in _inl output." );
926926 }
927927
928+ @ Test
929+ public void inlinerRatesByIncomingUsesNotOutgoingCalls () throws IOException {
930+ testAssertOkLinesWithStdLib (false ,
931+ "package test" ,
932+ "function h1(int x) returns int" ,
933+ " return x + 1" ,
934+ "function h2(int x) returns int" ,
935+ " return x + 2" ,
936+ "function h3(int x) returns int" ,
937+ " return x + 3" ,
938+ "function h4(int x) returns int" ,
939+ " return x + 4" ,
940+ "function wrapper(int x) returns int" ,
941+ " var a = h1(x)" ,
942+ " var b = h2(a)" ,
943+ " var c = h3(b)" ,
944+ " var d = h4(c)" ,
945+ " if d > 0" ,
946+ " d += 1" ,
947+ " if d > 10" ,
948+ " d += 2" ,
949+ " if d > 20" ,
950+ " d += 3" ,
951+ " if d > 30" ,
952+ " d += 4" ,
953+ " if d > 40" ,
954+ " d += 5" ,
955+ " if d > 50" ,
956+ " d += 6" ,
957+ " if d > 60" ,
958+ " d += 7" ,
959+ " if d > 70" ,
960+ " d += 8" ,
961+ " return d" ,
962+ "init" ,
963+ " let v = wrapper(GetRandomInt(1, 100))" ,
964+ " if v > 0" ,
965+ " testSuccess()" ,
966+ "endpackage"
967+ );
968+ String inlined = Files .toString (new File ("test-output/OptimizerTests_inlinerRatesByIncomingUsesNotOutgoingCalls_inl.j" ), Charsets .UTF_8 );
969+ assertFalse (inlined .contains ("call wrapper" ),
970+ "Expected wrapper to inline when it has one incoming use." );
971+ assertTrue (inlined .contains ("GetRandomInt(" ),
972+ "Expected test setup to remain non-constant and observable in _inl output." );
973+ }
974+
928975
929976 @ Test
930977 public void moveTowardsBug () { // see #737
0 commit comments