1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
| ; RUN: opt -licm -basicaa -licm-n2-threshold=0 < %s -S | FileCheck %s
; RUN: opt -licm -basicaa -licm-n2-threshold=200 < %s -S | FileCheck %s --check-prefix=ALIAS-N2
; 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
; 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
define void @test1(i1 %cond, i32* %ptr) {
; CHECK-LABEL: @test1(
; CHECK-LABEL: entry:
; CHECK: call {}* @llvm.invariant.start.p0i32(i64 4, i32* %ptr)
; CHECK: %val = load i32, i32* %ptr
; CHECK-LABEL: loop:
; ALIAS-N2-LABEL: @test1(
; ALIAS-N2-LABEL: entry:
; ALIAS-N2: call {}* @llvm.invariant.start.p0i32(i64 4, i32* %ptr)
; ALIAS-N2: %val = load i32, i32* %ptr
; ALIAS-N2-LABEL: loop:
entry:
br label %loop
loop:
%x = phi i32 [ 0, %entry ], [ %x.inc, %loop ]
call {}* @llvm.invariant.start.p0i32(i64 4, i32* %ptr)
%val = load i32, i32* %ptr
%x.inc = add i32 %x, %val
br label %loop
}
;; despite the loop varying invariant.start, we should be
;; able to hoist the load
define void @test2(i1 %cond, i32* %ptr) {
; CHECK-LABEL: @test2(
; CHECK-LABEL: entry:
; CHECK: %val = load i32, i32* %ptr
; CHECK-LABEL: loop:
; CHECK: call {}* @llvm.invariant.start.p0i32(i64 4, i32* %piv)
; ALIAS-N2-LABEL: @test2(
; ALIAS-N2-LABEL: entry:
; ALIAS-N2: %val = load i32, i32* %ptr
; ALIAS-N2-LABEL: loop:
; ALIAS-N2: call {}* @llvm.invariant.start.p0i32(i64 4, i32* %piv)
entry:
br label %loop
loop:
%x = phi i32 [ 0, %entry ], [ %x.inc, %loop ]
%piv = getelementptr i32, i32* %ptr, i32 %x
call {}* @llvm.invariant.start.p0i32(i64 4, i32* %piv)
%val = load i32, i32* %ptr
%x.inc = add i32 %x, %val
br label %loop
}
define void @test3(i1 %cond, i32* %ptr) {
; CHECK-LABEL: @test3(
; CHECK-LABEL: entry:
; CHECK: call {}* @llvm.invariant.start.p0i32(i64 4, i32* %ptr)
; CHECK: %val = load i32, i32* %ptr
; CHECK-LABEL: loop:
; ALIAS-N2-LABEL: @test3(
; ALIAS-N2-LABEL: entry:
; ALIAS-N2: call {}* @llvm.invariant.start.p0i32(i64 4, i32* %ptr)
; ALIAS-N2: %val = load i32, i32* %ptr
; ALIAS-N2-LABEL: loop:
entry:
br label %loop
loop:
%x = phi i32 [ 0, %entry ], [ %x.inc, %loop ]
call {}* @llvm.invariant.start.p0i32(i64 4, i32* %ptr)
%val = load i32, i32* %ptr
%p2 = getelementptr i32, i32* %ptr, i32 1
store volatile i32 0, i32* %p2
%x.inc = add i32 %x, %val
br label %loop
}
; can't hoist due to init in loop, only well defined if loop exits
; on first iteration, but we don't bother checking for that currently
define void @test4(i1 %cond, i32* %ptr) {
; CHECK-LABEL: @test4(
; CHECK-LABEL: entry:
; CHECK-LABEL: loop:
; CHECK: store i32 0, i32* %ptr
; CHECK: call {}* @llvm.invariant.start.p0i32(i64 4, i32* %ptr)
; CHECK: %val = load i32, i32* %ptr
; ALIAS-N2-LABEL: @test4(
; ALIAS-N2-LABEL: entry:
; ALIAS-N2-LABEL: loop:
; ALIAS-N2: store i32 0, i32* %ptr
; ALIAS-N2: call {}* @llvm.invariant.start.p0i32(i64 4, i32* %ptr)
; ALIAS-N2: %val = load i32, i32* %ptr
entry:
br label %loop
loop:
%x = phi i32 [ 0, %entry ], [ %x.inc, %loop ]
store i32 0, i32* %ptr
call {}* @llvm.invariant.start.p0i32(i64 4, i32* %ptr)
%val = load i32, i32* %ptr
%x.inc = add i32 %x, %val
br label %loop
}
; don't try to reason about scopes
define void @test5(i1 %cond, i32* %ptr) {
; CHECK-LABEL: @test5(
; CHECK-LABEL: entry:
; CHECK-LABEL: loop:
; CHECK: store i32 0, i32* %ptr
; CHECK: call {}* @llvm.invariant.start.p0i32(i64 4, i32* %ptr)
; CHECK: %val = load i32, i32* %ptr
; ALIAS-N2-LABEL: @test5(
; ALIAS-N2-LABEL: entry:
; ALIAS-N2-LABEL: loop:
; ALIAS-N2: store i32 0, i32* %ptr
; ALIAS-N2: call {}* @llvm.invariant.start.p0i32(i64 4, i32* %ptr)
; ALIAS-N2: %val = load i32, i32* %ptr
entry:
br label %loop
loop:
%x = phi i32 [ 0, %entry ], [ %x.inc, %loop ]
store i32 0, i32* %ptr
%scope = call {}* @llvm.invariant.start.p0i32(i64 4, i32* %ptr)
%val = load i32, i32* %ptr
call void @llvm.invariant.end.p0i32({}* %scope, i64 4, i32* %ptr)
%x.inc = add i32 %x, %val
br label %loop
}
declare {}* @llvm.invariant.start.p0i32(i64, i32*)
declare void @llvm.invariant.end.p0i32({}*, i64, i32*)
|