1 ; RUN: opt < %s -passes=slsr,gvn -S | FileCheck %s
2 ; RUN: opt < %s -passes='slsr,gvn' -S | FileCheck %s
4 target datalayout = "e-i64:64-v16:16-v32:32-n16:32:64"
6 define void @slsr1(i32 %b, i32 %s) {
12 call void @foo(i32 %mul0)
16 %mul1 = mul i32 %b1, %s
17 call void @foo(i32 %mul1)
21 %mul2 = mul i32 %b2, %s
22 call void @foo(i32 %mul2)
27 define void @non_canonicalized(i32 %b, i32 %s) {
28 ; CHECK-LABEL: @non_canonicalized(
30 %mul0 = mul i32 %b, %s
33 call void @foo(i32 %mul0)
37 %mul1 = mul i32 %b1, %s
38 call void @foo(i32 %mul1)
42 %mul2 = mul i32 %b2, %s
43 call void @foo(i32 %mul2)
48 define void @or(i32 %a, i32 %s) {
52 %mul0 = mul i32 %b, %s
53 ; CHECK: [[base:[^ ]+]] = mul i32
54 call void @foo(i32 %mul0)
58 %mul1 = mul i32 %b1, %s
59 ; CHECK: add i32 [[base]], %s
60 call void @foo(i32 %mul1)
64 %mul2 = mul i32 %b2, %s
65 ; CHECK: mul i32 %b2, %s
66 call void @foo(i32 %mul2)
74 ; foo((a + 1) * (b + 1))
75 define void @slsr2(i32 %a, i32 %b) {
76 ; CHECK-LABEL: @slsr2(
79 %mul0 = mul i32 %a, %b
82 %mul1 = mul i32 %a1, %b
83 %mul2 = mul i32 %a, %b1
84 %mul3 = mul i32 %a1, %b1
86 call void @foo(i32 %mul0)
87 call void @foo(i32 %mul1)
88 call void @foo(i32 %mul2)
89 call void @foo(i32 %mul3)
94 ; The bump is a multiple of the stride.
102 ; mul1 = mul0 + bump; // GVN ensures mul1 and mul2 use the same bump.
103 ; mul2 = mul1 + bump;
104 define void @slsr3(i32 %b, i32 %s) {
105 ; CHECK-LABEL: @slsr3(
106 %mul0 = mul i32 %b, %s
108 call void @foo(i32 %mul0)
111 %mul1 = mul i32 %b1, %s
112 ; CHECK: [[BUMP:%[a-zA-Z0-9]+]] = shl i32 %s, 1
113 ; CHECK: %mul1 = add i32 %mul0, [[BUMP]]
114 call void @foo(i32 %mul1)
117 %mul2 = mul i32 %b2, %s
118 ; CHECK: %mul2 = add i32 %mul1, [[BUMP]]
119 call void @foo(i32 %mul2)
124 ; Do not rewrite a candidate if its potential basis does not dominate it.
129 define void @not_dominate(i1 %cond, i32 %a, i32 %b) {
130 ; CHECK-LABEL: @not_dominate(
133 br i1 %cond, label %then, label %merge
136 %mul0 = mul i32 %a, %b
137 ; CHECK: %mul0 = mul i32 %a, %b
138 call void @foo(i32 %mul0)
142 %mul1 = mul i32 %a1, %b
143 ; CHECK: %mul1 = mul i32 %a1, %b
144 call void @foo(i32 %mul1)
148 declare void @foo(i32)