fcmp-select.ll
7.62 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
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt < %s -instsimplify -S | FileCheck %s
; X == 42.0 ? X : 42.0 --> 42.0
define double @oeq(double %x) {
; CHECK-LABEL: @oeq(
; CHECK-NEXT: ret double 4.200000e+01
;
%cmp = fcmp oeq double %x, 42.0
%cond = select i1 %cmp, double %x, double 42.0
ret double %cond
}
; X == 42.0 ? 42.0 : X --> X
define float @oeq_swapped(float %x) {
; CHECK-LABEL: @oeq_swapped(
; CHECK-NEXT: ret float [[X:%.*]]
;
%cmp = fcmp oeq float %x, 42.0
%cond = select i1 %cmp, float 42.0, float %x
ret float %cond
}
; x != y ? x : y -> x if it's the right kind of != and at least
; one of x and y is not negative zero.
; X != 42.0 ? X : 42.0 --> X
define double @une(double %x) {
; CHECK-LABEL: @une(
; CHECK-NEXT: ret double [[X:%.*]]
;
%cmp = fcmp une double %x, 42.0
%cond = select i1 %cmp, double %x, double 42.0
ret double %cond
}
; X != 42.0 ? 42.0 : X --> 42.0
define double @une_swapped(double %x) {
; CHECK-LABEL: @une_swapped(
; CHECK-NEXT: ret double 4.200000e+01
;
%cmp = fcmp une double %x, 42.0
%cond = select i1 %cmp, double 42.0, double %x
ret double %cond
}
; X == 0.0 ? X : 0.0 --> ? (X could be -0.0)
define double @oeq_zero(double %x) {
; CHECK-LABEL: @oeq_zero(
; CHECK-NEXT: [[CMP:%.*]] = fcmp oeq double [[X:%.*]], 0.000000e+00
; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], double [[X]], double 0.000000e+00
; CHECK-NEXT: ret double [[COND]]
;
%cmp = fcmp oeq double %x, 0.0
%cond = select i1 %cmp, double %x, double 0.0
ret double %cond
}
; X == 0.0 ? 0.0 : X --> ? (change sign if X is -0.0)
define float @oeq_zero_swapped(float %x) {
; CHECK-LABEL: @oeq_zero_swapped(
; CHECK-NEXT: [[CMP:%.*]] = fcmp oeq float [[X:%.*]], 0.000000e+00
; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], float 0.000000e+00, float [[X]]
; CHECK-NEXT: ret float [[COND]]
;
%cmp = fcmp oeq float %x, 0.0
%cond = select i1 %cmp, float 0.0, float %x
ret float %cond
}
; X != 0.0 ? X : -0.0 --> ? (change sign if X is 0.0)
define double @une_zero(double %x) {
; CHECK-LABEL: @une_zero(
; CHECK-NEXT: [[CMP:%.*]] = fcmp une double [[X:%.*]], 0.000000e+00
; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], double [[X]], double -0.000000e+00
; CHECK-NEXT: ret double [[COND]]
;
%cmp = fcmp une double %x, 0.0
%cond = select i1 %cmp, double %x, double -0.0
ret double %cond
}
; X != 0.0 ? -0.0 : X --> ? (X could be 0.0)
define double @une_zero_swapped(double %x) {
; CHECK-LABEL: @une_zero_swapped(
; CHECK-NEXT: [[CMP:%.*]] = fcmp une double [[X:%.*]], 0.000000e+00
; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], double -0.000000e+00, double [[X]]
; CHECK-NEXT: ret double [[COND]]
;
%cmp = fcmp une double %x, 0.0
%cond = select i1 %cmp, double -0.0, double %x
ret double %cond
}
; X == 0.0 ? X : 0.0 --> 0.0
define double @oeq_zero_nsz(double %x) {
; CHECK-LABEL: @oeq_zero_nsz(
; CHECK-NEXT: ret double 0.000000e+00
;
%cmp = fcmp oeq double %x, 0.0
%cond = select nsz i1 %cmp, double %x, double 0.0
ret double %cond
}
; X == 0.0 ? 0.0 : X --> X
define float @oeq_zero_swapped_nsz(float %x) {
; CHECK-LABEL: @oeq_zero_swapped_nsz(
; CHECK-NEXT: ret float [[X:%.*]]
;
%cmp = fcmp oeq float %x, 0.0
%cond = select fast i1 %cmp, float 0.0, float %x
ret float %cond
}
; X != 0.0 ? X : 0.0 --> X
define double @une_zero_nsz(double %x) {
; CHECK-LABEL: @une_zero_nsz(
; CHECK-NEXT: ret double [[X:%.*]]
;
%cmp = fcmp une double %x, 0.0
%cond = select nsz ninf i1 %cmp, double %x, double 0.0
ret double %cond
}
; X != 0.0 ? 0.0 : X --> 0.0
define <2 x double> @une_zero_swapped_nsz(<2 x double> %x) {
; CHECK-LABEL: @une_zero_swapped_nsz(
; CHECK-NEXT: ret <2 x double> zeroinitializer
;
%cmp = fcmp une <2 x double> %x, <double 0.0, double 0.0>
%cond = select nsz <2 x i1> %cmp, <2 x double> <double 0.0, double 0.0>, <2 x double> %x
ret <2 x double> %cond
}
; X == Y ? X : Y --> Y
define double @oeq_nsz(double %x, double %y) {
; CHECK-LABEL: @oeq_nsz(
; CHECK-NEXT: ret double [[Y:%.*]]
;
%cmp = fcmp oeq double %x, %y
%cond = select fast i1 %cmp, double %x, double %y
ret double %cond
}
; X == Y ? Y : X --> X
define <2 x float> @oeq_swapped_nsz(<2 x float> %x, <2 x float> %y) {
; CHECK-LABEL: @oeq_swapped_nsz(
; CHECK-NEXT: ret <2 x float> [[X:%.*]]
;
%cmp = fcmp oeq <2 x float> %x, %y
%cond = select nsz nnan <2 x i1> %cmp, <2 x float> %y, <2 x float> %x
ret <2 x float> %cond
}
; X != Y ? X : Y --> X
define double @une_nsz(double %x, double %y) {
; CHECK-LABEL: @une_nsz(
; CHECK-NEXT: ret double [[X:%.*]]
;
%cmp = fcmp une double %x, %y
%cond = select nsz i1 %cmp, double %x, double %y
ret double %cond
}
; X != Y ? Y : X --> Y
define <2 x double> @une_swapped_nsz(<2 x double> %x, <2 x double> %y) {
; CHECK-LABEL: @une_swapped_nsz(
; CHECK-NEXT: ret <2 x double> [[Y:%.*]]
;
%cmp = fcmp une <2 x double> %x, %y
%cond = select fast <2 x i1> %cmp, <2 x double> %y, <2 x double> %x
ret <2 x double> %cond
}
; Harder - mismatched zero constants (not typical due to canonicalization):
; X != 0.0 ? X : -0.0 --> X
define double @une_zero_mismatch_nsz(double %x) {
; CHECK-LABEL: @une_zero_mismatch_nsz(
; CHECK-NEXT: [[CMP:%.*]] = fcmp une double [[X:%.*]], 0.000000e+00
; CHECK-NEXT: [[COND:%.*]] = select ninf nsz i1 [[CMP]], double [[X]], double -0.000000e+00
; CHECK-NEXT: ret double [[COND]]
;
%cmp = fcmp une double %x, 0.0
%cond = select nsz ninf i1 %cmp, double %x, double -0.0
ret double %cond
}
; Even harder - mismatched vector zero constants (not typical due to canonicalization):
; X != 0.0 ? -0.0 : X --> 0.0
define <2 x double> @une_zero_mismatch_swapped_nsz(<2 x double> %x) {
; CHECK-LABEL: @une_zero_mismatch_swapped_nsz(
; CHECK-NEXT: [[CMP:%.*]] = fcmp une <2 x double> [[X:%.*]], <double -0.000000e+00, double 0.000000e+00>
; CHECK-NEXT: [[COND:%.*]] = select nsz <2 x i1> [[CMP]], <2 x double> <double 0.000000e+00, double -0.000000e+00>, <2 x double> [[X]]
; CHECK-NEXT: ret <2 x double> [[COND]]
;
%cmp = fcmp une <2 x double> %x, <double -0.0, double 0.0>
%cond = select nsz <2 x i1> %cmp, <2 x double> <double 0.0, double -0.0>, <2 x double> %x
ret <2 x double> %cond
}
define double @une_could_be_negzero(double %x, double %y) {
; CHECK-LABEL: @une_could_be_negzero(
; CHECK-NEXT: [[CMP:%.*]] = fcmp une double [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], double [[X]], double [[Y]]
; CHECK-NEXT: ret double [[COND]]
;
%cmp = fcmp une double %x, %y
%cond = select i1 %cmp, double %x, double %y
ret double %cond
}
define double @une_swapped_could_be_negzero(double %x, double %y) {
; CHECK-LABEL: @une_swapped_could_be_negzero(
; CHECK-NEXT: [[CMP:%.*]] = fcmp une double [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], double [[Y]], double [[X]]
; CHECK-NEXT: ret double [[COND]]
;
%cmp = fcmp une double %x, %y
%cond = select i1 %cmp, double %y, double %x
ret double %cond
}
define double @one(double %x) {
; CHECK-LABEL: @one(
; CHECK-NEXT: [[CMP:%.*]] = fcmp one double [[X:%.*]], -1.000000e+00
; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], double [[X]], double -1.000000e+00
; CHECK-NEXT: ret double [[COND]]
;
%cmp = fcmp one double %x, -1.0
%cond = select i1 %cmp, double %x, double -1.0
ret double %cond
}
define double @one_swapped(double %x) {
; CHECK-LABEL: @one_swapped(
; CHECK-NEXT: [[CMP:%.*]] = fcmp one double [[X:%.*]], -1.000000e+00
; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], double -1.000000e+00, double [[X]]
; CHECK-NEXT: ret double [[COND]]
;
%cmp = fcmp one double %x, -1.0
%cond = select i1 %cmp, double -1.0, double %x
ret double %cond
}