1 ; RUN: opt < %s -slsr -gvn -S | FileCheck %s 2 3 target datalayout = "e-i64:64-v16:16-v32:32-n16:32:64" 4 5 define void @shl(i32 %b, i32 %s) { 6 ; CHECK-LABEL: @shl( 7 %1 = add i32 %b, %s 8 ; [[BASIS:%[a-zA-Z0-9]+]] = add i32 %b, %s 9 call void @foo(i32 %1) 10 %s2 = shl i32 %s, 1 11 %2 = add i32 %b, %s2 12 ; add i32 [[BASIS]], %s 13 call void @foo(i32 %2) 14 ret void 15 } 16 17 define void @stride_is_2s(i32 %b, i32 %s) { 18 ; CHECK-LABEL: @stride_is_2s( 19 %s2 = shl i32 %s, 1 20 ; CHECK: %s2 = shl i32 %s, 1 21 %1 = add i32 %b, %s2 22 ; CHECK: [[t1:%[a-zA-Z0-9]+]] = add i32 %b, %s2 23 call void @foo(i32 %1) 24 %s4 = shl i32 %s, 2 25 %2 = add i32 %b, %s4 26 ; CHECK: [[t2:%[a-zA-Z0-9]+]] = add i32 [[t1]], %s2 27 call void @foo(i32 %2) 28 %s6 = mul i32 %s, 6 29 %3 = add i32 %b, %s6 30 ; CHECK: add i32 [[t2]], %s2 31 call void @foo(i32 %3) 32 ret void 33 } 34 35 define void @stride_is_3s(i32 %b, i32 %s) { 36 ; CHECK-LABEL: @stride_is_3s( 37 %1 = add i32 %s, %b 38 ; CHECK: [[t1:%[a-zA-Z0-9]+]] = add i32 %s, %b 39 call void @foo(i32 %1) 40 %s4 = shl i32 %s, 2 41 %2 = add i32 %s4, %b 42 ; CHECK: [[bump:%[a-zA-Z0-9]+]] = mul i32 %s, 3 43 ; CHECK: [[t2:%[a-zA-Z0-9]+]] = add i32 [[t1]], [[bump]] 44 call void @foo(i32 %2) 45 %s7 = mul i32 %s, 7 46 %3 = add i32 %s7, %b 47 ; CHECK: add i32 [[t2]], [[bump]] 48 call void @foo(i32 %3) 49 ret void 50 } 51 52 ; foo(b + 6 * s); 53 ; foo(b + 4 * s); 54 ; foo(b + 2 * s); 55 ; => 56 ; t1 = b + 6 * s; 57 ; foo(t1); 58 ; s2 = 2 * s; 59 ; t2 = t1 - s2; 60 ; foo(t2); 61 ; t3 = t2 - s2; 62 ; foo(t3); 63 define void @stride_is_minus_2s(i32 %b, i32 %s) { 64 ; CHECK-LABEL: @stride_is_minus_2s( 65 %s6 = mul i32 %s, 6 66 %1 = add i32 %b, %s6 67 ; CHECK: [[t1:%[a-zA-Z0-9]+]] = add i32 %b, %s6 68 ; CHECK: call void @foo(i32 [[t1]]) 69 call void @foo(i32 %1) 70 %s4 = shl i32 %s, 2 71 %2 = add i32 %b, %s4 72 ; CHECK: [[bump:%[a-zA-Z0-9]+]] = shl i32 %s, 1 73 ; CHECK: [[t2:%[a-zA-Z0-9]+]] = sub i32 [[t1]], [[bump]] 74 call void @foo(i32 %2) 75 ; CHECK: call void @foo(i32 [[t2]]) 76 %s2 = shl i32 %s, 1 77 %3 = add i32 %b, %s2 78 ; CHECK: [[t3:%[a-zA-Z0-9]+]] = sub i32 [[t2]], [[bump]] 79 call void @foo(i32 %3) 80 ; CHECK: call void @foo(i32 [[t3]]) 81 ret void 82 } 83 84 ; t = b + (s << 3); 85 ; foo(t); 86 ; foo(b + s); 87 ; 88 ; do not rewrite b + s to t - 7 * s because the latter is more complicated. 89 define void @simple_enough(i32 %b, i32 %s) { 90 ; CHECK-LABEL: @simple_enough( 91 %s8 = shl i32 %s, 3 92 %1 = add i32 %b, %s8 93 call void @foo(i32 %1) 94 %2 = add i32 %b, %s 95 ; CHECK: [[t:%[a-zA-Z0-9]+]] = add i32 %b, %s{{$}} 96 call void @foo(i32 %2) 97 ; CHECK: call void @foo(i32 [[t]]) 98 ret void 99 } 100 101 define void @slsr_strided_add_128bit(i128 %b, i128 %s) { 102 ; CHECK-LABEL: @slsr_strided_add_128bit( 103 %s125 = shl i128 %s, 125 104 %s126 = shl i128 %s, 126 105 %1 = add i128 %b, %s125 106 ; CHECK: [[t1:%[a-zA-Z0-9]+]] = add i128 %b, %s125 107 call void @bar(i128 %1) 108 %2 = add i128 %b, %s126 109 ; CHECK: [[t2:%[a-zA-Z0-9]+]] = add i128 [[t1]], %s125 110 call void @bar(i128 %2) 111 ; CHECK: call void @bar(i128 [[t2]]) 112 ret void 113 } 114 115 declare void @foo(i32) 116 declare void @bar(i128) 117