ART: Simplify (Not)Equal bool vs. int to true/false
Optimizations on the HGraph may produce comparisons of bool and ints.
Instruction simplifier will simplify these only for 0/1 int constants.
Since the range of bool is known, comparison against all other int
constants can always be determined statically.
Change-Id: I502651b7a08edf71ee0b2589069f00def6aacf66
diff --git a/test/458-checker-instruction-simplification/src/Main.java b/test/458-checker-instruction-simplification/src/Main.java
index 3c3b939..aa4dda1 100644
--- a/test/458-checker-instruction-simplification/src/Main.java
+++ b/test/458-checker-instruction-simplification/src/Main.java
@@ -927,6 +927,36 @@
return (false == arg) ? 3 : 5;
}
+ /// CHECK-START: boolean Main.EqualBoolVsIntConst(boolean) instruction_simplifier_after_bce (before)
+ /// CHECK-DAG: <<Arg:z\d+>> ParameterValue
+ /// CHECK-DAG: <<Const2:i\d+>> IntConstant 2
+ /// CHECK-DAG: <<BoolNot:z\d+>> BooleanNot [<<Arg>>]
+ /// CHECK-DAG: <<Cond:z\d+>> Equal [<<BoolNot>>,<<Const2>>]
+ /// CHECK-DAG: Return [<<Cond>>]
+
+ /// CHECK-START: boolean Main.EqualBoolVsIntConst(boolean) instruction_simplifier_after_bce (after)
+ /// CHECK-DAG: <<False:i\d+>> IntConstant 0
+ /// CHECK-DAG: Return [<<False>>]
+
+ public static boolean EqualBoolVsIntConst(boolean arg) {
+ return (arg ? 0 : 1) == 2;
+ }
+
+ /// CHECK-START: boolean Main.NotEqualBoolVsIntConst(boolean) instruction_simplifier_after_bce (before)
+ /// CHECK-DAG: <<Arg:z\d+>> ParameterValue
+ /// CHECK-DAG: <<Const2:i\d+>> IntConstant 2
+ /// CHECK-DAG: <<BoolNot:z\d+>> BooleanNot [<<Arg>>]
+ /// CHECK-DAG: <<Cond:z\d+>> NotEqual [<<BoolNot>>,<<Const2>>]
+ /// CHECK-DAG: Return [<<Cond>>]
+
+ /// CHECK-START: boolean Main.NotEqualBoolVsIntConst(boolean) instruction_simplifier_after_bce (after)
+ /// CHECK-DAG: <<True:i\d+>> IntConstant 1
+ /// CHECK-DAG: Return [<<True>>]
+
+ public static boolean NotEqualBoolVsIntConst(boolean arg) {
+ return (arg ? 0 : 1) != 2;
+ }
+
/*
* Test simplification of double Boolean negation. Note that sometimes
* both negations can be removed but we only expect the simplifier to