1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
| ; RUN: opt -S -basicaa -gvn < %s | FileCheck %s
target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128-n8:16:32"
target triple = "i386-apple-darwin11.0.0"
@sortlist = external global [5001 x i32], align 4
define void @Bubble() nounwind noinline {
; CHECK: entry:
; CHECK-NEXT: %tmp7.pre = load i32
entry:
br label %while.body5
; CHECK: while.body5:
; CHECK: %tmp7 = phi i32
; CHECK-NOT: %tmp7 = load i32
while.body5:
%indvar = phi i32 [ 0, %entry ], [ %tmp6, %if.end ]
%tmp5 = add i32 %indvar, 2
%arrayidx9 = getelementptr [5001 x i32], [5001 x i32]* @sortlist, i32 0, i32 %tmp5
%tmp6 = add i32 %indvar, 1
%arrayidx = getelementptr [5001 x i32], [5001 x i32]* @sortlist, i32 0, i32 %tmp6
%tmp7 = load i32, i32* %arrayidx, align 4
%tmp10 = load i32, i32* %arrayidx9, align 4
%cmp11 = icmp sgt i32 %tmp7, %tmp10
br i1 %cmp11, label %if.then, label %if.end
; CHECK: if.then:
if.then:
store i32 %tmp10, i32* %arrayidx, align 4
store i32 %tmp7, i32* %arrayidx9, align 4
br label %if.end
if.end:
%exitcond = icmp eq i32 %tmp6, 100
br i1 %exitcond, label %while.end.loopexit, label %while.body5
while.end.loopexit:
ret void
}
declare void @hold(i32) readonly
declare void @clobber()
; This is a classic LICM case
define i32 @test1(i1 %cnd, i32* %p) {
; CHECK-LABEL: @test1
entry:
; CHECK-LABEL: entry
; CHECK-NEXT: %v1.pre = load i32, i32* %p
br label %header
header:
; CHECK-LABEL: header
%v1 = load i32, i32* %p
call void @hold(i32 %v1)
br label %header
}
; Slightly more complicated case to highlight that MemoryDependenceAnalysis
; can compute availability for internal control flow. In this case, because
; the value is fully available across the backedge, we only need to establish
; anticipation for the preheader block (which is trivial in this case.)
define i32 @test2(i1 %cnd, i32* %p) {
; CHECK-LABEL: @test2
entry:
; CHECK-LABEL: entry
; CHECK-NEXT: %v1.pre = load i32, i32* %p
br label %header
header:
; CHECK-LABEL: header
%v1 = load i32, i32* %p
call void @hold(i32 %v1)
br i1 %cnd, label %bb1, label %bb2
bb1:
br label %merge
bb2:
br label %merge
merge:
br label %header
}
; TODO: at the moment, our anticipation check does not handle anything
; other than straight-line unconditional fallthrough. This particular
; case could be solved through either a backwards anticipation walk or
; use of the "safe to speculate" status (if we annotate the param)
define i32 @test3(i1 %cnd, i32* %p) {
entry:
; CHECK-LABEL: @test3
; CHECK-LABEL: entry
br label %header
header:
br i1 %cnd, label %bb1, label %bb2
bb1:
br label %merge
bb2:
br label %merge
merge:
; CHECK-LABEL: merge
; CHECK: load i32, i32* %p
%v1 = load i32, i32* %p
call void @hold(i32 %v1)
br label %header
}
; Highlight that we can PRE into a latch block when there are multiple
; latches only one of which clobbers an otherwise invariant value.
define i32 @test4(i1 %cnd, i32* %p) {
; CHECK-LABEL: @test4
entry:
; CHECK-LABEL: entry
%v1 = load i32, i32* %p
call void @hold(i32 %v1)
br label %header
header:
; CHECK-LABEL: header
%v2 = load i32, i32* %p
call void @hold(i32 %v2)
br i1 %cnd, label %bb1, label %bb2
bb1:
br label %header
bb2:
; CHECK-LABEL: bb2
; CHECK: call void @clobber()
; CHECK-NEXT: %v2.pre = load i32, i32* %p
; CHECK-NEXT: br label %header
call void @clobber()
br label %header
}
; Highlight the fact that we can PRE into a single clobbering latch block
; even in loop simplify form (though multiple applications of the same
; transformation).
define i32 @test5(i1 %cnd, i32* %p) {
; CHECK-LABEL: @test5
entry:
; CHECK-LABEL: entry
%v1 = load i32, i32* %p
call void @hold(i32 %v1)
br label %header
header:
; CHECK-LABEL: header
%v2 = load i32, i32* %p
call void @hold(i32 %v2)
br i1 %cnd, label %bb1, label %bb2
bb1:
br label %merge
bb2:
; CHECK-LABEL: bb2
; CHECK: call void @clobber()
; CHECK-NEXT: %v2.pre.pre = load i32, i32* %p
; CHECK-NEXT: br label %merge
call void @clobber()
br label %merge
merge:
br label %header
}
declare void @llvm.experimental.guard(i1 %cnd, ...)
; These two tests highlight speculation safety when we can not establish
; anticipation (since the original load might actually not execcute)
define i32 @test6a(i1 %cnd, i32* %p) {
entry:
; CHECK-LABEL: @test6a
br label %header
header:
; CHECK-LABEL: header
; CHECK: load i32, i32* %p
call void (i1, ...) @llvm.experimental.guard(i1 %cnd) ["deopt"()]
%v1 = load i32, i32* %p
call void @hold(i32 %v1)
br label %header
}
define i32 @test6b(i1 %cnd, i32* dereferenceable(8) %p) {
entry:
; CHECK-LABEL: @test6b
; CHECK: load i32, i32* %p
br label %header
header:
; CHECK-LABEL: header
call void (i1, ...) @llvm.experimental.guard(i1 %cnd) ["deopt"()]
%v1 = load i32, i32* %p
call void @hold(i32 %v1)
br label %header
}
|