File: phi-speculation.ll

package info (click to toggle)
llvm-toolchain-15 1%3A15.0.6-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,554,644 kB
  • sloc: cpp: 5,922,452; ansic: 1,012,136; asm: 674,362; python: 191,568; objc: 73,855; f90: 42,327; lisp: 31,913; pascal: 11,973; javascript: 10,144; sh: 9,421; perl: 7,447; ml: 5,527; awk: 3,523; makefile: 2,520; xml: 885; cs: 573; fortran: 567
file content (208 lines) | stat: -rw-r--r-- 6,767 bytes parent folder | download
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
target datalayout =
"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"

; RUN: opt < %s -aa-pipeline=basic-aa -passes=aa-eval -print-all-alias-modref-info -disable-output 2>&1 | FileCheck %s

; ptr_phi and ptr2_phi do not alias.
; CHECK: test_noalias_1
; CHECK: NoAlias: i32* %ptr2_phi, i32* %ptr_phi
; CHECK: NoAlias: i32* %ptr2_inc, i32* %ptr_inc
define i32 @test_noalias_1(i32* %ptr2, i32 %count, i32* %coeff) {
entry:
  %ptr = getelementptr inbounds i32, i32* %ptr2, i64 1
  br label %while.body

while.body:
  %num = phi i32 [ %count, %entry ], [ %dec, %while.body ]
  %ptr_phi = phi i32* [ %ptr, %entry ], [ %ptr_inc, %while.body ]
  %ptr2_phi = phi i32* [ %ptr2, %entry ], [ %ptr2_inc, %while.body ]
  %result.09 = phi i32 [ 0 , %entry ], [ %add, %while.body ]
  %dec = add nsw i32 %num, -1
  %0 = load i32, i32* %ptr_phi, align 4
  store i32 %0, i32* %ptr2_phi, align 4
  %1 = load i32, i32* %coeff, align 4
  %2 = load i32, i32* %ptr_phi, align 4
  %mul = mul nsw i32 %1, %2
  %add = add nsw i32 %mul, %result.09
  %tobool = icmp eq i32 %dec, 0
  %ptr_inc = getelementptr inbounds i32, i32* %ptr_phi, i64 1
  %ptr2_inc = getelementptr inbounds i32, i32* %ptr2_phi, i64 1
  load i32, i32* %ptr_inc
  load i32, i32* %ptr2_inc
  br i1 %tobool, label %the_exit, label %while.body

the_exit:
  ret i32 %add
}

; CHECK: test_noalias_2
; CHECK-DAG: NoAlias: i32* %ptr_outer_phi, i32* %ptr_outer_phi2
; CHECK-DAG: NoAlias: i32* %ptr2_inc_outer, i32* %ptr_inc_outer
; CHECK-DAG: NoAlias: i32* %ptr2_phi, i32* %ptr_phi
; CHECK-DAG: NoAlias: i32* %ptr2_inc, i32* %ptr_inc
define i32 @test_noalias_2(i32* %ptr2, i32 %count, i32* %coeff) {
entry:
  %ptr = getelementptr inbounds i32, i32* %ptr2, i64 1
  br label %outer.while.header

outer.while.header:
  %ptr_outer_phi = phi i32* [%ptr_inc_outer, %outer.while.backedge], [ %ptr, %entry]
  %ptr_outer_phi2 = phi i32* [%ptr2_inc_outer, %outer.while.backedge], [ %ptr2, %entry]
  %num.outer = phi i32 [ %count, %entry ], [ %dec.outer, %outer.while.backedge ]
  %ignore1 = load i32, i32* %ptr_outer_phi
  %ignore2 = load i32, i32* %ptr_outer_phi2
  br label %while.body

while.body:
  %num = phi i32 [ %count, %outer.while.header ], [ %dec, %while.body ]
  %ptr_phi = phi i32* [ %ptr_outer_phi, %outer.while.header ], [ %ptr_inc, %while.body ]
  %ptr2_phi = phi i32* [ %ptr_outer_phi2, %outer.while.header ], [ %ptr2_inc, %while.body ]
  %result.09 = phi i32 [ 0 , %outer.while.header ], [ %add, %while.body ]
  %dec = add nsw i32 %num, -1
  %0 = load i32, i32* %ptr_phi, align 4
  store i32 %0, i32* %ptr2_phi, align 4
  %1 = load i32, i32* %coeff, align 4
  %2 = load i32, i32* %ptr_phi, align 4
  %mul = mul nsw i32 %1, %2
  %add = add nsw i32 %mul, %result.09
  %tobool = icmp eq i32 %dec, 0
  %ptr_inc = getelementptr inbounds i32, i32* %ptr_phi, i64 1
  %ptr2_inc = getelementptr inbounds i32, i32* %ptr2_phi, i64 1
  load i32, i32* %ptr_inc
  load i32, i32* %ptr2_inc
  br i1 %tobool, label %outer.while.backedge, label %while.body

outer.while.backedge:
  %ptr_inc_outer = getelementptr inbounds i32, i32* %ptr_phi, i64 1
  %ptr2_inc_outer = getelementptr inbounds i32, i32* %ptr2_phi, i64 1
  load i32, i32* %ptr_inc_outer
  load i32, i32* %ptr2_inc_outer
  %dec.outer = add nsw i32 %num.outer, -1
  %br.cond = icmp eq i32 %dec.outer, 0
  br i1 %br.cond, label %the_exit, label %outer.while.header

the_exit:
  ret i32 %add
}

; CHECK: test_noalias_3
; CHECK: MayAlias: i8* %ptr2_phi, i8* %ptr_phi
define i32 @test_noalias_3(i8* noalias %x, i8* noalias %y, i8* noalias %z,
                           i32 %count) {
entry:
  br label %while.body

while.body:
  %num = phi i32 [ %count, %entry ], [ %dec, %while.body ]
  %ptr_phi = phi i8* [ %x, %entry ], [ %z, %while.body ]
  %ptr2_phi = phi i8* [ %y, %entry ], [ %ptr_phi, %while.body ]
  load i8, i8* %ptr_phi
  load i8, i8* %ptr2_phi
  %dec = add nsw i32 %num, -1
  %tobool = icmp eq i32 %dec, 0
  br i1 %tobool, label %the_exit, label %while.body

the_exit:
  ret i32 1
}

; CHECK-LABEL: test_different_stride_noalias
; CHECK: NoAlias: i8* %x.base, i16* %y.base
; CHECK: NoAlias: i8* %x, i16* %y
; CHECK: NoAlias: i8* %x.next, i16* %y.next
define void @test_different_stride_noalias(i1 %c, i8* noalias %x.base, i16* noalias %y.base) {
entry:
  load i8, i8* %x.base
  load i16, i16* %y.base
  br label %loop

loop:
  %x = phi i8* [ %x.base, %entry ], [ %x.next, %loop ]
  %y = phi i16* [ %y.base, %entry ], [ %y.next, %loop ]
  load i8, i8* %x
  load i16, i16* %y
  %x.next = getelementptr i8, i8* %x, i64 1
  %y.next = getelementptr i16, i16* %y, i64 1
  load i8, i8* %x.next
  load i16, i16* %y.next
  br i1 %c, label %loop, label %exit

exit:
  ret void
}

; CHECK-LABEL: test_no_loop_mustalias
; CHECK: MustAlias: i16* %z16, i8* %z8
define void @test_no_loop_mustalias(i1 %c, i8* noalias %x8, i8* noalias %y8) {
  br i1 %c, label %if, label %else

if:
  %x16 = bitcast i8* %x8 to i16*
  br label %end

else:
  %y16 = bitcast i8* %y8 to i16*
  br label %end

end:
  %z8 = phi i8* [ %x8, %if ], [ %y8, %else ]
  %z16 = phi i16* [ %x16, %if ], [ %y16, %else ]
  load i8, i8* %z8
  load i16, i16* %z16
  ret void
}

; CHECK-LABEL: test_same_stride_mustalias
; CHECK: MustAlias: i8* %x.base, i4* %y.base
; CHECK: MayAlias: i8* %x, i4* %y
; CHECK: MayAlias: i8* %x.next, i4* %y.next
; TODO: (x, y) could be MustAlias
define void @test_same_stride_mustalias(i1 %c, i8* noalias %x.base) {
entry:
  %y.base = bitcast i8* %x.base to i4*
  load i8, i8* %x.base
  load i4, i4* %y.base
  br label %loop

loop:
  %x = phi i8* [ %x.base, %entry ], [ %x.next, %loop ]
  %y = phi i4* [ %y.base, %entry ], [ %y.next, %loop ]
  load i8, i8* %x
  load i4, i4* %y
  %x.next = getelementptr i8, i8* %x, i64 1
  %y.next = getelementptr i4, i4* %y, i64 1
  load i8, i8* %x.next
  load i4, i4* %y.next
  br i1 %c, label %loop, label %exit

exit:
  ret void
}

; CHECK-LABEL: test_different_stride_mustalias
; CHECK: MustAlias: i8* %x.base, i16* %y.base
; CHECK: MayAlias: i8* %x, i16* %y
; CHECK: MayAlias: i8* %x.next, i16* %y.next
; Even though the base pointers MustAlias, the different strides don't preserve
; this property across iterations.
define void @test_different_stride_mustalias(i1 %c, i8* noalias %x.base) {
entry:
  %y.base = bitcast i8* %x.base to i16*
  load i8, i8* %x.base
  load i16, i16* %y.base
  br label %loop

loop:
  %x = phi i8* [ %x.base, %entry ], [ %x.next, %loop ]
  %y = phi i16* [ %y.base, %entry ], [ %y.next, %loop ]
  load i8, i8* %x
  load i16, i16* %y
  %x.next = getelementptr i8, i8* %x, i64 1
  %y.next = getelementptr i16, i16* %y, i64 1
  load i8, i8* %x.next
  load i16, i16* %y.next
  br i1 %c, label %loop, label %exit

exit:
  ret void
}