diff options
author | Mark Mendell <mark.p.mendell@intel.com> | 2015-04-15 19:57:22 -0400 |
---|---|---|
committer | Mark Mendell <mark.p.mendell@intel.com> | 2015-04-20 14:26:10 -0400 |
commit | b0bd8915cb257cdaf46ba663c450a6543bca75af (patch) | |
tree | 0af66cce65abb2958d03579bd7fb660ffdda929b /test/458-checker-instruction-simplification | |
parent | b9791aa606834160b085dec7c5b32ccbeaf9a186 (diff) | |
download | art-b0bd8915cb257cdaf46ba663c450a6543bca75af.zip art-b0bd8915cb257cdaf46ba663c450a6543bca75af.tar.gz art-b0bd8915cb257cdaf46ba663c450a6543bca75af.tar.bz2 |
[optimizing] Replace FP divide by power of 2
Replace a floating point division by a power of two by a multiplication
of the reciprocal. This is guarenteed to have the exact same result as
it is exactly representable.
Add routines to allow generation of float and double constants after the
SSA Builder. I was unsure if float and double caches should be
implemented. Under the assumption that there is probably not a lot of
repetition of FP values. Please let me know.
Change-Id: I3a6c3847b49b4e747a7e7e8843ca32bb174b1584
Signed-off-by: Mark Mendell <mark.p.mendell@intel.com>
Diffstat (limited to 'test/458-checker-instruction-simplification')
-rw-r--r-- | test/458-checker-instruction-simplification/src/Main.java | 52 |
1 files changed, 51 insertions, 1 deletions
diff --git a/test/458-checker-instruction-simplification/src/Main.java b/test/458-checker-instruction-simplification/src/Main.java index 65be6cb..f26e0b1 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. */ @@ -907,6 +919,43 @@ public class Main { return !(!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; + } + public static void main(String[] args) { int arg = 123456; @@ -941,7 +990,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); @@ -952,5 +1000,7 @@ 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); } } |