1 ; RUN: opt -S -basicaa -licm -licm-n2-threshold=0 %s | FileCheck %s
2 ; RUN: opt -licm -basicaa -licm-n2-threshold=200 < %s -S | FileCheck %s --check-prefix=ALIAS-N2
3 ; 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
4 ; 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
5 ; RUN: opt -S -basicaa -licm -licm-n2-threshold=0 -enable-mssa-loop-dependency=true -verify-memoryssa %s | FileCheck %s --check-prefix=ALIAS-N2
7 declare i32 @foo() readonly argmemonly nounwind
8 declare i32 @foo2() readonly nounwind
9 declare i32 @bar(i32* %loc2) readonly argmemonly nounwind
11 define void @test(i32* %loc) {
15 ; ALIAS-N2-LABEL: @test
17 ; ALIAS-N2-LABEL: loop:
21 %res = call i32 @foo()
22 store i32 %res, i32* %loc
26 ; Negative test: show argmemonly is required
27 define void @test_neg(i32* %loc) {
28 ; CHECK-LABEL: @test_neg
31 ; ALIAS-N2-LABEL: @test_neg
32 ; ALIAS-N2-LABEL: loop:
37 %res = call i32 @foo2()
38 store i32 %res, i32* %loc
42 define void @test2(i32* noalias %loc, i32* noalias %loc2) {
46 ; ALIAS-N2-LABEL: @test2
48 ; ALIAS-N2-LABEL: loop:
52 %res = call i32 @bar(i32* %loc2)
53 store i32 %res, i32* %loc
57 ; Negative test: %might clobber gep
58 define void @test3(i32* %loc) {
62 ; ALIAS-N2-LABEL: @test3
63 ; ALIAS-N2-LABEL: loop:
68 %res = call i32 @bar(i32* %loc)
69 %gep = getelementptr i32, i32 *%loc, i64 1000000
70 store i32 %res, i32* %gep
75 ; Negative test: %loc might alias %loc2
76 define void @test4(i32* %loc, i32* %loc2) {
80 ; ALIAS-N2-LABEL: @test4
81 ; ALIAS-N2-LABEL: loop:
86 %res = call i32 @bar(i32* %loc2)
87 store i32 %res, i32* %loc
91 declare i32 @foo_new(i32*) readonly
92 ; With the default AST mechanism used by LICM for alias analysis,
93 ; we clump foo_new with bar.
94 ; With the N2 Alias analysis diagnostic tool, we are able to hoist the
95 ; argmemonly bar call out of the loop.
96 ; Using MemorySSA we can also hoist bar.
98 define void @test5(i32* %loc2, i32* noalias %loc) {
99 ; ALIAS-N2-LABEL: @test5
101 ; ALIAS-N2-LABEL: loop:
103 ; CHECK-LABEL: @test5
109 %res1 = call i32 @bar(i32* %loc2)
110 %res = call i32 @foo_new(i32* %loc2)
111 store volatile i32 %res1, i32* %loc
116 ; memcpy doesn't write to it's source argument, so loads to that location
117 ; can still be hoisted
118 define void @test6(i32* noalias %loc, i32* noalias %loc2) {
119 ; CHECK-LABEL: @test6
120 ; CHECK: %val = load i32, i32* %loc2
122 ; CHECK: @llvm.memcpy
123 ; ALIAS-N2-LABEL: @test6
124 ; ALIAS-N2: %val = load i32, i32* %loc2
125 ; ALIAS-N2-LABEL: loop:
126 ; ALIAS-N2: @llvm.memcpy
130 %val = load i32, i32* %loc2
131 store i32 %val, i32* %loc
132 %dest = bitcast i32* %loc to i8*
133 %src = bitcast i32* %loc2 to i8*
134 call void @llvm.memcpy.p0i8.p0i8.i64(i8* %dest, i8* %src, i64 8, i1 false)
138 define void @test7(i32* noalias %loc, i32* noalias %loc2) {
139 ; CHECK-LABEL: @test7
140 ; CHECK: %val = load i32, i32* %loc2
142 ; CHECK: @custom_memcpy
143 ; ALIAS-N2-LABEL: @test7
144 ; ALIAS-N2: %val = load i32, i32* %loc2
145 ; ALIAS-N2-LABEL: loop:
146 ; ALIAS-N2: @custom_memcpy
150 %val = load i32, i32* %loc2
151 store i32 %val, i32* %loc
152 %dest = bitcast i32* %loc to i8*
153 %src = bitcast i32* %loc2 to i8*
154 call void @custom_memcpy(i8* %dest, i8* %src)
158 declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture writeonly, i8* nocapture readonly, i64, i1)
159 declare void @custom_memcpy(i8* nocapture writeonly, i8* nocapture readonly) argmemonly nounwind