1 ; RUN: opt -S -basic-aa -licm %s -enable-new-pm=0 | FileCheck %s
2 ; RUN: opt -aa-pipeline=basic-aa -passes='require<aa>,require<targetir>,require<scalar-evolution>,require<opt-remark-emit>,loop-mssa(licm)' < %s -S | FileCheck %s
4 ; We should be able to hoist loads in presence of read only calls and stores
7 ; Since LICM uses the AST mechanism for alias analysis, we will clump
8 ; together all loads and stores in one set along with the read-only call.
9 ; This prevents hoisting load that doesn't alias with any other memory
12 declare void @foo(i64, i32*) readonly
14 ; hoist the load out with the n2-threshold
15 ; since it doesn't alias with the store.
16 ; default AST mechanism clumps all memory locations in one set because of the
18 define void @test1(i32* %ptr) {
19 ; CHECK-LABEL: @test1(
21 ; CHECK: %val = load i32, i32* %ptr
27 %x = phi i32 [ 0, %entry ], [ %x.inc, %loop ]
28 %val = load i32, i32* %ptr
29 call void @foo(i64 4, i32* %ptr)
30 %p2 = getelementptr i32, i32* %ptr, i32 1
31 store volatile i32 0, i32* %p2
32 %x.inc = add i32 %x, %val
36 ; can hoist out load with the default AST and the alias analysis mechanism.
37 define void @test2(i32* %ptr) {
38 ; CHECK-LABEL: @test2(
40 ; CHECK: %val = load i32, i32* %ptr
46 %x = phi i32 [ 0, %entry ], [ %x.inc, %loop ]
47 %val = load i32, i32* %ptr
48 call void @foo(i64 4, i32* %ptr)
49 %x.inc = add i32 %x, %val
53 ; cannot hoist load since not guaranteed to execute
54 define void @test3(i32* %ptr) {
55 ; CHECK-LABEL: @test3(
58 ; CHECK: %val = load i32, i32* %ptr
63 %x = phi i32 [ 0, %entry ], [ %x.inc, %loop ]
64 call void @foo(i64 4, i32* %ptr)
65 %val = load i32, i32* %ptr
66 %x.inc = add i32 %x, %val