Optimizing: Improve constant folding + DCE for inlining.
Run constant folding before DCE in inliner to eliminate more
code that can prevent inlining. Improve the constant folding
to evaluate Equals and NotEquals for null inputs.
Change-Id: I876ffb903ef39484370b6c8793f0f8467a977362
diff --git a/test/442-checker-constant-folding/src/Main.java b/test/442-checker-constant-folding/src/Main.java
index 59e7282..43bc9d0 100644
--- a/test/442-checker-constant-folding/src/Main.java
+++ b/test/442-checker-constant-folding/src/Main.java
@@ -659,6 +659,33 @@
/**
+ * Exercise constant folding on constant (static) condition for null references.
+ */
+
+ /// CHECK-START: int Main.StaticConditionNulls() constant_folding_after_inlining (before)
+ /// CHECK-DAG: <<Null:l\d+>> NullConstant
+ /// CHECK-DAG: <<Cond:z\d+>> NotEqual [<<Null>>,<<Null>>]
+ /// CHECK-DAG: If [<<Cond>>]
+
+ /// CHECK-START: int Main.StaticConditionNulls() constant_folding_after_inlining (after)
+ /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
+ /// CHECK-DAG: If [<<Const0>>]
+
+ /// CHECK-START: int Main.StaticConditionNulls() constant_folding_after_inlining (after)
+ /// CHECK-NOT: NotEqual
+
+ private static Object getNull() {
+ return null;
+ }
+
+ public static int StaticConditionNulls() {
+ Object a = getNull();
+ Object b = getNull();
+ return (a == b) ? 5 : 2;
+ }
+
+
+ /**
* Exercise constant folding on a program with condition
* (i.e. jumps) leading to the creation of many blocks.
*
@@ -1208,6 +1235,7 @@
assertLongEquals(9, XorLongInt());
assertIntEquals(5, StaticCondition());
+ assertIntEquals(5, StaticConditionNulls());
assertIntEquals(7, JumpsAndConditionals(true));
assertIntEquals(3, JumpsAndConditionals(false));