| Chad Rosier | e6b8761 | 2014-06-30 14:51:14 +0000 | [diff] [blame^] | 1 | ; RUN: llc < %s -march=aarch64 | FileCheck %s |
| 2 | |
| 3 | ; Convert mul x, pow2 to shift. |
| 4 | ; Convert mul x, pow2 +/- 1 to shift + add/sub. |
| 5 | |
| 6 | define i32 @test2(i32 %x) { |
| 7 | ; CHECK-LABEL: test2 |
| 8 | ; CHECK: lsl w0, w0, #1 |
| 9 | |
| 10 | %mul = shl nsw i32 %x, 1 |
| 11 | ret i32 %mul |
| 12 | } |
| 13 | |
| 14 | define i32 @test3(i32 %x) { |
| 15 | ; CHECK-LABEL: test3 |
| 16 | ; CHECK: add w0, w0, w0, lsl #1 |
| 17 | |
| 18 | %mul = mul nsw i32 %x, 3 |
| 19 | ret i32 %mul |
| 20 | } |
| 21 | |
| 22 | define i32 @test4(i32 %x) { |
| 23 | ; CHECK-LABEL: test4 |
| 24 | ; CHECK: lsl w0, w0, #2 |
| 25 | |
| 26 | %mul = shl nsw i32 %x, 2 |
| 27 | ret i32 %mul |
| 28 | } |
| 29 | |
| 30 | define i32 @test5(i32 %x) { |
| 31 | ; CHECK-LABEL: test5 |
| 32 | ; CHECK: add w0, w0, w0, lsl #2 |
| 33 | |
| 34 | |
| 35 | %mul = mul nsw i32 %x, 5 |
| 36 | ret i32 %mul |
| 37 | } |
| 38 | |
| 39 | define i32 @test7(i32 %x) { |
| 40 | ; CHECK-LABEL: test7 |
| 41 | ; CHECK: lsl {{w[0-9]+}}, w0, #3 |
| 42 | ; CHECK: sub w0, {{w[0-9]+}}, w0 |
| 43 | |
| 44 | %mul = mul nsw i32 %x, 7 |
| 45 | ret i32 %mul |
| 46 | } |
| 47 | |
| 48 | define i32 @test8(i32 %x) { |
| 49 | ; CHECK-LABEL: test8 |
| 50 | ; CHECK: lsl w0, w0, #3 |
| 51 | |
| 52 | %mul = shl nsw i32 %x, 3 |
| 53 | ret i32 %mul |
| 54 | } |
| 55 | |
| 56 | define i32 @test9(i32 %x) { |
| 57 | ; CHECK-LABEL: test9 |
| 58 | ; CHECK: add w0, w0, w0, lsl #3 |
| 59 | |
| 60 | %mul = mul nsw i32 %x, 9 |
| 61 | ret i32 %mul |
| 62 | } |
| 63 | |
| 64 | ; Convert mul x, -pow2 to shift. |
| 65 | ; Convert mul x, -(pow2 +/- 1) to shift + add/sub. |
| 66 | |
| 67 | define i32 @ntest2(i32 %x) { |
| 68 | ; CHECK-LABEL: ntest2 |
| 69 | ; CHECK: neg w0, w0, lsl #1 |
| 70 | |
| 71 | %mul = mul nsw i32 %x, -2 |
| 72 | ret i32 %mul |
| 73 | } |
| 74 | |
| 75 | define i32 @ntest3(i32 %x) { |
| 76 | ; CHECK-LABEL: ntest3 |
| 77 | ; CHECK: add {{w[0-9]+}}, w0, w0, lsl #1 |
| 78 | ; CHECK: neg w0, {{w[0-9]+}} |
| 79 | |
| 80 | %mul = mul nsw i32 %x, -3 |
| 81 | ret i32 %mul |
| 82 | } |
| 83 | |
| 84 | define i32 @ntest4(i32 %x) { |
| 85 | ; CHECK-LABEL: ntest4 |
| 86 | ; CHECK:neg w0, w0, lsl #2 |
| 87 | |
| 88 | %mul = mul nsw i32 %x, -4 |
| 89 | ret i32 %mul |
| 90 | } |
| 91 | |
| 92 | define i32 @ntest5(i32 %x) { |
| 93 | ; CHECK-LABEL: ntest5 |
| 94 | ; CHECK: add {{w[0-9]+}}, w0, w0, lsl #2 |
| 95 | ; CHECK: neg w0, {{w[0-9]+}} |
| 96 | %mul = mul nsw i32 %x, -5 |
| 97 | ret i32 %mul |
| 98 | } |
| 99 | |
| 100 | define i32 @ntest7(i32 %x) { |
| 101 | ; CHECK-LABEL: ntest7 |
| 102 | ; CHECK: sub w0, w0, w0, lsl #3 |
| 103 | |
| 104 | %mul = mul nsw i32 %x, -7 |
| 105 | ret i32 %mul |
| 106 | } |
| 107 | |
| 108 | define i32 @ntest8(i32 %x) { |
| 109 | ; CHECK-LABEL: ntest8 |
| 110 | ; CHECK: neg w0, w0, lsl #3 |
| 111 | |
| 112 | %mul = mul nsw i32 %x, -8 |
| 113 | ret i32 %mul |
| 114 | } |
| 115 | |
| 116 | define i32 @ntest9(i32 %x) { |
| 117 | ; CHECK-LABEL: ntest9 |
| 118 | ; CHECK: add {{w[0-9]+}}, w0, w0, lsl #3 |
| 119 | ; CHECK: neg w0, {{w[0-9]+}} |
| 120 | |
| 121 | %mul = mul nsw i32 %x, -9 |
| 122 | ret i32 %mul |
| 123 | } |