conditions-ranges-with-undef.ll
6.77 KB
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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt < %s -ipsccp -S | FileCheck %s
declare void @use(i1)
; We can simplify the conditions in the true block, because the condition
; allows us to replace all uses of %a in the block with a constant.
define void @val_undef_eq() {
; CHECK-LABEL: @val_undef_eq(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[A:%.*]] = add i32 undef, 0
; CHECK-NEXT: [[BC_1:%.*]] = icmp eq i32 [[A]], 10
; CHECK-NEXT: br i1 [[BC_1]], label [[TRUE:%.*]], label [[FALSE:%.*]]
; CHECK: true:
; CHECK-NEXT: call void @use(i1 false)
; CHECK-NEXT: call void @use(i1 true)
; CHECK-NEXT: ret void
; CHECK: false:
; CHECK-NEXT: ret void
;
entry:
%a = add i32 undef, 0
%bc.1 = icmp eq i32 %a, 10
br i1 %bc.1, label %true, label %false
true:
%f.1 = icmp ne i32 %a, 10
call void @use(i1 %f.1)
%f.2 = icmp eq i32 %a, 10
call void @use(i1 %f.2)
ret void
false:
ret void
}
declare void @use.i32(i32)
; It is not allowed to use the range information from the condition to remove
; %a.127 = and ... in the true block, as %a could be undef.
define void @val_undef_range() {
; CHECK-LABEL: @val_undef_range(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[A:%.*]] = add i32 undef, 0
; CHECK-NEXT: [[BC_1:%.*]] = icmp ult i32 [[A]], 127
; CHECK-NEXT: br i1 [[BC_1]], label [[TRUE:%.*]], label [[FALSE:%.*]]
; CHECK: true:
; CHECK-NEXT: call void @use(i1 false)
; CHECK-NEXT: [[A_127:%.*]] = and i32 [[A]], 127
; CHECK-NEXT: call void @use.i32(i32 [[A_127]])
; CHECK-NEXT: ret void
; CHECK: false:
; CHECK-NEXT: ret void
;
entry:
%a = add i32 undef, 0
%bc.1 = icmp ult i32 %a, 127
br i1 %bc.1, label %true, label %false
true:
%f.1 = icmp eq i32 %a, 128
call void @use(i1 %f.1)
%a.127 = and i32 %a, 127
call void @use.i32(i32 %a.127)
ret void
false:
ret void
}
; All uses of %p can be replaced by a constant (10).
define void @val_singlecrfromundef_range(i1 %cond) {
; CHECK-LABEL: @val_singlecrfromundef_range(
; CHECK-NEXT: entry:
; CHECK-NEXT: br i1 [[COND:%.*]], label [[INC1:%.*]], label [[INC2:%.*]]
; CHECK: inc1:
; CHECK-NEXT: br label [[IF:%.*]]
; CHECK: inc2:
; CHECK-NEXT: br label [[IF]]
; CHECK: if:
; CHECK-NEXT: br label [[TRUE:%.*]]
; CHECK: true:
; CHECK-NEXT: call void @use(i1 false)
; CHECK-NEXT: [[P_127:%.*]] = and i32 10, 127
; CHECK-NEXT: call void @use.i32(i32 [[P_127]])
; CHECK-NEXT: ret void
;
entry:
br i1 %cond, label %inc1, label %inc2
inc1:
br label %if
inc2:
br label %if
if:
%p = phi i32 [ 10, %inc1 ], [ undef, %inc2 ]
%bc.1 = icmp ult i32 %p, 127
br i1 %bc.1, label %true, label %false
true:
%f.1 = icmp eq i32 %p, 128
call void @use(i1 %f.1)
%p.127 = and i32 %p, 127
call void @use.i32(i32 %p.127)
ret void
false:
ret void
}
; It is not allowed to use the information from the condition ([0, 128))
; to remove a.127.2 = and i32 %p, 127, as %p might be undef.
define void @val_undef_to_cr_to_overdef_range(i32 %a, i1 %cond) {
; CHECK-LABEL: @val_undef_to_cr_to_overdef_range(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[A_127:%.*]] = and i32 [[A:%.*]], 127
; CHECK-NEXT: br i1 [[COND:%.*]], label [[INC1:%.*]], label [[INC2:%.*]]
; CHECK: inc1:
; CHECK-NEXT: br label [[IF:%.*]]
; CHECK: inc2:
; CHECK-NEXT: br label [[IF]]
; CHECK: if:
; CHECK-NEXT: [[P:%.*]] = phi i32 [ [[A_127]], [[INC1]] ], [ undef, [[INC2]] ]
; CHECK-NEXT: [[BC_1:%.*]] = icmp ult i32 [[P]], 100
; CHECK-NEXT: br i1 [[BC_1]], label [[TRUE:%.*]], label [[FALSE:%.*]]
; CHECK: true:
; CHECK-NEXT: call void @use(i1 false)
; CHECK-NEXT: [[P_127:%.*]] = and i32 [[P]], 127
; CHECK-NEXT: call void @use.i32(i32 [[P_127]])
; CHECK-NEXT: ret void
; CHECK: false:
; CHECK-NEXT: ret void
;
entry:
%a.127 = and i32 %a, 127
br i1 %cond, label %inc1, label %inc2
inc1:
br label %if
inc2:
br label %if
if:
%p = phi i32 [ %a.127, %inc1 ], [ undef, %inc2 ]
%bc.1 = icmp ult i32 %p, 100
br i1 %bc.1, label %true, label %false
true:
%f.1 = icmp eq i32 %p, 128
call void @use(i1 %f.1)
%p.127 = and i32 %p, 127
call void @use.i32(i32 %p.127)
ret void
false:
ret void
}
; All uses of %p can be replaced by a constant (10), we are allowed to use it
; as a bound too.
define void @bound_singlecrfromundef(i32 %a, i1 %cond) {
; CHECK-LABEL: @bound_singlecrfromundef(
; CHECK-NEXT: entry:
; CHECK-NEXT: br i1 [[COND:%.*]], label [[BB1:%.*]], label [[BB2:%.*]]
; CHECK: bb1:
; CHECK-NEXT: br label [[PRED:%.*]]
; CHECK: bb2:
; CHECK-NEXT: br label [[PRED]]
; CHECK: pred:
; CHECK-NEXT: [[BC_1:%.*]] = icmp ugt i32 [[A:%.*]], 10
; CHECK-NEXT: br i1 [[BC_1]], label [[TRUE:%.*]], label [[FALSE:%.*]]
; CHECK: true:
; CHECK-NEXT: call void @use(i1 false)
; CHECK-NEXT: call void @use(i1 true)
; CHECK-NEXT: [[A_127:%.*]] = and i32 [[A]], 127
; CHECK-NEXT: call void @use.i32(i32 [[A_127]])
; CHECK-NEXT: ret void
; CHECK: false:
; CHECK-NEXT: ret void
;
entry:
br i1 %cond, label %bb1, label %bb2
bb1:
br label %pred
bb2:
br label %pred
pred:
%p = phi i32 [ undef, %bb1 ], [ 10, %bb2 ]
%bc.1 = icmp ugt i32 %a, %p
br i1 %bc.1, label %true, label %false
true:
%f.1 = icmp eq i32 %a, 5
call void @use(i1 %f.1)
%t.1 = icmp ne i32 %a, 5
call void @use(i1 %t.1)
%a.127 = and i32 %a, 127
call void @use.i32(i32 %a.127)
ret void
false:
ret void
}
; It is not allowed to use the information from %p as a bound, because an
; incoming value is undef.
define void @bound_range_and_undef(i32 %a, i1 %cond) {
; CHECK-LABEL: @bound_range_and_undef(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[A_10:%.*]] = and i32 [[A:%.*]], 127
; CHECK-NEXT: br i1 [[COND:%.*]], label [[BB1:%.*]], label [[BB2:%.*]]
; CHECK: bb1:
; CHECK-NEXT: br label [[PRED:%.*]]
; CHECK: bb2:
; CHECK-NEXT: br label [[PRED]]
; CHECK: pred:
; CHECK-NEXT: [[P:%.*]] = phi i32 [ [[A_10]], [[BB1]] ], [ undef, [[BB2]] ]
; CHECK-NEXT: [[BC_1:%.*]] = icmp ugt i32 [[A]], [[P]]
; CHECK-NEXT: br i1 [[BC_1]], label [[TRUE:%.*]], label [[FALSE:%.*]]
; CHECK: true:
; CHECK-NEXT: [[F_1:%.*]] = icmp eq i32 [[A]], 300
; CHECK-NEXT: call void @use(i1 [[F_1]])
; CHECK-NEXT: [[A_127_2:%.*]] = and i32 [[P]], 127
; CHECK-NEXT: call void @use.i32(i32 [[A_127_2]])
; CHECK-NEXT: ret void
; CHECK: false:
; CHECK-NEXT: ret void
;
entry:
%a.10 = and i32 %a, 127
br i1 %cond, label %bb1, label %bb2
bb1:
br label %pred
bb2:
br label %pred
pred:
%p = phi i32 [ %a.10, %bb1 ], [ undef, %bb2 ]
%bc.1 = icmp ugt i32 %a, %p
br i1 %bc.1, label %true, label %false
true:
%f.1 = icmp eq i32 %a, 300
call void @use(i1 %f.1)
%a.127.2 = and i32 %p, 127
call void @use.i32(i32 %a.127.2)
ret void
false:
ret void
}