1 ; RUN: opt < %s -slsr -gvn -S | FileCheck %s
3 target datalayout = "e-i64:64-v16:16-v32:32-n16:32:64"
5 define void @shl(i32 %b, i32 %s) {
8 ; [[BASIS:%[a-zA-Z0-9]+]] = add i32 %b, %s
12 ; add i32 [[BASIS]], %s
13 call void @foo(i32 %2)
17 define void @stride_is_2s(i32 %b, i32 %s) {
18 ; CHECK-LABEL: @stride_is_2s(
20 ; CHECK: %s2 = shl i32 %s, 1
22 ; CHECK: [[t1:%[a-zA-Z0-9]+]] = add i32 %b, %s2
23 call void @foo(i32 %1)
26 ; CHECK: [[t2:%[a-zA-Z0-9]+]] = add i32 [[t1]], %s2
27 call void @foo(i32 %2)
30 ; CHECK: add i32 [[t2]], %s2
31 call void @foo(i32 %3)
35 define void @stride_is_3s(i32 %b, i32 %s) {
36 ; CHECK-LABEL: @stride_is_3s(
38 ; CHECK: [[t1:%[a-zA-Z0-9]+]] = add i32 %s, %b
39 call void @foo(i32 %1)
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)
47 ; CHECK: add i32 [[t2]], [[bump]]
48 call void @foo(i32 %3)
63 define void @stride_is_minus_2s(i32 %b, i32 %s) {
64 ; CHECK-LABEL: @stride_is_minus_2s(
67 ; CHECK: [[t1:%[a-zA-Z0-9]+]] = add i32 %b, %s6
68 ; CHECK: call void @foo(i32 [[t1]])
69 call void @foo(i32 %1)
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]])
78 ; CHECK: [[t3:%[a-zA-Z0-9]+]] = sub i32 [[t2]], [[bump]]
79 call void @foo(i32 %3)
80 ; CHECK: call void @foo(i32 [[t3]])
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(
93 call void @foo(i32 %1)
95 ; CHECK: [[t:%[a-zA-Z0-9]+]] = add i32 %b, %s{{$}}
96 call void @foo(i32 %2)
97 ; CHECK: call void @foo(i32 [[t]])
101 declare void @foo(i32)