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 %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 ; We should be able to hoist loads in presence of read only calls and stores
12 ; Since LICM uses the AST mechanism for alias analysis, we will clump
13 ; together all loads and stores in one set along with the read-only call.
14 ; This prevents hoisting load that doesn't alias with any other memory
17 declare void @foo(i64, i32*) readonly
19 ; hoist the load out with the n2-threshold
20 ; since it doesn't alias with the store.
21 ; default AST mechanism clumps all memory locations in one set because of the
23 define void @test1(i32* %ptr) {
24 ; CHECK-LABEL: @test1(
27 ; CHECK: %val = load i32, i32* %ptr
29 ; ALIAS-N2-LABEL: @test1(
30 ; ALIAS-N2-LABEL: entry:
31 ; ALIAS-N2: %val = load i32, i32* %ptr
32 ; ALIAS-N2-LABEL: loop:
37 %x = phi i32 [ 0, %entry ], [ %x.inc, %loop ]
38 %val = load i32, i32* %ptr
39 call void @foo(i64 4, i32* %ptr)
40 %p2 = getelementptr i32, i32* %ptr, i32 1
41 store volatile i32 0, i32* %p2
42 %x.inc = add i32 %x, %val
46 ; can hoist out load with the default AST and the alias analysis mechanism.
47 define void @test2(i32* %ptr) {
48 ; CHECK-LABEL: @test2(
50 ; CHECK: %val = load i32, i32* %ptr
53 ; ALIAS-N2-LABEL: @test2(
54 ; ALIAS-N2-LABEL: entry:
55 ; ALIAS-N2: %val = load i32, i32* %ptr
56 ; ALIAS-N2-LABEL: loop:
61 %x = phi i32 [ 0, %entry ], [ %x.inc, %loop ]
62 %val = load i32, i32* %ptr
63 call void @foo(i64 4, i32* %ptr)
64 %x.inc = add i32 %x, %val
68 ; cannot hoist load since not guaranteed to execute
69 define void @test3(i32* %ptr) {
70 ; CHECK-LABEL: @test3(
73 ; CHECK: %val = load i32, i32* %ptr
75 ; ALIAS-N2-LABEL: @test3(
76 ; ALIAS-N2-LABEL: entry:
77 ; ALIAS-N2-LABEL: loop:
78 ; ALIAS-N2: %val = load i32, i32* %ptr
83 %x = phi i32 [ 0, %entry ], [ %x.inc, %loop ]
84 call void @foo(i64 4, i32* %ptr)
85 %val = load i32, i32* %ptr
86 %x.inc = add i32 %x, %val