1 ; RUN: opt -S -basicaa -licm -licm-n2-threshold=0 -enable-mssa-loop-dependency=false %s | FileCheck %s
2 ; RUN: opt -S -basicaa -licm -licm-n2-threshold=0 -enable-mssa-loop-dependency=true -verify-memoryssa %s | FileCheck %s --check-prefix=ALIAS-N2
3 ; RUN: opt -licm -basicaa -licm-n2-threshold=200 < %s -S | FileCheck %s --check-prefix=ALIAS-N2
5 ; RUN: opt -aa-pipeline=basic-aa -licm-n2-threshold=0 -passes='require<aa>,require<targetir>,require<scalar-evolution>,require<opt-remark-emit>,loop(licm)' < %s -S | FileCheck %s
6 ; RUN: opt -aa-pipeline=basic-aa -licm-n2-threshold=0 -passes='require<aa>,require<targetir>,require<scalar-evolution>,require<opt-remark-emit>,loop-mssa(licm)' < %s -S | FileCheck %s --check-prefix=ALIAS-N2
7 ; RUN: opt -aa-pipeline=basic-aa -licm-n2-threshold=200 -passes='require<aa>,require<targetir>,require<scalar-evolution>,require<opt-remark-emit>,loop(licm)' < %s -S | FileCheck %s --check-prefix=ALIAS-N2
9 declare i32 @foo() readonly argmemonly nounwind
10 declare i32 @foo2() readonly nounwind
11 declare i32 @bar(i32* %loc2) readonly argmemonly nounwind
13 define void @test(i32* %loc) {
17 ; ALIAS-N2-LABEL: @test
19 ; ALIAS-N2-LABEL: loop:
23 %res = call i32 @foo()
24 store i32 %res, i32* %loc
28 ; Negative test: show argmemonly is required
29 define void @test_neg(i32* %loc) {
30 ; CHECK-LABEL: @test_neg
33 ; ALIAS-N2-LABEL: @test_neg
34 ; ALIAS-N2-LABEL: loop:
39 %res = call i32 @foo2()
40 store i32 %res, i32* %loc
44 define void @test2(i32* noalias %loc, i32* noalias %loc2) {
48 ; ALIAS-N2-LABEL: @test2
50 ; ALIAS-N2-LABEL: loop:
54 %res = call i32 @bar(i32* %loc2)
55 store i32 %res, i32* %loc
59 ; Negative test: %might clobber gep
60 define void @test3(i32* %loc) {
64 ; ALIAS-N2-LABEL: @test3
65 ; ALIAS-N2-LABEL: loop:
70 %res = call i32 @bar(i32* %loc)
71 %gep = getelementptr i32, i32 *%loc, i64 1000000
72 store i32 %res, i32* %gep
77 ; Negative test: %loc might alias %loc2
78 define void @test4(i32* %loc, i32* %loc2) {
82 ; ALIAS-N2-LABEL: @test4
83 ; ALIAS-N2-LABEL: loop:
88 %res = call i32 @bar(i32* %loc2)
89 store i32 %res, i32* %loc
93 declare i32 @foo_new(i32*) readonly
94 ; With the default AST mechanism used by LICM for alias analysis,
95 ; we clump foo_new with bar.
96 ; With the N2 Alias analysis diagnostic tool, we are able to hoist the
97 ; argmemonly bar call out of the loop.
98 ; Using MemorySSA we can also hoist bar.
100 define void @test5(i32* %loc2, i32* noalias %loc) {
101 ; ALIAS-N2-LABEL: @test5
103 ; ALIAS-N2-LABEL: loop:
105 ; CHECK-LABEL: @test5
111 %res1 = call i32 @bar(i32* %loc2)
112 %res = call i32 @foo_new(i32* %loc2)
113 store volatile i32 %res1, i32* %loc
118 ; memcpy doesn't write to it's source argument, so loads to that location
119 ; can still be hoisted
120 define void @test6(i32* noalias %loc, i32* noalias %loc2) {
121 ; CHECK-LABEL: @test6
122 ; CHECK: %val = load i32, i32* %loc2
124 ; CHECK: @llvm.memcpy
125 ; ALIAS-N2-LABEL: @test6
126 ; ALIAS-N2: %val = load i32, i32* %loc2
127 ; ALIAS-N2-LABEL: loop:
128 ; ALIAS-N2: @llvm.memcpy
132 %val = load i32, i32* %loc2
133 store i32 %val, i32* %loc
134 %dest = bitcast i32* %loc to i8*
135 %src = bitcast i32* %loc2 to i8*
136 call void @llvm.memcpy.p0i8.p0i8.i64(i8* %dest, i8* %src, i64 8, i1 false)
140 define void @test7(i32* noalias %loc, i32* noalias %loc2) {
141 ; CHECK-LABEL: @test7
142 ; CHECK: %val = load i32, i32* %loc2
144 ; CHECK: @custom_memcpy
145 ; ALIAS-N2-LABEL: @test7
146 ; ALIAS-N2: %val = load i32, i32* %loc2
147 ; ALIAS-N2-LABEL: loop:
148 ; ALIAS-N2: @custom_memcpy
152 %val = load i32, i32* %loc2
153 store i32 %val, i32* %loc
154 %dest = bitcast i32* %loc to i8*
155 %src = bitcast i32* %loc2 to i8*
156 call void @custom_memcpy(i8* %dest, i8* %src)
160 declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture writeonly, i8* nocapture readonly, i64, i1)
161 declare void @custom_memcpy(i8* nocapture writeonly, i8* nocapture readonly) argmemonly nounwind