1 ; RUN: opt -S -basicaa -gvn < %s | FileCheck %s
2 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"
3 target triple = "i386-apple-darwin11.0.0"
5 @sortlist = external global [5001 x i32], align 4
7 define void @Bubble() nounwind noinline {
9 ; CHECK-NEXT: %tmp7.pre = load i32
14 ; CHECK: %tmp7 = phi i32
15 ; CHECK-NOT: %tmp7 = load i32
17 %indvar = phi i32 [ 0, %entry ], [ %tmp6, %if.end ]
18 %tmp5 = add i32 %indvar, 2
19 %arrayidx9 = getelementptr [5001 x i32], [5001 x i32]* @sortlist, i32 0, i32 %tmp5
20 %tmp6 = add i32 %indvar, 1
21 %arrayidx = getelementptr [5001 x i32], [5001 x i32]* @sortlist, i32 0, i32 %tmp6
22 %tmp7 = load i32, i32* %arrayidx, align 4
23 %tmp10 = load i32, i32* %arrayidx9, align 4
24 %cmp11 = icmp sgt i32 %tmp7, %tmp10
25 br i1 %cmp11, label %if.then, label %if.end
29 store i32 %tmp10, i32* %arrayidx, align 4
30 store i32 %tmp7, i32* %arrayidx9, align 4
34 %exitcond = icmp eq i32 %tmp6, 100
35 br i1 %exitcond, label %while.end.loopexit, label %while.body5
41 declare void @hold(i32) readonly
42 declare void @clobber()
44 ; This is a classic LICM case
45 define i32 @test1(i1 %cnd, i32* %p) {
49 ; CHECK-NEXT: %v1.pre = load i32, i32* %p
54 %v1 = load i32, i32* %p
55 call void @hold(i32 %v1)
60 ; Slightly more complicated case to highlight that MemoryDependenceAnalysis
61 ; can compute availability for internal control flow. In this case, because
62 ; the value is fully available across the backedge, we only need to establish
63 ; anticipation for the preheader block (which is trivial in this case.)
64 define i32 @test2(i1 %cnd, i32* %p) {
68 ; CHECK-NEXT: %v1.pre = load i32, i32* %p
73 %v1 = load i32, i32* %p
74 call void @hold(i32 %v1)
75 br i1 %cnd, label %bb1, label %bb2
88 ; TODO: at the moment, our anticipation check does not handle anything
89 ; other than straight-line unconditional fallthrough. This particular
90 ; case could be solved through either a backwards anticipation walk or
91 ; use of the "safe to speculate" status (if we annotate the param)
92 define i32 @test3(i1 %cnd, i32* %p) {
99 br i1 %cnd, label %bb1, label %bb2
109 ; CHECK: load i32, i32* %p
110 %v1 = load i32, i32* %p
111 call void @hold(i32 %v1)
115 ; Highlight that we can PRE into a latch block when there are multiple
116 ; latches only one of which clobbers an otherwise invariant value.
117 define i32 @test4(i1 %cnd, i32* %p) {
118 ; CHECK-LABEL: @test4
121 %v1 = load i32, i32* %p
122 call void @hold(i32 %v1)
126 ; CHECK-LABEL: header
127 %v2 = load i32, i32* %p
128 call void @hold(i32 %v2)
129 br i1 %cnd, label %bb1, label %bb2
136 ; CHECK: call void @clobber()
137 ; CHECK-NEXT: %v2.pre = load i32, i32* %p
138 ; CHECK-NEXT: br label %header
144 ; Highlight the fact that we can PRE into a single clobbering latch block
145 ; even in loop simplify form (though multiple applications of the same
147 define i32 @test5(i1 %cnd, i32* %p) {
148 ; CHECK-LABEL: @test5
151 %v1 = load i32, i32* %p
152 call void @hold(i32 %v1)
156 ; CHECK-LABEL: header
157 %v2 = load i32, i32* %p
158 call void @hold(i32 %v2)
159 br i1 %cnd, label %bb1, label %bb2
166 ; CHECK: call void @clobber()
167 ; CHECK-NEXT: %v2.pre.pre = load i32, i32* %p
168 ; CHECK-NEXT: br label %merge
177 declare void @llvm.experimental.guard(i1 %cnd, ...)
179 ; These two tests highlight speculation safety when we can not establish
180 ; anticipation (since the original load might actually not execcute)
181 define i32 @test6a(i1 %cnd, i32* %p) {
183 ; CHECK-LABEL: @test6a
187 ; CHECK-LABEL: header
188 ; CHECK: load i32, i32* %p
189 call void (i1, ...) @llvm.experimental.guard(i1 %cnd) ["deopt"()]
190 %v1 = load i32, i32* %p
191 call void @hold(i32 %v1)
195 define i32 @test6b(i1 %cnd, i32* dereferenceable(8) %p) {
197 ; CHECK-LABEL: @test6b
198 ; CHECK: load i32, i32* %p
202 ; CHECK-LABEL: header
203 call void (i1, ...) @llvm.experimental.guard(i1 %cnd) ["deopt"()]
204 %v1 = load i32, i32* %p
205 call void @hold(i32 %v1)