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: sub w0, w0, w0, lsl #2 78 79 %mul = mul nsw i32 %x, -3 80 ret i32 %mul 81 } 82 83 define i32 @ntest4(i32 %x) { 84 ; CHECK-LABEL: ntest4 85 ; CHECK:neg w0, w0, lsl #2 86 87 %mul = mul nsw i32 %x, -4 88 ret i32 %mul 89 } 90 91 define i32 @ntest5(i32 %x) { 92 ; CHECK-LABEL: ntest5 93 ; CHECK: add {{w[0-9]+}}, w0, w0, lsl #2 94 ; CHECK: neg w0, {{w[0-9]+}} 95 %mul = mul nsw i32 %x, -5 96 ret i32 %mul 97 } 98 99 define i32 @ntest7(i32 %x) { 100 ; CHECK-LABEL: ntest7 101 ; CHECK: sub w0, w0, w0, lsl #3 102 103 %mul = mul nsw i32 %x, -7 104 ret i32 %mul 105 } 106 107 define i32 @ntest8(i32 %x) { 108 ; CHECK-LABEL: ntest8 109 ; CHECK: neg w0, w0, lsl #3 110 111 %mul = mul nsw i32 %x, -8 112 ret i32 %mul 113 } 114 115 define i32 @ntest9(i32 %x) { 116 ; CHECK-LABEL: ntest9 117 ; CHECK: add {{w[0-9]+}}, w0, w0, lsl #3 118 ; CHECK: neg w0, {{w[0-9]+}} 119 120 %mul = mul nsw i32 %x, -9 121 ret i32 %mul 122 } 123