Fix & add Checker assertions in 442-checker-constant-folding.
Change-Id: Id4165b14816c04961d5c274f24861d0e7856d95e
diff --git a/test/442-checker-constant-folding/src/Main.java b/test/442-checker-constant-folding/src/Main.java
index b7863be..079777e 100644
--- a/test/442-checker-constant-folding/src/Main.java
+++ b/test/442-checker-constant-folding/src/Main.java
@@ -46,9 +46,9 @@
}
}
+
/**
- * Tiny three-register program exercising int constant folding
- * on negation.
+ * Exercise constant folding on negation.
*/
/// CHECK-START: int Main.IntNegation() constant_folding (before)
@@ -60,6 +60,9 @@
/// CHECK-DAG: <<ConstN42:i\d+>> IntConstant -42
/// CHECK-DAG: Return [<<ConstN42>>]
+ /// CHECK-START: int Main.IntNegation() constant_folding (after)
+ /// CHECK-NOT: Neg
+
public static int IntNegation() {
int x, y;
x = 42;
@@ -67,9 +70,9 @@
return y;
}
+
/**
- * Tiny three-register program exercising int constant folding
- * on addition.
+ * Exercise constant folding on addition.
*/
/// CHECK-START: int Main.IntAddition1() constant_folding (before)
@@ -82,6 +85,9 @@
/// CHECK-DAG: <<Const3:i\d+>> IntConstant 3
/// CHECK-DAG: Return [<<Const3>>]
+ /// CHECK-START: int Main.IntAddition1() constant_folding (after)
+ /// CHECK-NOT: Add
+
public static int IntAddition1() {
int a, b, c;
a = 1;
@@ -90,11 +96,6 @@
return c;
}
- /**
- * Small three-register program exercising int constant folding
- * on addition.
- */
-
/// CHECK-START: int Main.IntAddition2() constant_folding (before)
/// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
/// CHECK-DAG: <<Const2:i\d+>> IntConstant 2
@@ -109,6 +110,9 @@
/// CHECK-DAG: <<Const14:i\d+>> IntConstant 14
/// CHECK-DAG: Return [<<Const14>>]
+ /// CHECK-START: int Main.IntAddition2() constant_folding (after)
+ /// CHECK-NOT: Add
+
public static int IntAddition2() {
int a, b, c;
a = 1;
@@ -121,9 +125,30 @@
return c;
}
+ /// CHECK-START: long Main.LongAddition() constant_folding (before)
+ /// CHECK-DAG: <<Const1:j\d+>> LongConstant 1
+ /// CHECK-DAG: <<Const2:j\d+>> LongConstant 2
+ /// CHECK-DAG: <<Add:j\d+>> Add [<<Const1>>,<<Const2>>]
+ /// CHECK-DAG: Return [<<Add>>]
+
+ /// CHECK-START: long Main.LongAddition() constant_folding (after)
+ /// CHECK-DAG: <<Const3:j\d+>> LongConstant 3
+ /// CHECK-DAG: Return [<<Const3>>]
+
+ /// CHECK-START: long Main.LongAddition() constant_folding (after)
+ /// CHECK-NOT: Add
+
+ public static long LongAddition() {
+ long a, b, c;
+ a = 1L;
+ b = 2L;
+ c = a + b;
+ return c;
+ }
+
+
/**
- * Tiny three-register program exercising int constant folding
- * on subtraction.
+ * Exercise constant folding on subtraction.
*/
/// CHECK-START: int Main.IntSubtraction() constant_folding (before)
@@ -136,6 +161,9 @@
/// CHECK-DAG: <<Const4:i\d+>> IntConstant 4
/// CHECK-DAG: Return [<<Const4>>]
+ /// CHECK-START: int Main.IntSubtraction() constant_folding (after)
+ /// CHECK-NOT: Sub
+
public static int IntSubtraction() {
int a, b, c;
a = 6;
@@ -144,34 +172,6 @@
return c;
}
- /**
- * Tiny three-register program exercising long constant folding
- * on addition.
- */
-
- /// CHECK-START: long Main.LongAddition() constant_folding (before)
- /// CHECK-DAG: <<Const1:j\d+>> LongConstant 1
- /// CHECK-DAG: <<Const2:j\d+>> LongConstant 2
- /// CHECK-DAG: <<Add:j\d+>> Add [<<Const1>>,<<Const2>>]
- /// CHECK-DAG: Return [<<Add>>]
-
- /// CHECK-START: long Main.LongAddition() constant_folding (after)
- /// CHECK-DAG: <<Const3:j\d+>> LongConstant 3
- /// CHECK-DAG: Return [<<Const3>>]
-
- public static long LongAddition() {
- long a, b, c;
- a = 1L;
- b = 2L;
- c = a + b;
- return c;
- }
-
- /**
- * Tiny three-register program exercising long constant folding
- * on subtraction.
- */
-
/// CHECK-START: long Main.LongSubtraction() constant_folding (before)
/// CHECK-DAG: <<Const6:j\d+>> LongConstant 6
/// CHECK-DAG: <<Const2:j\d+>> LongConstant 2
@@ -182,6 +182,9 @@
/// CHECK-DAG: <<Const4:j\d+>> LongConstant 4
/// CHECK-DAG: Return [<<Const4>>]
+ /// CHECK-START: long Main.LongSubtraction() constant_folding (after)
+ /// CHECK-NOT: Sub
+
public static long LongSubtraction() {
long a, b, c;
a = 6L;
@@ -190,8 +193,9 @@
return c;
}
+
/**
- * Three-register program with a constant (static) condition.
+ * Exercise constant folding on constant (static) condition.
*/
/// CHECK-START: int Main.StaticCondition() constant_folding (before)
@@ -204,6 +208,9 @@
/// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
/// CHECK-DAG: If [<<Const1>>]
+ /// CHECK-START: int Main.StaticCondition() constant_folding (after)
+ /// CHECK-NOT: GreaterThanOrEqual
+
public static int StaticCondition() {
int a, b, c;
a = 7;
@@ -215,9 +222,10 @@
return c;
}
+
/**
- * Four-variable program with jumps leading to the creation of many
- * blocks.
+ * Exercise constant folding on a program with condition
+ * (i.e. jumps) leading to the creation of many blocks.
*
* The intent of this test is to ensure that all constant expressions
* are actually evaluated at compile-time, thanks to the reverse
@@ -238,6 +246,10 @@
/// CHECK-DAG: <<Phi:i\d+>> Phi [<<Const7>>,<<Const3>>]
/// CHECK-DAG: Return [<<Phi>>]
+ /// CHECK-START: int Main.JumpsAndConditionals(boolean) constant_folding (after)
+ /// CHECK-NOT: Add
+ /// CHECK-NOT: Sub
+
public static int JumpsAndConditionals(boolean cond) {
int a, b, c;
a = 5;
@@ -249,6 +261,7 @@
return c;
}
+
/**
* Test optimizations of arithmetic identities yielding a constant result.
*/
@@ -262,9 +275,11 @@
/// CHECK-START: int Main.And0(int) constant_folding (after)
/// CHECK-DAG: <<Arg:i\d+>> ParameterValue
/// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
- /// CHECK-NOT: And
/// CHECK-DAG: Return [<<Const0>>]
+ /// CHECK-START: int Main.And0(int) constant_folding (after)
+ /// CHECK-NOT: And
+
public static int And0(int arg) {
return arg & 0;
}
@@ -278,9 +293,11 @@
/// CHECK-START: long Main.Mul0(long) constant_folding (after)
/// CHECK-DAG: <<Arg:j\d+>> ParameterValue
/// CHECK-DAG: <<Const0:j\d+>> LongConstant 0
- /// CHECK-NOT: Mul
/// CHECK-DAG: Return [<<Const0>>]
+ /// CHECK-START: long Main.Mul0(long) constant_folding (after)
+ /// CHECK-NOT: Mul
+
public static long Mul0(long arg) {
return arg * 0;
}
@@ -293,9 +310,11 @@
/// CHECK-START: int Main.OrAllOnes(int) constant_folding (after)
/// CHECK-DAG: <<ConstF:i\d+>> IntConstant -1
- /// CHECK-NOT: Or
/// CHECK-DAG: Return [<<ConstF>>]
+ /// CHECK-START: int Main.OrAllOnes(int) constant_folding (after)
+ /// CHECK-NOT: Or
+
public static int OrAllOnes(int arg) {
return arg | -1;
}
@@ -309,9 +328,11 @@
/// CHECK-START: long Main.Rem0(long) constant_folding (after)
/// CHECK-DAG: <<Const0:j\d+>> LongConstant 0
- /// CHECK-NOT: Rem
/// CHECK-DAG: Return [<<Const0>>]
+ /// CHECK-START: long Main.Rem0(long) constant_folding (after)
+ /// CHECK-NOT: Rem
+
public static long Rem0(long arg) {
return 0 % arg;
}
@@ -324,9 +345,11 @@
/// CHECK-START: int Main.Rem1(int) constant_folding (after)
/// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
- /// CHECK-NOT: Rem
/// CHECK-DAG: Return [<<Const0>>]
+ /// CHECK-START: int Main.Rem1(int) constant_folding (after)
+ /// CHECK-NOT: Rem
+
public static int Rem1(int arg) {
return arg % 1;
}
@@ -340,9 +363,11 @@
/// CHECK-START: long Main.RemN1(long) constant_folding (after)
/// CHECK-DAG: <<Const0:j\d+>> LongConstant 0
- /// CHECK-NOT: Rem
/// CHECK-DAG: Return [<<Const0>>]
+ /// CHECK-START: long Main.RemN1(long) constant_folding (after)
+ /// CHECK-NOT: Rem
+
public static long RemN1(long arg) {
return arg % -1;
}
@@ -356,9 +381,11 @@
/// CHECK-START: int Main.Shl0(int) constant_folding (after)
/// CHECK-DAG: <<Arg:i\d+>> ParameterValue
/// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
- /// CHECK-NOT: Shl
/// CHECK-DAG: Return [<<Const0>>]
+ /// CHECK-START: int Main.Shl0(int) constant_folding (after)
+ /// CHECK-NOT: Shl
+
public static int Shl0(int arg) {
return 0 << arg;
}
@@ -372,9 +399,11 @@
/// CHECK-START: long Main.Shr0(int) constant_folding (after)
/// CHECK-DAG: <<Arg:i\d+>> ParameterValue
/// CHECK-DAG: <<Const0:j\d+>> LongConstant 0
- /// CHECK-NOT: Shr
/// CHECK-DAG: Return [<<Const0>>]
+ /// CHECK-START: long Main.Shr0(int) constant_folding (after)
+ /// CHECK-NOT: Shr
+
public static long Shr0(int arg) {
return (long)0 >> arg;
}
@@ -387,9 +416,11 @@
/// CHECK-START: long Main.SubSameLong(long) constant_folding (after)
/// CHECK-DAG: <<Arg:j\d+>> ParameterValue
/// CHECK-DAG: <<Const0:j\d+>> LongConstant 0
- /// CHECK-NOT: Sub
/// CHECK-DAG: Return [<<Const0>>]
+ /// CHECK-START: long Main.SubSameLong(long) constant_folding (after)
+ /// CHECK-NOT: Sub
+
public static long SubSameLong(long arg) {
return arg - arg;
}
@@ -403,9 +434,11 @@
/// CHECK-START: int Main.UShr0(int) constant_folding (after)
/// CHECK-DAG: <<Arg:i\d+>> ParameterValue
/// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
- /// CHECK-NOT: UShr
/// CHECK-DAG: Return [<<Const0>>]
+ /// CHECK-START: int Main.UShr0(int) constant_folding (after)
+ /// CHECK-NOT: UShr
+
public static int UShr0(int arg) {
return 0 >>> arg;
}
@@ -418,9 +451,11 @@
/// CHECK-START: int Main.XorSameInt(int) constant_folding (after)
/// CHECK-DAG: <<Arg:i\d+>> ParameterValue
/// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
- /// CHECK-NOT: Xor
/// CHECK-DAG: Return [<<Const0>>]
+ /// CHECK-START: int Main.XorSameInt(int) constant_folding (after)
+ /// CHECK-NOT: Xor
+
public static int XorSameInt(int arg) {
return arg ^ arg;
}
@@ -473,6 +508,11 @@
return arg < Double.NaN;
}
+
+ /**
+ * Exercise constant folding on type conversions.
+ */
+
/// CHECK-START: int Main.ReturnInt33() constant_folding (before)
/// CHECK-DAG: <<Const33:j\d+>> LongConstant 33
/// CHECK-DAG: <<Convert:i\d+>> TypeConversion [<<Const33>>]
@@ -482,6 +522,9 @@
/// CHECK-DAG: <<Const33:i\d+>> IntConstant 33
/// CHECK-DAG: Return [<<Const33>>]
+ /// CHECK-START: int Main.ReturnInt33() constant_folding (after)
+ /// CHECK-NOT: TypeConversion
+
public static int ReturnInt33() {
long imm = 33L;
return (int) imm;
@@ -496,6 +539,9 @@
/// CHECK-DAG: <<ConstMax:i\d+>> IntConstant 2147483647
/// CHECK-DAG: Return [<<ConstMax>>]
+ /// CHECK-START: int Main.ReturnIntMax() constant_folding (after)
+ /// CHECK-NOT: TypeConversion
+
public static int ReturnIntMax() {
float imm = 1.0e34f;
return (int) imm;
@@ -510,6 +556,9 @@
/// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
/// CHECK-DAG: Return [<<Const0>>]
+ /// CHECK-START: int Main.ReturnInt0() constant_folding (after)
+ /// CHECK-NOT: TypeConversion
+
public static int ReturnInt0() {
double imm = Double.NaN;
return (int) imm;
@@ -524,6 +573,9 @@
/// CHECK-DAG: <<Const33:j\d+>> LongConstant 33
/// CHECK-DAG: Return [<<Const33>>]
+ /// CHECK-START: long Main.ReturnLong33() constant_folding (after)
+ /// CHECK-NOT: TypeConversion
+
public static long ReturnLong33() {
int imm = 33;
return (long) imm;
@@ -538,6 +590,9 @@
/// CHECK-DAG: <<Const34:j\d+>> LongConstant 34
/// CHECK-DAG: Return [<<Const34>>]
+ /// CHECK-START: long Main.ReturnLong34() constant_folding (after)
+ /// CHECK-NOT: TypeConversion
+
public static long ReturnLong34() {
float imm = 34.0f;
return (long) imm;
@@ -552,6 +607,9 @@
/// CHECK-DAG: <<Const0:j\d+>> LongConstant 0
/// CHECK-DAG: Return [<<Const0>>]
+ /// CHECK-START: long Main.ReturnLong0() constant_folding (after)
+ /// CHECK-NOT: TypeConversion
+
public static long ReturnLong0() {
double imm = -Double.NaN;
return (long) imm;
@@ -566,6 +624,9 @@
/// CHECK-DAG: <<Const33:f\d+>> FloatConstant 33
/// CHECK-DAG: Return [<<Const33>>]
+ /// CHECK-START: float Main.ReturnFloat33() constant_folding (after)
+ /// CHECK-NOT: TypeConversion
+
public static float ReturnFloat33() {
int imm = 33;
return (float) imm;
@@ -580,6 +641,9 @@
/// CHECK-DAG: <<Const34:f\d+>> FloatConstant 34
/// CHECK-DAG: Return [<<Const34>>]
+ /// CHECK-START: float Main.ReturnFloat34() constant_folding (after)
+ /// CHECK-NOT: TypeConversion
+
public static float ReturnFloat34() {
long imm = 34L;
return (float) imm;
@@ -594,6 +658,9 @@
/// CHECK-DAG: <<Const:f\d+>> FloatConstant 99.25
/// CHECK-DAG: Return [<<Const>>]
+ /// CHECK-START: float Main.ReturnFloat99P25() constant_folding (after)
+ /// CHECK-NOT: TypeConversion
+
public static float ReturnFloat99P25() {
double imm = 99.25;
return (float) imm;
@@ -622,6 +689,9 @@
/// CHECK-DAG: <<Const34:d\d+>> DoubleConstant 34
/// CHECK-DAG: Return [<<Const34>>]
+ /// CHECK-START: double Main.ReturnDouble34() constant_folding (after)
+ /// CHECK-NOT: TypeConversion
+
public static double ReturnDouble34() {
long imm = 34L;
return (double) imm;
@@ -636,46 +706,61 @@
/// CHECK-DAG: <<Const:d\d+>> DoubleConstant 99.25
/// CHECK-DAG: Return [<<Const>>]
+ /// CHECK-START: double Main.ReturnDouble99P25() constant_folding (after)
+ /// CHECK-NOT: TypeConversion
+
public static double ReturnDouble99P25() {
float imm = 99.25f;
return (double) imm;
}
+
public static void main(String[] args) {
- assertIntEquals(IntNegation(), -42);
- assertIntEquals(IntAddition1(), 3);
- assertIntEquals(IntAddition2(), 14);
- assertIntEquals(IntSubtraction(), 4);
- assertLongEquals(LongAddition(), 3L);
- assertLongEquals(LongSubtraction(), 4L);
- assertIntEquals(StaticCondition(), 5);
- assertIntEquals(JumpsAndConditionals(true), 7);
- assertIntEquals(JumpsAndConditionals(false), 3);
+ assertIntEquals(-42, IntNegation());
+
+ assertIntEquals(3, IntAddition1());
+ assertIntEquals(14, IntAddition2());
+ assertLongEquals(3L, LongAddition());
+
+ assertIntEquals(4, IntSubtraction());
+ assertLongEquals(4L, LongSubtraction());
+
+ assertIntEquals(5, StaticCondition());
+
+ assertIntEquals(7, JumpsAndConditionals(true));
+ assertIntEquals(3, JumpsAndConditionals(false));
+
int arbitrary = 123456; // Value chosen arbitrarily.
- assertIntEquals(And0(arbitrary), 0);
- assertLongEquals(Mul0(arbitrary), 0);
- assertIntEquals(OrAllOnes(arbitrary), -1);
- assertLongEquals(Rem0(arbitrary), 0);
- assertIntEquals(Rem1(arbitrary), 0);
- assertLongEquals(RemN1(arbitrary), 0);
- assertIntEquals(Shl0(arbitrary), 0);
- assertLongEquals(Shr0(arbitrary), 0);
- assertLongEquals(SubSameLong(arbitrary), 0);
- assertIntEquals(UShr0(arbitrary), 0);
- assertIntEquals(XorSameInt(arbitrary), 0);
+
+ assertIntEquals(0, And0(arbitrary));
+ assertLongEquals(0, Mul0(arbitrary));
+ assertIntEquals(-1, OrAllOnes(arbitrary));
+ assertLongEquals(0, Rem0(arbitrary));
+ assertIntEquals(0, Rem1(arbitrary));
+ assertLongEquals(0, RemN1(arbitrary));
+ assertIntEquals(0, Shl0(arbitrary));
+ assertLongEquals(0, Shr0(arbitrary));
+ assertLongEquals(0, SubSameLong(arbitrary));
+ assertIntEquals(0, UShr0(arbitrary));
+ assertIntEquals(0, XorSameInt(arbitrary));
+
assertFalse(CmpFloatGreaterThanNaN(arbitrary));
assertFalse(CmpDoubleLessThanNaN(arbitrary));
- assertIntEquals(ReturnInt33(), 33);
- assertIntEquals(ReturnIntMax(), 2147483647);
- assertIntEquals(ReturnInt0(), 0);
- assertLongEquals(ReturnLong33(), 33);
- assertLongEquals(ReturnLong34(), 34);
- assertLongEquals(ReturnLong0(), 0);
- assertFloatEquals(ReturnFloat33(), 33);
- assertFloatEquals(ReturnFloat34(), 34);
- assertFloatEquals(ReturnFloat99P25(), 99.25f);
- assertDoubleEquals(ReturnDouble33(), 33);
- assertDoubleEquals(ReturnDouble34(), 34);
- assertDoubleEquals(ReturnDouble99P25(), 99.25);
+
+ assertIntEquals(33, ReturnInt33());
+ assertIntEquals(2147483647, ReturnIntMax());
+ assertIntEquals(0, ReturnInt0());
+
+ assertLongEquals(33, ReturnLong33());
+ assertLongEquals(34, ReturnLong34());
+ assertLongEquals(0, ReturnLong0());
+
+ assertFloatEquals(33, ReturnFloat33());
+ assertFloatEquals(34, ReturnFloat34());
+ assertFloatEquals(99.25f, ReturnFloat99P25());
+
+ assertDoubleEquals(33, ReturnDouble33());
+ assertDoubleEquals(34, ReturnDouble34());
+ assertDoubleEquals(99.25, ReturnDouble99P25());
}
}