summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorDavid Brazdil <dbrazdil@google.com>2015-04-17 14:52:19 +0100
committerDavid Brazdil <dbrazdil@google.com>2015-04-20 18:11:39 +0100
commit0d13fee6f4330cc9cb100c43135490a34c11d7a5 (patch)
treee96f089c1e384772bebdd8d8701c95d73569f29c /test
parent27eac12a66a73eb38b5ccb45b62350cf341299d0 (diff)
downloadart-0d13fee6f4330cc9cb100c43135490a34c11d7a5.zip
art-0d13fee6f4330cc9cb100c43135490a34c11d7a5.tar.gz
art-0d13fee6f4330cc9cb100c43135490a34c11d7a5.tar.bz2
ART: Simplify more bool operations
Now that we have the HBooleanNot instruction, the instruction simplifier can optimize out more conditions comparing a boolean against a constant, as well as sequences of Boolean negations. Change-Id: I7f634f6428a3984dd97b27b3d6362491346f1ff6
Diffstat (limited to 'test')
-rw-r--r--test/458-checker-instruction-simplification/src/Main.java160
-rw-r--r--test/463-checker-boolean-simplifier/src/Main.java15
2 files changed, 167 insertions, 8 deletions
diff --git a/test/458-checker-instruction-simplification/src/Main.java b/test/458-checker-instruction-simplification/src/Main.java
index 3cbcebb..65be6cb 100644
--- a/test/458-checker-instruction-simplification/src/Main.java
+++ b/test/458-checker-instruction-simplification/src/Main.java
@@ -16,6 +16,12 @@
public class Main {
+ public static void assertBooleanEquals(boolean expected, boolean result) {
+ if (expected != result) {
+ throw new Error("Expected: " + expected + ", found: " + result);
+ }
+ }
+
public static void assertIntEquals(int expected, int result) {
if (expected != result) {
throw new Error("Expected: " + expected + ", found: " + result);
@@ -41,7 +47,7 @@ public class Main {
// CHECK-START: long Main.Add0(long) instruction_simplifier (after)
// CHECK-DAG: [[Arg:j\d+]] ParameterValue
// CHECK-DAG: Return [ [[Arg]] ]
- //
+
// CHECK-START: long Main.Add0(long) instruction_simplifier (after)
// CHECK-NOT: Add
@@ -760,6 +766,147 @@ public class Main {
return res;
}
+ // CHECK-START: int Main.EqualTrueRhs(boolean) instruction_simplifier (before)
+ // CHECK-DAG: [[Arg:z\d+]] ParameterValue
+ // CHECK-DAG: [[Const1:i\d+]] IntConstant 1
+ // CHECK-DAG: [[Cond:z\d+]] Equal [ [[Arg]] [[Const1]] ]
+ // CHECK-DAG: If [ [[Cond]] ]
+
+ // CHECK-START: int Main.EqualTrueRhs(boolean) instruction_simplifier (after)
+ // CHECK-DAG: [[Arg:z\d+]] ParameterValue
+ // CHECK-DAG: If [ [[Arg]] ]
+
+ public static int EqualTrueRhs(boolean arg) {
+ return (arg != true) ? 3 : 5;
+ }
+
+ // CHECK-START: int Main.EqualTrueLhs(boolean) instruction_simplifier (before)
+ // CHECK-DAG: [[Arg:z\d+]] ParameterValue
+ // CHECK-DAG: [[Const1:i\d+]] IntConstant 1
+ // CHECK-DAG: [[Cond:z\d+]] Equal [ [[Const1]] [[Arg]] ]
+ // CHECK-DAG: If [ [[Cond]] ]
+
+ // CHECK-START: int Main.EqualTrueLhs(boolean) instruction_simplifier (after)
+ // CHECK-DAG: [[Arg:z\d+]] ParameterValue
+ // CHECK-DAG: If [ [[Arg]] ]
+
+ public static int EqualTrueLhs(boolean arg) {
+ return (true != arg) ? 3 : 5;
+ }
+
+ // CHECK-START: int Main.EqualFalseRhs(boolean) instruction_simplifier (before)
+ // CHECK-DAG: [[Arg:z\d+]] ParameterValue
+ // CHECK-DAG: [[Const0:i\d+]] IntConstant 0
+ // CHECK-DAG: [[Cond:z\d+]] Equal [ [[Arg]] [[Const0]] ]
+ // CHECK-DAG: If [ [[Cond]] ]
+
+ // CHECK-START: int Main.EqualFalseRhs(boolean) instruction_simplifier (after)
+ // CHECK-DAG: [[Arg:z\d+]] ParameterValue
+ // CHECK-DAG: [[NotArg:z\d+]] BooleanNot [ [[Arg]] ]
+ // CHECK-DAG: If [ [[NotArg]] ]
+
+ public static int EqualFalseRhs(boolean arg) {
+ return (arg != false) ? 3 : 5;
+ }
+
+ // CHECK-START: int Main.EqualFalseLhs(boolean) instruction_simplifier (before)
+ // CHECK-DAG: [[Arg:z\d+]] ParameterValue
+ // CHECK-DAG: [[Const0:i\d+]] IntConstant 0
+ // CHECK-DAG: [[Cond:z\d+]] Equal [ [[Const0]] [[Arg]] ]
+ // CHECK-DAG: If [ [[Cond]] ]
+
+ // CHECK-START: int Main.EqualFalseLhs(boolean) instruction_simplifier (after)
+ // CHECK-DAG: [[Arg:z\d+]] ParameterValue
+ // CHECK-DAG: [[NotArg:z\d+]] BooleanNot [ [[Arg]] ]
+ // CHECK-DAG: If [ [[NotArg]] ]
+
+ public static int EqualFalseLhs(boolean arg) {
+ return (false != arg) ? 3 : 5;
+ }
+
+ // CHECK-START: int Main.NotEqualTrueRhs(boolean) instruction_simplifier (before)
+ // CHECK-DAG: [[Arg:z\d+]] ParameterValue
+ // CHECK-DAG: [[Const1:i\d+]] IntConstant 1
+ // CHECK-DAG: [[Cond:z\d+]] NotEqual [ [[Arg]] [[Const1]] ]
+ // CHECK-DAG: If [ [[Cond]] ]
+
+ // CHECK-START: int Main.NotEqualTrueRhs(boolean) instruction_simplifier (after)
+ // CHECK-DAG: [[Arg:z\d+]] ParameterValue
+ // CHECK-DAG: [[NotArg:z\d+]] BooleanNot [ [[Arg]] ]
+ // CHECK-DAG: If [ [[NotArg]] ]
+
+ public static int NotEqualTrueRhs(boolean arg) {
+ return (arg == true) ? 3 : 5;
+ }
+
+ // CHECK-START: int Main.NotEqualTrueLhs(boolean) instruction_simplifier (before)
+ // CHECK-DAG: [[Arg:z\d+]] ParameterValue
+ // CHECK-DAG: [[Const1:i\d+]] IntConstant 1
+ // CHECK-DAG: [[Cond:z\d+]] NotEqual [ [[Const1]] [[Arg]] ]
+ // CHECK-DAG: If [ [[Cond]] ]
+
+ // CHECK-START: int Main.NotEqualTrueLhs(boolean) instruction_simplifier (after)
+ // CHECK-DAG: [[Arg:z\d+]] ParameterValue
+ // CHECK-DAG: [[NotArg:z\d+]] BooleanNot [ [[Arg]] ]
+ // CHECK-DAG: If [ [[NotArg]] ]
+
+ public static int NotEqualTrueLhs(boolean arg) {
+ return (true == arg) ? 3 : 5;
+ }
+
+ // CHECK-START: int Main.NotEqualFalseRhs(boolean) instruction_simplifier (before)
+ // CHECK-DAG: [[Arg:z\d+]] ParameterValue
+ // CHECK-DAG: [[Const0:i\d+]] IntConstant 0
+ // CHECK-DAG: [[Cond:z\d+]] NotEqual [ [[Arg]] [[Const0]] ]
+ // CHECK-DAG: If [ [[Cond]] ]
+
+ // CHECK-START: int Main.NotEqualFalseRhs(boolean) instruction_simplifier (after)
+ // CHECK-DAG: [[Arg:z\d+]] ParameterValue
+ // CHECK-DAG: If [ [[Arg]] ]
+
+ public static int NotEqualFalseRhs(boolean arg) {
+ return (arg == false) ? 3 : 5;
+ }
+
+ // CHECK-START: int Main.NotEqualFalseLhs(boolean) instruction_simplifier (before)
+ // CHECK-DAG: [[Arg:z\d+]] ParameterValue
+ // CHECK-DAG: [[Const0:i\d+]] IntConstant 0
+ // CHECK-DAG: [[Cond:z\d+]] NotEqual [ [[Const0]] [[Arg]] ]
+ // CHECK-DAG: If [ [[Cond]] ]
+
+ // CHECK-START: int Main.NotEqualFalseLhs(boolean) instruction_simplifier (after)
+ // CHECK-DAG: [[Arg:z\d+]] ParameterValue
+ // CHECK-DAG: If [ [[Arg]] ]
+
+ public static int NotEqualFalseLhs(boolean arg) {
+ return (false == arg) ? 3 : 5;
+ }
+
+ /*
+ * Test simplification of double Boolean negation. Note that sometimes
+ * both negations can be removed but we only expect the simplifier to
+ * remove the second.
+ */
+
+ // CHECK-START: boolean Main.NotNotBool(boolean) instruction_simplifier_after_types (before)
+ // CHECK-DAG: [[Arg:z\d+]] ParameterValue
+ // CHECK-DAG: [[NotArg:z\d+]] BooleanNot [ [[Arg]] ]
+ // CHECK-DAG: [[NotNotArg:z\d+]] BooleanNot [ [[NotArg]] ]
+ // CHECK-DAG: Return [ [[NotNotArg]] ]
+
+ // CHECK-START: boolean Main.NotNotBool(boolean) instruction_simplifier_after_types (after)
+ // CHECK-DAG: [[Arg:z\d+]] ParameterValue
+ // CHECK-DAG: BooleanNot [ [[Arg]] ]
+ // CHECK-DAG: Return [ [[Arg]] ]
+
+ // CHECK-START: boolean Main.NotNotBool(boolean) instruction_simplifier_after_types (after)
+ // CHECK: BooleanNot
+ // CHECK-NOT: BooleanNot
+
+ public static boolean NotNotBool(boolean arg) {
+ return !(!arg);
+ }
+
public static void main(String[] args) {
int arg = 123456;
@@ -794,5 +941,16 @@ public class Main {
assertIntEquals(SubNeg1(arg, arg + 1), -(arg + arg + 1));
assertIntEquals(SubNeg2(arg, arg + 1), -(arg + arg + 1));
assertLongEquals(SubNeg3(arg, arg + 1), -(2 * arg + 1));
+
+ assertIntEquals(EqualTrueRhs(true), 5);
+ assertIntEquals(EqualTrueLhs(true), 5);
+ assertIntEquals(EqualFalseRhs(true), 3);
+ assertIntEquals(EqualFalseLhs(true), 3);
+ assertIntEquals(NotEqualTrueRhs(true), 3);
+ assertIntEquals(NotEqualTrueLhs(true), 3);
+ assertIntEquals(NotEqualFalseRhs(true), 5);
+ assertIntEquals(NotEqualFalseLhs(true), 5);
+ assertBooleanEquals(NotNotBool(true), true);
+ assertBooleanEquals(NotNotBool(false), false);
}
}
diff --git a/test/463-checker-boolean-simplifier/src/Main.java b/test/463-checker-boolean-simplifier/src/Main.java
index efe0d3f..3daf693 100644
--- a/test/463-checker-boolean-simplifier/src/Main.java
+++ b/test/463-checker-boolean-simplifier/src/Main.java
@@ -27,16 +27,15 @@ public class Main {
}
/*
- * Elementary test negating a boolean. Verifies that the condition is replaced,
- * blocks merged and empty branches removed.
+ * Elementary test negating a boolean. Verifies that blocks are merged and
+ * empty branches removed.
*/
// CHECK-START: boolean Main.BooleanNot(boolean) boolean_simplifier (before)
// CHECK-DAG: [[Param:z\d+]] ParameterValue
// CHECK-DAG: [[Const0:i\d+]] IntConstant 0
// CHECK-DAG: [[Const1:i\d+]] IntConstant 1
- // CHECK-DAG: [[NotEq:z\d+]] NotEqual [ [[Param]] [[Const0]] ]
- // CHECK-DAG: If [ [[NotEq]] ]
+ // CHECK-DAG: If [ [[Param]] ]
// CHECK-DAG: [[Phi:i\d+]] Phi [ [[Const1]] [[Const0]] ]
// CHECK-DAG: Return [ [[Phi]] ]
@@ -49,11 +48,10 @@ public class Main {
// CHECK-START: boolean Main.BooleanNot(boolean) boolean_simplifier (after)
// CHECK-DAG: [[Param:z\d+]] ParameterValue
// CHECK-DAG: [[Const0:i\d+]] IntConstant 0
- // CHECK-DAG: [[Eq:z\d+]] Equal [ [[Param]] [[Const0]] ]
- // CHECK-DAG: Return [ [[Eq]] ]
+ // CHECK-DAG: [[NotParam:z\d+]] BooleanNot [ [[Param]] ]
+ // CHECK-DAG: Return [ [[NotParam]] ]
// CHECK-START: boolean Main.BooleanNot(boolean) boolean_simplifier (after)
- // CHECK-NOT: NotEqual
// CHECK-NOT: If
// CHECK-NOT: Phi
@@ -115,6 +113,9 @@ public class Main {
// CHECK-DAG: [[Cond:z\d+]] LessThan [ [[ParamX]] [[ParamY]] ]
// CHECK-DAG: Return [ [[Cond]] ]
+ // CHECK-START: boolean Main.LessThan(int, int) boolean_simplifier (after)
+ // CHECK-NOT: GreaterThanOrEqual
+
public static boolean LessThan(int x, int y) {
return (x < y) ? true : false;
}