1 ; RUN: opt -basicaa -loop-idiom < %s -S | FileCheck %s
2 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
3 target triple = "x86_64-apple-darwin10.0.0"
5 define void @test1(i8* %Base, i64 %Size) nounwind ssp {
6 bb.nph: ; preds = %entry
9 for.body: ; preds = %bb.nph, %for.body
10 %indvar = phi i64 [ 0, %bb.nph ], [ %indvar.next, %for.body ]
11 %I.0.014 = getelementptr i8* %Base, i64 %indvar
12 store i8 0, i8* %I.0.014, align 1
13 %indvar.next = add i64 %indvar, 1
14 %exitcond = icmp eq i64 %indvar.next, %Size
15 br i1 %exitcond, label %for.end, label %for.body
17 for.end: ; preds = %for.body, %entry
20 ; CHECK: call void @llvm.memset.p0i8.i64(i8* %Base, i8 0, i64 %Size, i32 1, i1 false)
24 ; This is a loop that was rotated but where the blocks weren't merged. This
25 ; shouldn't perturb us.
26 define void @test1a(i8* %Base, i64 %Size) nounwind ssp {
27 bb.nph: ; preds = %entry
30 for.body: ; preds = %bb.nph, %for.body
31 %indvar = phi i64 [ 0, %bb.nph ], [ %indvar.next, %for.body.cont ]
32 %I.0.014 = getelementptr i8* %Base, i64 %indvar
33 store i8 0, i8* %I.0.014, align 1
34 %indvar.next = add i64 %indvar, 1
35 br label %for.body.cont
37 %exitcond = icmp eq i64 %indvar.next, %Size
38 br i1 %exitcond, label %for.end, label %for.body
40 for.end: ; preds = %for.body, %entry
43 ; CHECK: call void @llvm.memset.p0i8.i64(i8* %Base, i8 0, i64 %Size, i32 1, i1 false)
48 define void @test2(i32* %Base, i64 %Size) nounwind ssp {
50 %cmp10 = icmp eq i64 %Size, 0
51 br i1 %cmp10, label %for.end, label %for.body
53 for.body: ; preds = %entry, %for.body
54 %i.011 = phi i64 [ %inc, %for.body ], [ 0, %entry ]
55 %add.ptr.i = getelementptr i32* %Base, i64 %i.011
56 store i32 16843009, i32* %add.ptr.i, align 4
57 %inc = add nsw i64 %i.011, 1
58 %exitcond = icmp eq i64 %inc, %Size
59 br i1 %exitcond, label %for.end, label %for.body
61 for.end: ; preds = %for.body, %entry
64 ; CHECK: br i1 %cmp10,
65 ; CHECK: %tmp = mul i64 %Size, 4
66 ; CHECK: call void @llvm.memset.p0i8.i64(i8* %Base1, i8 1, i64 %tmp, i32 4, i1 false)
70 ; This is a case where there is an extra may-aliased store in the loop, we can't
72 define void @test3(i32* %Base, i64 %Size, i8 *%MayAlias) nounwind ssp {
76 for.body: ; preds = %entry, %for.body
77 %i.011 = phi i64 [ %inc, %for.body ], [ 0, %entry ]
78 %add.ptr.i = getelementptr i32* %Base, i64 %i.011
79 store i32 16843009, i32* %add.ptr.i, align 4
81 store i8 42, i8* %MayAlias
82 %inc = add nsw i64 %i.011, 1
83 %exitcond = icmp eq i64 %inc, %Size
84 br i1 %exitcond, label %for.end, label %for.body
86 for.end: ; preds = %entry
94 ;; TODO: We should be able to promote this memset. Not yet though.
95 define void @test4(i8* %Base) nounwind ssp {
96 bb.nph: ; preds = %entry
97 %Base100 = getelementptr i8* %Base, i64 1000
100 for.body: ; preds = %bb.nph, %for.body
101 %indvar = phi i64 [ 0, %bb.nph ], [ %indvar.next, %for.body ]
102 %I.0.014 = getelementptr i8* %Base, i64 %indvar
103 store i8 0, i8* %I.0.014, align 1
105 ;; Store beyond the range memset, should be safe to promote.
106 store i8 42, i8* %Base100
108 %indvar.next = add i64 %indvar, 1
109 %exitcond = icmp eq i64 %indvar.next, 100
110 br i1 %exitcond, label %for.end, label %for.body
112 for.end: ; preds = %for.body, %entry
115 ; CHECK-TODO: call void @llvm.memset.p0i8.i64(i8* %Base, i8 0, i64 100, i32 1, i1 false)
116 ; CHECK-TODO-NOT: store
119 ; This can't be promoted: the memset is a store of a loop variant value.
120 define void @test5(i8* %Base, i64 %Size) nounwind ssp {
121 bb.nph: ; preds = %entry
124 for.body: ; preds = %bb.nph, %for.body
125 %indvar = phi i64 [ 0, %bb.nph ], [ %indvar.next, %for.body ]
126 %I.0.014 = getelementptr i8* %Base, i64 %indvar
128 %V = trunc i64 %indvar to i8
129 store i8 %V, i8* %I.0.014, align 1
130 %indvar.next = add i64 %indvar, 1
131 %exitcond = icmp eq i64 %indvar.next, %Size
132 br i1 %exitcond, label %for.end, label %for.body
134 for.end: ; preds = %for.body, %entry
143 define void @test6(i64 %Size) nounwind ssp {
145 %Base = alloca i8, i32 10000
146 %Dest = alloca i8, i32 10000
149 for.body: ; preds = %bb.nph, %for.body
150 %indvar = phi i64 [ 0, %bb.nph ], [ %indvar.next, %for.body ]
151 %I.0.014 = getelementptr i8* %Base, i64 %indvar
152 %DestI = getelementptr i8* %Dest, i64 %indvar
153 %V = load i8* %I.0.014, align 1
154 store i8 %V, i8* %DestI, align 1
155 %indvar.next = add i64 %indvar, 1
156 %exitcond = icmp eq i64 %indvar.next, %Size
157 br i1 %exitcond, label %for.end, label %for.body
159 for.end: ; preds = %for.body, %entry
162 ; CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* %Dest, i8* %Base, i64 %Size, i32 1, i1 false)
168 ; This is a loop that was rotated but where the blocks weren't merged. This
169 ; shouldn't perturb us.
170 define void @test7(i8* %Base, i64 %Size) nounwind ssp {
171 bb.nph: ; preds = %entry
174 for.body: ; preds = %bb.nph, %for.body
175 %indvar = phi i64 [ 0, %bb.nph ], [ %indvar.next, %for.body.cont ]
176 br label %for.body.cont
178 %I.0.014 = getelementptr i8* %Base, i64 %indvar
179 store i8 0, i8* %I.0.014, align 1
180 %indvar.next = add i64 %indvar, 1
181 %exitcond = icmp eq i64 %indvar.next, %Size
182 br i1 %exitcond, label %for.end, label %for.body
184 for.end: ; preds = %for.body, %entry
187 ; CHECK: call void @llvm.memset.p0i8.i64(i8* %Base, i8 0, i64 %Size, i32 1, i1 false)