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
6 ; We should be able to hoist loads in presence of read only calls and stores
9 ; Since LICM uses the AST mechanism for alias analysis, we will clump
10 ; together all loads and stores in one set along with the read-only call.
11 ; This prevents hoisting load that doesn't alias with any other memory
14 declare void @foo(i64, i32*) readonly
16 ; hoist the load out with the n2-threshold
17 ; since it doesn't alias with the store.
18 ; default AST mechanism clumps all memory locations in one set because of the
20 define void @test1(i32* %ptr) {
21 ; CHECK-LABEL: @test1(
24 ; CHECK: %val = load i32, i32* %ptr
26 ; ALIAS-N2-LABEL: @test1(
27 ; ALIAS-N2-LABEL: entry:
28 ; ALIAS-N2: %val = load i32, i32* %ptr
29 ; ALIAS-N2-LABEL: loop:
34 %x = phi i32 [ 0, %entry ], [ %x.inc, %loop ]
35 %val = load i32, i32* %ptr
36 call void @foo(i64 4, i32* %ptr)
37 %p2 = getelementptr i32, i32* %ptr, i32 1
38 store volatile i32 0, i32* %p2
39 %x.inc = add i32 %x, %val
43 ; can hoist out load with the default AST and the alias analysis mechanism.
44 define void @test2(i32* %ptr) {
45 ; CHECK-LABEL: @test2(
47 ; CHECK: %val = load i32, i32* %ptr
50 ; ALIAS-N2-LABEL: @test2(
51 ; ALIAS-N2-LABEL: entry:
52 ; ALIAS-N2: %val = load i32, i32* %ptr
53 ; ALIAS-N2-LABEL: loop:
58 %x = phi i32 [ 0, %entry ], [ %x.inc, %loop ]
59 %val = load i32, i32* %ptr
60 call void @foo(i64 4, i32* %ptr)
61 %x.inc = add i32 %x, %val
65 ; cannot hoist load since not guaranteed to execute
66 define void @test3(i32* %ptr) {
67 ; CHECK-LABEL: @test3(
70 ; CHECK: %val = load i32, i32* %ptr
72 ; ALIAS-N2-LABEL: @test3(
73 ; ALIAS-N2-LABEL: entry:
74 ; ALIAS-N2-LABEL: loop:
75 ; ALIAS-N2: %val = load i32, i32* %ptr
80 %x = phi i32 [ 0, %entry ], [ %x.inc, %loop ]
81 call void @foo(i64 4, i32* %ptr)
82 %val = load i32, i32* %ptr
83 %x.inc = add i32 %x, %val