diff options
Diffstat (limited to 'test/458-checker-instruct-simplification/src/Main.java')
-rw-r--r-- | test/458-checker-instruct-simplification/src/Main.java | 255 |
1 files changed, 255 insertions, 0 deletions
diff --git a/test/458-checker-instruct-simplification/src/Main.java b/test/458-checker-instruct-simplification/src/Main.java index 5ffb75feb9..557f126d01 100644 --- a/test/458-checker-instruct-simplification/src/Main.java +++ b/test/458-checker-instruct-simplification/src/Main.java @@ -2529,6 +2529,219 @@ public class Main { return "x".indexOf(ch, fromIndex); // Not simplified. } + /// CHECK-START: byte Main.$noinline$redundantAndNotRedundant(int) instruction_simplifier (before) + /// CHECK-DAG: And + + /// CHECK-START: byte Main.$noinline$redundantAndNotRedundant(int) instruction_simplifier (after) + /// CHECK-DAG: And + public static byte $noinline$redundantAndNotRedundant(int value) { + // Here the AND is not redundant. This test checks that it is not removed. + // 0xf500 = 1111 0101 0000 0000 - bits [11:8] of value will be changed by + // the AND with 0101. These bits are kept following the SHR and TypeConversion. + return (byte) ((value & 0xf500) >> 8); + } + + /// CHECK-START: byte Main.$noinline$redundantAndOtherUse(int) instruction_simplifier (before) + /// CHECK-DAG: And + + /// CHECK-START: byte Main.$noinline$redundantAndOtherUse(int) instruction_simplifier (after) + /// CHECK-DAG: And + public static byte $noinline$redundantAndOtherUse(int value){ + int v1 = value & 0xff00; + // Above AND is redundant in the context of calculating v2. + byte v2 = (byte) (v1 >> 8); + byte v3 = (byte) (v1 - 0x6eef); + // Use of AND result (v1) in calculating v3 means AND must not be removed. + return (byte) (v2 - v3); + } + + /// CHECK-START: byte Main.$noinline$redundantAndShortToByteShift2(short) instruction_simplifier (before) + /// CHECK-DAG: And + + /// CHECK-START: byte Main.$noinline$redundantAndShortToByteShift2(short) instruction_simplifier (after) + /// CHECK-NOT: And + public static byte $noinline$redundantAndShortToByteShift2(short value) { + // & 0xfff only changes bits higher than bit number 12 inclusive. + // These bits are discarded during Type Conversion to byte. + // Therefore AND is redundant and should be removed. + return (byte) ((value & 0xfff) >> 2); + } + + /// CHECK-START: byte Main.$noinline$redundantAndShortToByteShift5(short) instruction_simplifier (before) + /// CHECK-DAG: And + + /// CHECK-START: byte Main.$noinline$redundantAndShortToByteShift5(short) instruction_simplifier (after) + /// CHECK-NOT: And + public static byte $noinline$redundantAndShortToByteShift5(short value) { + // & 0xffe0 changes bits [4:0] and bits higher than 16 inclusive. + // These bits are discarded by the right shift and type conversion. + // Therefore AND is redundant and should be removed. + return (byte) ((value & 0xffe0) >> 5); + } + + /// CHECK-START: byte Main.$noinline$redundantAndShortToByteShift8(short) instruction_simplifier (before) + /// CHECK-DAG: And + + /// CHECK-START: byte Main.$noinline$redundantAndShortToByteShift8(short) instruction_simplifier (after) + /// CHECK-NOT: And + public static byte $noinline$redundantAndShortToByteShift8(short value) { + return (byte) ((value & 0xff00) >> 8); + } + + /// CHECK-START: byte Main.$noinline$redundantAndShortToByteShift9NotRedundant(short) instruction_simplifier (before) + /// CHECK-DAG: And + + /// CHECK-START: byte Main.$noinline$redundantAndShortToByteShift9NotRedundant(short) instruction_simplifier (after) + /// CHECK-DAG: And + public static byte $noinline$redundantAndShortToByteShift9NotRedundant(short value) { + // Byte and Short operands for bitwise operations (e.g. &,>>) are promoted to Int32 prior to operation. + // Negative operands will be sign extended accordingly: (short: 0xff45) --> (int: 0xffffff45) + // & fe00 will clear bits [31:16]. For negative 'value', this will clear sign bits. + // Without the AND, the right shift will move the sign extended ones into the result instead of zeros. + // Therefore AND is not redundant and should not be removed. + return (byte) ((value & 0xfe00) >> 9); + } + + /// CHECK-START: byte Main.$noinline$redundantAndShortToByteShift10NotRedundant(short) instruction_simplifier (before) + /// CHECK-DAG: And + + /// CHECK-START: byte Main.$noinline$redundantAndShortToByteShift10NotRedundant(short) instruction_simplifier (after) + /// CHECK-DAG: And + public static byte $noinline$redundantAndShortToByteShift10NotRedundant(short value) { + return (byte) ((value & 0x1ffff) >> 10); + } + + /// CHECK-START: byte Main.$noinline$redundantAndShortToByteShift12(short) instruction_simplifier (before) + /// CHECK-DAG: And + + /// CHECK-START: byte Main.$noinline$redundantAndShortToByteShift12(short) instruction_simplifier (after) + /// CHECK-NOT: And + public static byte $noinline$redundantAndShortToByteShift12(short value) { + // & fff00 preserves bits [19:8] and clears all others. + // Here the AND preserves enough ones; such that zeros are moved into the result. + // Therefore AND is redundant and can be removed. + return (byte) ((value & 0xfff00) >> 12); + } + + /// CHECK-START: byte Main.$noinline$redundantAndShortToByteShift15(short) instruction_simplifier (before) + /// CHECK-DAG: And + + /// CHECK-START: byte Main.$noinline$redundantAndShortToByteShift15(short) instruction_simplifier (after) + /// CHECK-NOT: And + public static byte $noinline$redundantAndShortToByteShift15(short value) { + return (byte) ((value & 0xffff00) >> 15); + } + + /// CHECK-START: byte Main.$noinline$redundantAndShortToByteShift16(short) instruction_simplifier (before) + /// CHECK-DAG: And + + /// CHECK-START: byte Main.$noinline$redundantAndShortToByteShift16(short) instruction_simplifier (after) + /// CHECK-NOT: And + public static byte $noinline$redundantAndShortToByteShift16(short value) { + return (byte) ((value & 0xf0ffff00) >> 16); + } + + /// CHECK-START: byte Main.$noinline$redundantAndIntToByteShift2(int) instruction_simplifier (before) + /// CHECK-DAG: And + + /// CHECK-START: byte Main.$noinline$redundantAndIntToByteShift2(int) instruction_simplifier (after) + /// CHECK-NOT: And + public static byte $noinline$redundantAndIntToByteShift2(int value) { + return (byte) ((value & 0xfff) >> 2); + } + + /// CHECK-START: byte Main.$noinline$redundantAndIntToByteShift5(int) instruction_simplifier (before) + /// CHECK-DAG: And + + /// CHECK-START: byte Main.$noinline$redundantAndIntToByteShift5(int) instruction_simplifier (after) + /// CHECK-NOT: And + public static byte $noinline$redundantAndIntToByteShift5(int value) { + return (byte) ((value & 0xffe0) >> 5); + } + + /// CHECK-START: byte Main.$noinline$redundantAndIntToByteShift8(int) instruction_simplifier (before) + /// CHECK-DAG: And + + /// CHECK-START: byte Main.$noinline$redundantAndIntToByteShift8(int) instruction_simplifier (after) + /// CHECK-NOT: And + public static byte $noinline$redundantAndIntToByteShift8(int value) { + return (byte) ((value & 0xffffff00) >> 8); + } + + /// CHECK-START: byte Main.$noinline$redundantAndIntToByteShift9(int) instruction_simplifier (before) + /// CHECK-DAG: And + + /// CHECK-START: byte Main.$noinline$redundantAndIntToByteShift9(int) instruction_simplifier (after) + /// CHECK-NOT: And + public static byte $noinline$redundantAndIntToByteShift9(int value) { + return (byte) ((value & 0xf001fe00) >> 9); + } + + /// CHECK-START: byte Main.$noinline$redundantAndIntToByteShift16(int) instruction_simplifier (before) + /// CHECK-DAG: And + + /// CHECK-START: byte Main.$noinline$redundantAndIntToByteShift16(int) instruction_simplifier (after) + /// CHECK-NOT: And + public static byte $noinline$redundantAndIntToByteShift16(int value) { + return (byte) ((value & 0xf0ff0000) >> 16); + } + + /// CHECK-START: byte Main.$noinline$redundantAndIntToByteShift20(int) instruction_simplifier (before) + /// CHECK-DAG: And + + /// CHECK-START: byte Main.$noinline$redundantAndIntToByteShift20(int) instruction_simplifier (after) + /// CHECK-NOT: And + public static byte $noinline$redundantAndIntToByteShift20(int value) { + return (byte) ((value & 0xfff00000) >> 20); + } + + /// CHECK-START: byte Main.$noinline$redundantAndIntToByteShift25(int) instruction_simplifier (before) + /// CHECK-DAG: And + + /// CHECK-START: byte Main.$noinline$redundantAndIntToByteShift25(int) instruction_simplifier (after) + /// CHECK-NOT: And + public static byte $noinline$redundantAndIntToByteShift25(int value) { + return (byte) ((value & 0xfe000000) >> 25); + } + + /// CHECK-START: byte Main.$noinline$redundantAndIntToByteShift24(int) instruction_simplifier (before) + /// CHECK-DAG: And + + /// CHECK-START: byte Main.$noinline$redundantAndIntToByteShift24(int) instruction_simplifier (after) + /// CHECK-NOT: And + public static byte $noinline$redundantAndIntToByteShift24(int value) { + return (byte) ((value & 0xff000000) >> 24); + } + + /// CHECK-START: byte Main.$noinline$redundantAndIntToByteShift31(int) instruction_simplifier (before) + /// CHECK-DAG: And + + /// CHECK-START: byte Main.$noinline$redundantAndIntToByteShift31(int) instruction_simplifier (after) + /// CHECK-NOT: And + public static byte $noinline$redundantAndIntToByteShift31(int value) { + return (byte) ((value & 0xff000000) >> 31); + } + + /// CHECK-START: byte Main.$noinline$redundantAndShortToByteShortAndConstant(short) instruction_simplifier (before) + /// CHECK-DAG: And + + /// CHECK-START: byte Main.$noinline$redundantAndShortToByteShortAndConstant(short) instruction_simplifier (after) + /// CHECK-NOT: And + public static byte $noinline$redundantAndShortToByteShortAndConstant(short value) { + short and_constant = (short) 0xff00; + return (byte) ((value & and_constant) >> 16); + } + + /// CHECK-START: byte Main.$noinline$redundantAndIntToByteShortAndConstant(int) instruction_simplifier (before) + /// CHECK-DAG: And + + /// CHECK-START: byte Main.$noinline$redundantAndIntToByteShortAndConstant(int) instruction_simplifier (after) + /// CHECK-NOT: And + public static byte $noinline$redundantAndIntToByteShortAndConstant(int value) { + short and_constant = (short) 0xff00; + return (byte) ((value & and_constant) >> 16); + } + public static void main(String[] args) throws Exception { Class smaliTests2 = Class.forName("SmaliTests2"); Method $noinline$XorAllOnes = smaliTests2.getMethod("$noinline$XorAllOnes", int.class); @@ -2793,6 +3006,48 @@ public class Main { assertIntEquals(0, $noinline$singleCharStringIndexOfAfter('x', -1)); assertIntEquals(-1, $noinline$singleCharStringIndexOfAfter('x', 1)); assertIntEquals(-1, $noinline$singleCharStringIndexOfAfter('Z', -1)); + + assertIntEquals(0x65,$noinline$redundantAndNotRedundant(0x7fff6f45)); + assertIntEquals(0x5e,$noinline$redundantAndOtherUse(0x7fff6f45)); + + assertIntEquals(0x79, $noinline$redundantAndShortToByteShift2((short) 0x6de7)); + assertIntEquals(0x79, $noinline$redundantAndShortToByteShift2((short) 0xfde7)); + assertIntEquals(0x7a, $noinline$redundantAndShortToByteShift5((short) 0x6f45)); + assertIntEquals(-6, $noinline$redundantAndShortToByteShift5((short) 0xff45)); + assertIntEquals(0x6f, $noinline$redundantAndShortToByteShift8((short) 0x6f45)); + assertIntEquals(-1, $noinline$redundantAndShortToByteShift8((short) 0xff45)); + assertIntEquals(0x37, $noinline$redundantAndShortToByteShift9NotRedundant((short) 0x6f45)); + assertIntEquals(127, $noinline$redundantAndShortToByteShift9NotRedundant((short) 0xff45)); + assertIntEquals(127, $noinline$redundantAndShortToByteShift10NotRedundant((short) 0xffff)); + assertIntEquals(6, $noinline$redundantAndShortToByteShift12((short) 0x6f45)); + assertIntEquals(-1, $noinline$redundantAndShortToByteShift12((short) 0xff45)); + assertIntEquals(0, $noinline$redundantAndShortToByteShift15((short) 0x6f45)); + assertIntEquals(-1, $noinline$redundantAndShortToByteShift15((short) 0xff45)); + assertIntEquals(0, $noinline$redundantAndShortToByteShift16((short) 0x6f45)); + assertIntEquals(-1, $noinline$redundantAndShortToByteShift16((short) 0xff45)); + assertIntEquals(0, $noinline$redundantAndShortToByteShortAndConstant((short) 0x6f45)); + assertIntEquals(-1, $noinline$redundantAndShortToByteShortAndConstant((short) 0xff45)); + + assertIntEquals(0x79, $noinline$redundantAndIntToByteShift2(0x7fff6de7)); + assertIntEquals(0x79, $noinline$redundantAndIntToByteShift2(0xfffffde7)); + assertIntEquals(0x7a, $noinline$redundantAndIntToByteShift5(0x7fff6f45)); + assertIntEquals(-6, $noinline$redundantAndIntToByteShift5(0xffffff45)); + assertIntEquals(0x6f, $noinline$redundantAndIntToByteShift8(0x7fff6f45)); + assertIntEquals(-1, $noinline$redundantAndIntToByteShift8(0xffffff45)); + assertIntEquals(-73, $noinline$redundantAndIntToByteShift9(0x7fff6f45)); + assertIntEquals(-1, $noinline$redundantAndIntToByteShift9(0xffffff45)); + assertIntEquals(0x6f, $noinline$redundantAndIntToByteShift16(0x7f6fffff)); + assertIntEquals(0x6f, $noinline$redundantAndIntToByteShift16(0xff6fff45)); + assertIntEquals(0x6f, $noinline$redundantAndIntToByteShift20(0x76ffffff)); + assertIntEquals(0x6f, $noinline$redundantAndIntToByteShift20(0xf6ffff45)); + assertIntEquals(0x7f, $noinline$redundantAndIntToByteShift24(0x7fffffff)); + assertIntEquals(-1, $noinline$redundantAndIntToByteShift24(0xffffff45)); + assertIntEquals(0x3f, $noinline$redundantAndIntToByteShift25(0x7fffffff)); + assertIntEquals(-1, $noinline$redundantAndIntToByteShift25(0xffffff45)); + assertIntEquals(0, $noinline$redundantAndIntToByteShift31(0x7fffffff)); + assertIntEquals(-1, $noinline$redundantAndIntToByteShift31(0xffffff45)); + assertIntEquals(-1, $noinline$redundantAndIntToByteShortAndConstant(0x7fffff45)); + assertIntEquals(-1, $noinline$redundantAndIntToByteShortAndConstant(0xffffff45)); } private static boolean $inline$true() { return true; } |