summaryrefslogtreecommitdiffstats
path: root/test/458-checker-instruction-simplification
diff options
context:
space:
mode:
authorNicolas Geoffray <ngeoffray@google.com>2015-04-27 08:53:46 +0000
committerMark Mendell <mark.p.mendell@intel.com>2015-04-27 20:06:50 -0400
commit0d22184ec9e5b1e958c031ac92c7f053de3a13a2 (patch)
tree4055eda9986916dc86b39d023082a57e60c804f4 /test/458-checker-instruction-simplification
parent97c96f5aab22f75dd54089bdc194588a4b5a2e8d (diff)
downloadart-0d22184ec9e5b1e958c031ac92c7f053de3a13a2.tar.gz
art-0d22184ec9e5b1e958c031ac92c7f053de3a13a2.tar.bz2
art-0d22184ec9e5b1e958c031ac92c7f053de3a13a2.zip
Revert "Revert "[optimizing] Replace FP divide by power of 2""
This reverts commit 067cae2c86627d2edcf01b918ee601774bc76aeb. Change-Id: Iaaa8772500ea7d3dce6ae0829dc0dc3bbc9c14ca
Diffstat (limited to 'test/458-checker-instruction-simplification')
-rw-r--r--test/458-checker-instruction-simplification/src/Main.java91
1 files changed, 90 insertions, 1 deletions
diff --git a/test/458-checker-instruction-simplification/src/Main.java b/test/458-checker-instruction-simplification/src/Main.java
index 0dbda6b3eb..5d5a6b3627 100644
--- a/test/458-checker-instruction-simplification/src/Main.java
+++ b/test/458-checker-instruction-simplification/src/Main.java
@@ -34,6 +34,18 @@ public class Main {
}
}
+ public static void assertFloatEquals(float expected, float result) {
+ if (expected != result) {
+ throw new Error("Expected: " + expected + ", found: " + result);
+ }
+ }
+
+ public static void assertDoubleEquals(double expected, double result) {
+ if (expected != result) {
+ throw new Error("Expected: " + expected + ", found: " + result);
+ }
+ }
+
/**
* Tiny programs exercising optimizations of arithmetic identities.
*/
@@ -926,6 +938,80 @@ public class Main {
return !(NegateValue(arg));
}
+ // CHECK-START: float Main.Div2(float) instruction_simplifier (before)
+ // CHECK-DAG: [[Arg:f\d+]] ParameterValue
+ // CHECK-DAG: [[Const2:f\d+]] FloatConstant 2
+ // CHECK-DAG: [[Div:f\d+]] Div [ [[Arg]] [[Const2]] ]
+ // CHECK-DAG: Return [ [[Div]] ]
+
+ // CHECK-START: float Main.Div2(float) instruction_simplifier (after)
+ // CHECK-DAG: [[Arg:f\d+]] ParameterValue
+ // CHECK-DAG: [[ConstP5:f\d+]] FloatConstant 0.5
+ // CHECK-DAG: [[Mul:f\d+]] Mul [ [[Arg]] [[ConstP5]] ]
+ // CHECK-DAG: Return [ [[Mul]] ]
+
+ // CHECK-START: float Main.Div2(float) instruction_simplifier (after)
+ // CHECK-NOT: Div
+
+ public static float Div2(float arg) {
+ return arg / 2.0f;
+ }
+
+ // CHECK-START: double Main.Div2(double) instruction_simplifier (before)
+ // CHECK-DAG: [[Arg:d\d+]] ParameterValue
+ // CHECK-DAG: [[Const2:d\d+]] DoubleConstant 2
+ // CHECK-DAG: [[Div:d\d+]] Div [ [[Arg]] [[Const2]] ]
+ // CHECK-DAG: Return [ [[Div]] ]
+
+ // CHECK-START: double Main.Div2(double) instruction_simplifier (after)
+ // CHECK-DAG: [[Arg:d\d+]] ParameterValue
+ // CHECK-DAG: [[ConstP5:d\d+]] DoubleConstant 0.5
+ // CHECK-DAG: [[Mul:d\d+]] Mul [ [[Arg]] [[ConstP5]] ]
+ // CHECK-DAG: Return [ [[Mul]] ]
+
+ // CHECK-START: double Main.Div2(double) instruction_simplifier (after)
+ // CHECK-NOT: Div
+ public static double Div2(double arg) {
+ return arg / 2.0;
+ }
+
+ // CHECK-START: float Main.DivMP25(float) instruction_simplifier (before)
+ // CHECK-DAG: [[Arg:f\d+]] ParameterValue
+ // CHECK-DAG: [[ConstMP25:f\d+]] FloatConstant -0.25
+ // CHECK-DAG: [[Div:f\d+]] Div [ [[Arg]] [[ConstMP25]] ]
+ // CHECK-DAG: Return [ [[Div]] ]
+
+ // CHECK-START: float Main.DivMP25(float) instruction_simplifier (after)
+ // CHECK-DAG: [[Arg:f\d+]] ParameterValue
+ // CHECK-DAG: [[ConstM4:f\d+]] FloatConstant -4
+ // CHECK-DAG: [[Mul:f\d+]] Mul [ [[Arg]] [[ConstM4]] ]
+ // CHECK-DAG: Return [ [[Mul]] ]
+
+ // CHECK-START: float Main.DivMP25(float) instruction_simplifier (after)
+ // CHECK-NOT: Div
+
+ public static float DivMP25(float arg) {
+ return arg / -0.25f;
+ }
+
+ // CHECK-START: double Main.DivMP25(double) instruction_simplifier (before)
+ // CHECK-DAG: [[Arg:d\d+]] ParameterValue
+ // CHECK-DAG: [[ConstMP25:d\d+]] DoubleConstant -0.25
+ // CHECK-DAG: [[Div:d\d+]] Div [ [[Arg]] [[ConstMP25]] ]
+ // CHECK-DAG: Return [ [[Div]] ]
+
+ // CHECK-START: double Main.DivMP25(double) instruction_simplifier (after)
+ // CHECK-DAG: [[Arg:d\d+]] ParameterValue
+ // CHECK-DAG: [[ConstM4:d\d+]] DoubleConstant -4
+ // CHECK-DAG: [[Mul:d\d+]] Mul [ [[Arg]] [[ConstM4]] ]
+ // CHECK-DAG: Return [ [[Mul]] ]
+
+ // CHECK-START: double Main.DivMP25(double) instruction_simplifier (after)
+ // CHECK-NOT: Div
+ public static double DivMP25(double arg) {
+ return arg / -0.25f;
+ }
+
public static void main(String[] args) {
int arg = 123456;
@@ -960,7 +1046,6 @@ 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);
@@ -971,5 +1056,9 @@ public class Main {
assertIntEquals(NotEqualFalseLhs(true), 5);
assertBooleanEquals(NotNotBool(true), true);
assertBooleanEquals(NotNotBool(false), false);
+ assertFloatEquals(Div2(100.0f), 50.0f);
+ assertDoubleEquals(Div2(150.0), 75.0);
+ assertFloatEquals(DivMP25(100.0f), -400.0f);
+ assertDoubleEquals(DivMP25(150.0), -600.0);
}
}