implement the "no aliasing accesses in loop" safety check. This pass
[oota-llvm.git] / test / Transforms / LoopIdiom / basic.ll
1 ; RUN: opt -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"
4
5 define void @test1(i8* %Base, i64 %Size) nounwind ssp {
6 bb.nph:                                           ; preds = %entry
7   br label %for.body
8
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
16
17 for.end:                                          ; preds = %for.body, %entry
18   ret void
19 ; CHECK: @test1
20 ; CHECK: call void @llvm.memset.p0i8.i64(i8* %Base, i8 0, i64 %Size, i32 1, i1 false)
21 ; CHECK-NOT: store
22 }
23
24 define void @test2(i32* %Base, i64 %Size) nounwind ssp {
25 entry:
26   %cmp10 = icmp eq i64 %Size, 0
27   br i1 %cmp10, label %for.end, label %for.body
28
29 for.body:                                         ; preds = %entry, %for.body
30   %i.011 = phi i64 [ %inc, %for.body ], [ 0, %entry ]
31   %add.ptr.i = getelementptr i32* %Base, i64 %i.011
32   store i32 16843009, i32* %add.ptr.i, align 4
33   %inc = add nsw i64 %i.011, 1
34   %exitcond = icmp eq i64 %inc, %Size
35   br i1 %exitcond, label %for.end, label %for.body
36
37 for.end:                                          ; preds = %for.body, %entry
38   ret void
39 ; CHECK: @test2
40 ; CHECK: br i1 %cmp10,
41 ; CHECK: %tmp = mul i64 %Size, 4
42 ; CHECK: call void @llvm.memset.p0i8.i64(i8* %Base1, i8 1, i64 %tmp, i32 4, i1 false)
43 ; CHECK-NOT: store
44 }
45
46 ; This is a case where there is an extra may-aliased store in the loop, we can't
47 ; promote the memset.
48 define void @test3(i32* %Base, i64 %Size, i8 *%MayAlias) nounwind ssp {
49 entry:
50   br label %for.body
51
52 for.body:                                         ; preds = %entry, %for.body
53   %i.011 = phi i64 [ %inc, %for.body ], [ 0, %entry ]
54   %add.ptr.i = getelementptr i32* %Base, i64 %i.011
55   store i32 16843009, i32* %add.ptr.i, align 4
56   
57   store i8 42, i8* %MayAlias
58   %inc = add nsw i64 %i.011, 1
59   %exitcond = icmp eq i64 %inc, %Size
60   br i1 %exitcond, label %for.end, label %for.body
61
62 for.end:                                          ; preds = %entry
63   ret void
64 ; CHECK: @test3
65 ; CHECK-NOT: memset
66 ; CHECK: ret void
67 }