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 @slsr1(i32 %b, i32 %s) {
11 call void @foo(i32 %mul0)
15 %mul1 = mul i32 %b1, %s
16 call void @foo(i32 %mul1)
20 %mul2 = mul i32 %b2, %s
21 call void @foo(i32 %mul2)
26 define void @non_canonicalized(i32 %b, i32 %s) {
27 ; CHECK-LABEL: @non_canonicalized(
29 %mul0 = mul i32 %b, %s
32 call void @foo(i32 %mul0)
36 %mul1 = mul i32 %b1, %s
37 call void @foo(i32 %mul1)
41 %mul2 = mul i32 %b2, %s
42 call void @foo(i32 %mul2)
47 define void @or(i32 %a, i32 %s) {
51 %mul0 = mul i32 %b, %s
52 ; CHECK: [[base:[^ ]+]] = mul i32
53 call void @foo(i32 %mul0)
57 %mul1 = mul i32 %b1, %s
58 ; CHECK: add i32 [[base]], %s
59 call void @foo(i32 %mul1)
63 %mul2 = mul i32 %b2, %s
64 ; CHECK: mul i32 %b2, %s
65 call void @foo(i32 %mul2)
73 ; foo((a + 1) * (b + 1))
74 define void @slsr2(i32 %a, i32 %b) {
75 ; CHECK-LABEL: @slsr2(
78 %mul0 = mul i32 %a, %b
81 %mul1 = mul i32 %a1, %b
82 %mul2 = mul i32 %a, %b1
83 %mul3 = mul i32 %a1, %b1
85 call void @foo(i32 %mul0)
86 call void @foo(i32 %mul1)
87 call void @foo(i32 %mul2)
88 call void @foo(i32 %mul3)
93 ; The bump is a multiple of the stride.
101 ; mul1 = mul0 + bump; // GVN ensures mul1 and mul2 use the same bump.
102 ; mul2 = mul1 + bump;
103 define void @slsr3(i32 %b, i32 %s) {
104 ; CHECK-LABEL: @slsr3(
105 %mul0 = mul i32 %b, %s
107 call void @foo(i32 %mul0)
110 %mul1 = mul i32 %b1, %s
111 ; CHECK: [[BUMP:%[a-zA-Z0-9]+]] = shl i32 %s, 1
112 ; CHECK: %mul1 = add i32 %mul0, [[BUMP]]
113 call void @foo(i32 %mul1)
116 %mul2 = mul i32 %b2, %s
117 ; CHECK: %mul2 = add i32 %mul1, [[BUMP]]
118 call void @foo(i32 %mul2)
123 ; Do not rewrite a candidate if its potential basis does not dominate it.
128 define void @not_dominate(i1 %cond, i32 %a, i32 %b) {
129 ; CHECK-LABEL: @not_dominate(
132 br i1 %cond, label %then, label %merge
135 %mul0 = mul i32 %a, %b
136 ; CHECK: %mul0 = mul i32 %a, %b
137 call void @foo(i32 %mul0)
141 %mul1 = mul i32 %a1, %b
142 ; CHECK: %mul1 = mul i32 %a1, %b
143 call void @foo(i32 %mul1)
147 declare void @foo(i32)