1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=instsimplify -S | FileCheck %s
4 ; fneg (fsub -0.0, X) ==> X
5 define float @fsub_-0_x(float %a) #0 {
6 ; CHECK-LABEL: @fsub_-0_x(
7 ; CHECK-NEXT: [[T1:%.*]] = call float @llvm.experimental.constrained.fsub.f32(float -0.000000e+00, float [[A:%.*]], metadata !"round.tonearest", metadata !"fpexcept.ignore")
8 ; CHECK-NEXT: [[RET:%.*]] = fneg float [[T1]]
9 ; CHECK-NEXT: ret float [[RET]]
11 %t1 = call float @llvm.experimental.constrained.fsub.f32(float -0.0, float %a, metadata !"round.tonearest", metadata !"fpexcept.ignore")
16 define <2 x float> @fsub_-0_x_vec(<2 x float> %a) #0 {
17 ; CHECK-LABEL: @fsub_-0_x_vec(
18 ; CHECK-NEXT: [[T1:%.*]] = call <2 x float> @llvm.experimental.constrained.fsub.v2f32(<2 x float> <float -0.000000e+00, float -0.000000e+00>, <2 x float> [[A:%.*]], metadata !"round.tonearest", metadata !"fpexcept.ignore")
19 ; CHECK-NEXT: [[RET:%.*]] = fneg <2 x float> [[T1]]
20 ; CHECK-NEXT: ret <2 x float> [[RET]]
22 %t1 = call <2 x float> @llvm.experimental.constrained.fsub.v2f32(<2 x float><float -0.0, float -0.0>, <2 x float> %a, metadata !"round.tonearest", metadata !"fpexcept.ignore")
23 %ret = fneg <2 x float> %t1
27 define <2 x float> @fsub_-0_x_vec_undef_elts(<2 x float> %a) #0 {
28 ; CHECK-LABEL: @fsub_-0_x_vec_undef_elts(
29 ; CHECK-NEXT: [[T1:%.*]] = call <2 x float> @llvm.experimental.constrained.fsub.v2f32(<2 x float> <float -0.000000e+00, float undef>, <2 x float> [[A:%.*]], metadata !"round.tonearest", metadata !"fpexcept.ignore")
30 ; CHECK-NEXT: [[RET:%.*]] = fneg <2 x float> [[T1]]
31 ; CHECK-NEXT: ret <2 x float> [[RET]]
33 %t1 = call <2 x float> @llvm.experimental.constrained.fsub.v2f32(<2 x float><float -0.0, float undef>, <2 x float> %a, metadata !"round.tonearest", metadata !"fpexcept.ignore")
34 %ret = fneg <2 x float> %t1
38 define <2 x float> @fsub_negzero_vec_undef_elts(<2 x float> %x) #0 {
39 ; CHECK-LABEL: @fsub_negzero_vec_undef_elts(
40 ; CHECK-NEXT: [[R:%.*]] = call nsz <2 x float> @llvm.experimental.constrained.fsub.v2f32(<2 x float> <float undef, float -0.000000e+00>, <2 x float> [[X:%.*]], metadata !"round.tonearest", metadata !"fpexcept.ignore")
41 ; CHECK-NEXT: ret <2 x float> [[R]]
43 %r = call nsz <2 x float> @llvm.experimental.constrained.fsub.v2f32(<2 x float><float undef, float -0.0>, <2 x float> %x, metadata !"round.tonearest", metadata !"fpexcept.ignore")
47 ; fsub -0.0, (fsub -0.0, X) ==> X
48 define float @fsub_-0_-0_x(float %a) #0 {
49 ; CHECK-LABEL: @fsub_-0_-0_x(
50 ; CHECK-NEXT: [[T1:%.*]] = call float @llvm.experimental.constrained.fsub.f32(float -0.000000e+00, float [[A:%.*]], metadata !"round.tonearest", metadata !"fpexcept.ignore")
51 ; CHECK-NEXT: [[RET:%.*]] = call float @llvm.experimental.constrained.fsub.f32(float -0.000000e+00, float [[T1]], metadata !"round.tonearest", metadata !"fpexcept.ignore")
52 ; CHECK-NEXT: ret float [[RET]]
54 %t1 = call float @llvm.experimental.constrained.fsub.f32(float -0.0, float %a, metadata !"round.tonearest", metadata !"fpexcept.ignore")
55 %ret = call float @llvm.experimental.constrained.fsub.f32(float -0.0, float %t1, metadata !"round.tonearest", metadata !"fpexcept.ignore")
59 ; fsub -0.0, (fneg X) ==> X
60 define float @fneg_x(float %a) #0 {
61 ; CHECK-LABEL: @fneg_x(
62 ; CHECK-NEXT: ret float [[A:%.*]]
65 %ret = call float @llvm.experimental.constrained.fsub.f32(float -0.0, float %t1, metadata !"round.tonearest", metadata !"fpexcept.ignore")
69 define <2 x float> @fsub_-0_-0_x_vec(<2 x float> %a) #0 {
70 ; CHECK-LABEL: @fsub_-0_-0_x_vec(
71 ; CHECK-NEXT: [[T1:%.*]] = call <2 x float> @llvm.experimental.constrained.fsub.v2f32(<2 x float> <float -0.000000e+00, float -0.000000e+00>, <2 x float> [[A:%.*]], metadata !"round.tonearest", metadata !"fpexcept.ignore")
72 ; CHECK-NEXT: [[RET:%.*]] = call <2 x float> @llvm.experimental.constrained.fsub.v2f32(<2 x float> <float -0.000000e+00, float -0.000000e+00>, <2 x float> [[T1]], metadata !"round.tonearest", metadata !"fpexcept.ignore")
73 ; CHECK-NEXT: ret <2 x float> [[RET]]
75 %t1 = call <2 x float> @llvm.experimental.constrained.fsub.v2f32(<2 x float><float -0.0, float -0.0>, <2 x float> %a, metadata !"round.tonearest", metadata !"fpexcept.ignore")
76 %ret = call <2 x float> @llvm.experimental.constrained.fsub.v2f32(<2 x float><float -0.0, float -0.0>, <2 x float> %t1, metadata !"round.tonearest", metadata !"fpexcept.ignore")
80 define <2 x float> @fneg_x_vec(<2 x float> %a) #0 {
81 ; CHECK-LABEL: @fneg_x_vec(
82 ; CHECK-NEXT: ret <2 x float> [[A:%.*]]
84 %t1 = fneg <2 x float> %a
85 %ret = call <2 x float> @llvm.experimental.constrained.fsub.v2f32(<2 x float><float -0.0, float -0.0>, <2 x float> %t1, metadata !"round.tonearest", metadata !"fpexcept.ignore")
89 define <2 x float> @fsub_-0_-0_x_vec_undef_elts(<2 x float> %a) #0 {
90 ; CHECK-LABEL: @fsub_-0_-0_x_vec_undef_elts(
91 ; CHECK-NEXT: [[T1:%.*]] = call <2 x float> @llvm.experimental.constrained.fsub.v2f32(<2 x float> <float undef, float -0.000000e+00>, <2 x float> [[A:%.*]], metadata !"round.tonearest", metadata !"fpexcept.ignore")
92 ; CHECK-NEXT: [[RET:%.*]] = call <2 x float> @llvm.experimental.constrained.fsub.v2f32(<2 x float> <float -0.000000e+00, float undef>, <2 x float> [[T1]], metadata !"round.tonearest", metadata !"fpexcept.ignore")
93 ; CHECK-NEXT: ret <2 x float> [[RET]]
95 %t1 = call <2 x float> @llvm.experimental.constrained.fsub.v2f32(<2 x float><float undef, float -0.0>, <2 x float> %a, metadata !"round.tonearest", metadata !"fpexcept.ignore")
96 %ret = call <2 x float> @llvm.experimental.constrained.fsub.v2f32(<2 x float><float -0.0, float undef>, <2 x float> %t1, metadata !"round.tonearest", metadata !"fpexcept.ignore")
100 define <2 x float> @fneg_x_vec_undef_elts(<2 x float> %a) #0 {
101 ; CHECK-LABEL: @fneg_x_vec_undef_elts(
102 ; CHECK-NEXT: ret <2 x float> [[A:%.*]]
104 %t1 = fneg <2 x float> %a
105 %ret = call <2 x float> @llvm.experimental.constrained.fsub.v2f32(<2 x float><float -0.0, float undef>, <2 x float> %t1, metadata !"round.tonearest", metadata !"fpexcept.ignore")
109 ; fsub -0.0, (fsub 0.0, X) != X
110 define float @fsub_-0_0_x(float %a) #0 {
111 ; CHECK-LABEL: @fsub_-0_0_x(
112 ; CHECK-NEXT: [[T1:%.*]] = call float @llvm.experimental.constrained.fsub.f32(float 0.000000e+00, float [[A:%.*]], metadata !"round.tonearest", metadata !"fpexcept.ignore")
113 ; CHECK-NEXT: [[RET:%.*]] = call float @llvm.experimental.constrained.fsub.f32(float -0.000000e+00, float [[T1]], metadata !"round.tonearest", metadata !"fpexcept.ignore")
114 ; CHECK-NEXT: ret float [[RET]]
116 %t1 = call float @llvm.experimental.constrained.fsub.f32(float 0.0, float %a, metadata !"round.tonearest", metadata !"fpexcept.ignore")
117 %ret = call float @llvm.experimental.constrained.fsub.f32(float -0.0, float %t1, metadata !"round.tonearest", metadata !"fpexcept.ignore")
121 ; fsub 0.0, (fsub -0.0, X) != X
122 define float @fsub_0_-0_x(float %a) #0 {
123 ; CHECK-LABEL: @fsub_0_-0_x(
124 ; CHECK-NEXT: [[T1:%.*]] = call float @llvm.experimental.constrained.fsub.f32(float -0.000000e+00, float [[A:%.*]], metadata !"round.tonearest", metadata !"fpexcept.ignore")
125 ; CHECK-NEXT: [[RET:%.*]] = call float @llvm.experimental.constrained.fsub.f32(float 0.000000e+00, float [[T1]], metadata !"round.tonearest", metadata !"fpexcept.ignore")
126 ; CHECK-NEXT: ret float [[RET]]
128 %t1 = call float @llvm.experimental.constrained.fsub.f32(float -0.0, float %a, metadata !"round.tonearest", metadata !"fpexcept.ignore")
129 %ret = call float @llvm.experimental.constrained.fsub.f32(float 0.0, float %t1, metadata !"round.tonearest", metadata !"fpexcept.ignore")
134 define float @fsub_x_0(float %x) #0 {
135 ; CHECK-LABEL: @fsub_x_0(
136 ; CHECK-NEXT: ret float [[X:%.*]]
138 %r = call float @llvm.experimental.constrained.fsub.f32(float %x, float 0.0, metadata !"round.tonearest", metadata !"fpexcept.ignore")
142 define <2 x float> @fsub_x_0_vec_undef(<2 x float> %x) #0 {
143 ; CHECK-LABEL: @fsub_x_0_vec_undef(
144 ; CHECK-NEXT: ret <2 x float> [[X:%.*]]
146 %r = call <2 x float> @llvm.experimental.constrained.fsub.v2f32(<2 x float> %x, <2 x float><float undef, float 0.0>, metadata !"round.tonearest", metadata !"fpexcept.ignore")
151 define float @fadd_x_n0(float %a) #0 {
152 ; CHECK-LABEL: @fadd_x_n0(
153 ; CHECK-NEXT: ret float [[A:%.*]]
155 %ret = call float @llvm.experimental.constrained.fadd.f32(float %a, float -0.0, metadata !"round.tonearest", metadata !"fpexcept.ignore")
159 define <2 x float> @fadd_x_n0_vec_undef_elt(<2 x float> %a) #0 {
160 ; CHECK-LABEL: @fadd_x_n0_vec_undef_elt(
161 ; CHECK-NEXT: ret <2 x float> [[A:%.*]]
163 %ret = call <2 x float> @llvm.experimental.constrained.fadd.v2f32(<2 x float> %a, <2 x float> <float -0.0, float undef>, metadata !"round.tonearest", metadata !"fpexcept.ignore")
168 define float @fadd_x_p0(float %a) #0 {
169 ; CHECK-LABEL: @fadd_x_p0(
170 ; CHECK-NEXT: [[RET:%.*]] = call float @llvm.experimental.constrained.fadd.f32(float [[A:%.*]], float 0.000000e+00, metadata !"round.tonearest", metadata !"fpexcept.ignore")
171 ; CHECK-NEXT: ret float [[RET]]
173 %ret = call float @llvm.experimental.constrained.fadd.f32(float %a, float 0.0, metadata !"round.tonearest", metadata !"fpexcept.ignore")
177 define <2 x float> @fadd_x_p0_vec_undef_elt(<2 x float> %a) #0 {
178 ; CHECK-LABEL: @fadd_x_p0_vec_undef_elt(
179 ; CHECK-NEXT: [[RET:%.*]] = call <2 x float> @llvm.experimental.constrained.fadd.v2f32(<2 x float> [[A:%.*]], <2 x float> <float 0.000000e+00, float undef>, metadata !"round.tonearest", metadata !"fpexcept.ignore")
180 ; CHECK-NEXT: ret <2 x float> [[RET]]
182 %ret = call <2 x float> @llvm.experimental.constrained.fadd.v2f32(<2 x float> %a, <2 x float> <float 0.0, float undef>, metadata !"round.tonearest", metadata !"fpexcept.ignore")
187 define double @fmul_X_1(double %a) #0 {
188 ; CHECK-LABEL: @fmul_X_1(
189 ; CHECK-NEXT: ret double [[A:%.*]]
191 %b = call double @llvm.experimental.constrained.fmul.f64(double 1.0, double %a, metadata !"round.tonearest", metadata !"fpexcept.ignore")
196 define <4 x float> @fmul_X_1_vec(<4 x float> %x) #0 {
197 ; CHECK-LABEL: @fmul_X_1_vec(
198 ; CHECK-NEXT: ret <4 x float> [[X:%.*]]
200 %m = call <4 x float> @llvm.experimental.constrained.fmul.v4f32(<4 x float> %x, <4 x float> <float 1.0, float 1.0, float 1.0, float 1.0>, metadata !"round.tonearest", metadata !"fpexcept.ignore")
205 define float @fdiv_x_1(float %a) #0 {
206 ; CHECK-LABEL: @fdiv_x_1(
207 ; CHECK-NEXT: ret float [[A:%.*]]
209 %ret = call float @llvm.experimental.constrained.fdiv.f32(float %a, float 1.0, metadata !"round.tonearest", metadata !"fpexcept.ignore")
215 ; The fabs can't be eliminated because llvm.experimental.constrained.sqrt.f32 may return -0 or NaN with
216 ; an arbitrary sign bit.
217 define float @fabs_sqrt(float %a) #0 {
218 ; CHECK-LABEL: @fabs_sqrt(
219 ; CHECK-NEXT: [[SQRT:%.*]] = call float @llvm.experimental.constrained.sqrt.f32(float [[A:%.*]], metadata !"round.tonearest", metadata !"fpexcept.ignore")
220 ; CHECK-NEXT: [[FABS:%.*]] = call float @llvm.fabs.f32(float [[SQRT]]) #[[ATTR0:[0-9]+]]
221 ; CHECK-NEXT: ret float [[FABS]]
223 %sqrt = call float @llvm.experimental.constrained.sqrt.f32(float %a, metadata !"round.tonearest", metadata !"fpexcept.ignore")
224 %fabs = call float @llvm.fabs.f32(float %sqrt) #0
228 ; The fabs can't be eliminated because the nnan sqrt may still return -0.
229 define float @fabs_sqrt_nnan(float %a) #0 {
230 ; CHECK-LABEL: @fabs_sqrt_nnan(
231 ; CHECK-NEXT: [[SQRT:%.*]] = call nnan float @llvm.experimental.constrained.sqrt.f32(float [[A:%.*]], metadata !"round.tonearest", metadata !"fpexcept.ignore")
232 ; CHECK-NEXT: [[FABS:%.*]] = call float @llvm.fabs.f32(float [[SQRT]]) #[[ATTR0]]
233 ; CHECK-NEXT: ret float [[FABS]]
235 %sqrt = call nnan float @llvm.experimental.constrained.sqrt.f32(float %a, metadata !"round.tonearest", metadata !"fpexcept.ignore")
236 %fabs = call float @llvm.fabs.f32(float %sqrt) #0
240 ; The fabs can't be eliminated because the nsz sqrt may still return NaN.
241 define float @fabs_sqrt_nsz(float %a) #0 {
242 ; CHECK-LABEL: @fabs_sqrt_nsz(
243 ; CHECK-NEXT: [[SQRT:%.*]] = call nsz float @llvm.experimental.constrained.sqrt.f32(float [[A:%.*]], metadata !"round.tonearest", metadata !"fpexcept.ignore")
244 ; CHECK-NEXT: [[FABS:%.*]] = call float @llvm.fabs.f32(float [[SQRT]]) #[[ATTR0]]
245 ; CHECK-NEXT: ret float [[FABS]]
247 %sqrt = call nsz float @llvm.experimental.constrained.sqrt.f32(float %a, metadata !"round.tonearest", metadata !"fpexcept.ignore")
248 %fabs = call float @llvm.fabs.f32(float %sqrt) #0
252 ; The fabs can be eliminated because we're nsz and nnan.
253 define float @fabs_sqrt_nnan_nsz(float %a) #0 {
254 ; CHECK-LABEL: @fabs_sqrt_nnan_nsz(
255 ; CHECK-NEXT: [[SQRT:%.*]] = call nnan nsz float @llvm.experimental.constrained.sqrt.f32(float [[A:%.*]], metadata !"round.tonearest", metadata !"fpexcept.ignore")
256 ; CHECK-NEXT: [[FABS:%.*]] = call float @llvm.fabs.f32(float [[SQRT]]) #[[ATTR0]]
257 ; CHECK-NEXT: ret float [[FABS]]
259 %sqrt = call nnan nsz float @llvm.experimental.constrained.sqrt.f32(float %a, metadata !"round.tonearest", metadata !"fpexcept.ignore")
260 %fabs = call float @llvm.fabs.f32(float %sqrt) #0
264 ; The second fabs can be eliminated because the operand to sqrt cannot be -0.
265 define float @fabs_sqrt_nnan_fabs(float %a) #0 {
266 ; CHECK-LABEL: @fabs_sqrt_nnan_fabs(
267 ; CHECK-NEXT: [[B:%.*]] = call float @llvm.fabs.f32(float [[A:%.*]]) #[[ATTR0]]
268 ; CHECK-NEXT: [[SQRT:%.*]] = call nnan float @llvm.experimental.constrained.sqrt.f32(float [[B]], metadata !"round.tonearest", metadata !"fpexcept.ignore")
269 ; CHECK-NEXT: [[FABS:%.*]] = call float @llvm.fabs.f32(float [[SQRT]]) #[[ATTR0]]
270 ; CHECK-NEXT: ret float [[FABS]]
272 %b = call float @llvm.fabs.f32(float %a) #0
273 %sqrt = call nnan float @llvm.experimental.constrained.sqrt.f32(float %b, metadata !"round.tonearest", metadata !"fpexcept.ignore")
274 %fabs = call float @llvm.fabs.f32(float %sqrt) #0
280 define float @fsub_fsub_common_op(float %x, float %y) #0 {
281 ; CHECK-LABEL: @fsub_fsub_common_op(
282 ; CHECK-NEXT: [[S:%.*]] = call float @llvm.experimental.constrained.fsub.f32(float [[Y:%.*]], float [[X:%.*]], metadata !"round.tonearest", metadata !"fpexcept.ignore")
283 ; CHECK-NEXT: [[R:%.*]] = call reassoc nsz float @llvm.experimental.constrained.fsub.f32(float [[Y]], float [[S]], metadata !"round.tonearest", metadata !"fpexcept.ignore")
284 ; CHECK-NEXT: ret float [[R]]
286 %s = call float @llvm.experimental.constrained.fsub.f32(float %y, float %x, metadata !"round.tonearest", metadata !"fpexcept.ignore")
287 %r = call reassoc nsz float @llvm.experimental.constrained.fsub.f32(float %y, float %s, metadata !"round.tonearest", metadata !"fpexcept.ignore")
291 define <2 x float> @fsub_fsub_common_op_vec(<2 x float> %x, <2 x float> %y) #0 {
292 ; CHECK-LABEL: @fsub_fsub_common_op_vec(
293 ; CHECK-NEXT: [[S:%.*]] = call <2 x float> @llvm.experimental.constrained.fsub.v2f32(<2 x float> [[Y:%.*]], <2 x float> [[X:%.*]], metadata !"round.tonearest", metadata !"fpexcept.ignore")
294 ; CHECK-NEXT: [[R:%.*]] = call reassoc nsz <2 x float> @llvm.experimental.constrained.fsub.v2f32(<2 x float> [[Y]], <2 x float> [[S]], metadata !"round.tonearest", metadata !"fpexcept.ignore")
295 ; CHECK-NEXT: ret <2 x float> [[R]]
297 %s = call <2 x float> @llvm.experimental.constrained.fsub.v2f32(<2 x float> %y, <2 x float> %x, metadata !"round.tonearest", metadata !"fpexcept.ignore")
298 %r = call reassoc nsz <2 x float> @llvm.experimental.constrained.fsub.v2f32(<2 x float> %y, <2 x float> %s, metadata !"round.tonearest", metadata !"fpexcept.ignore")
302 ; Negative test - fsub is not commutative.
303 ; Y - (X - Y) --> (Y - X) + Y (canonicalized)
305 define float @fsub_fsub_wrong_common_op(float %x, float %y) #0 {
306 ; CHECK-LABEL: @fsub_fsub_wrong_common_op(
307 ; CHECK-NEXT: [[S:%.*]] = call float @llvm.experimental.constrained.fsub.f32(float [[X:%.*]], float [[Y:%.*]], metadata !"round.tonearest", metadata !"fpexcept.ignore")
308 ; CHECK-NEXT: [[R:%.*]] = call reassoc nsz float @llvm.experimental.constrained.fsub.f32(float [[Y]], float [[S]], metadata !"round.tonearest", metadata !"fpexcept.ignore")
309 ; CHECK-NEXT: ret float [[R]]
311 %s = call float @llvm.experimental.constrained.fsub.f32(float %x, float %y, metadata !"round.tonearest", metadata !"fpexcept.ignore")
312 %r = call reassoc nsz float @llvm.experimental.constrained.fsub.f32(float %y, float %s, metadata !"round.tonearest", metadata !"fpexcept.ignore")
316 ; Negative test - negated operand needed.
319 define float @fsub_fsub_common_op_wrong_commute(float %x, float %y) #0 {
320 ; CHECK-LABEL: @fsub_fsub_common_op_wrong_commute(
321 ; CHECK-NEXT: [[S:%.*]] = call float @llvm.experimental.constrained.fsub.f32(float [[Y:%.*]], float [[X:%.*]], metadata !"round.tonearest", metadata !"fpexcept.ignore")
322 ; CHECK-NEXT: [[R:%.*]] = call reassoc nsz float @llvm.experimental.constrained.fsub.f32(float [[S]], float [[Y]], metadata !"round.tonearest", metadata !"fpexcept.ignore")
323 ; CHECK-NEXT: ret float [[R]]
325 %s = call float @llvm.experimental.constrained.fsub.f32(float %y, float %x, metadata !"round.tonearest", metadata !"fpexcept.ignore")
326 %r = call reassoc nsz float @llvm.experimental.constrained.fsub.f32(float %s, float %y, metadata !"round.tonearest", metadata !"fpexcept.ignore")
330 ; Negative test - fsub is not commutative.
333 define float @fsub_fsub_wrong_common_op_wrong_commute(float %x, float %y) #0 {
334 ; CHECK-LABEL: @fsub_fsub_wrong_common_op_wrong_commute(
335 ; CHECK-NEXT: [[S:%.*]] = call float @llvm.experimental.constrained.fsub.f32(float [[X:%.*]], float [[Y:%.*]], metadata !"round.tonearest", metadata !"fpexcept.ignore")
336 ; CHECK-NEXT: [[R:%.*]] = call reassoc nsz float @llvm.experimental.constrained.fsub.f32(float [[S]], float [[Y]], metadata !"round.tonearest", metadata !"fpexcept.ignore")
337 ; CHECK-NEXT: ret float [[R]]
339 %s = call float @llvm.experimental.constrained.fsub.f32(float %x, float %y, metadata !"round.tonearest", metadata !"fpexcept.ignore")
340 %r = call reassoc nsz float @llvm.experimental.constrained.fsub.f32(float %s, float %y, metadata !"round.tonearest", metadata !"fpexcept.ignore")
346 define float @fadd_fsub_common_op(float %x, float %y) #0 {
347 ; CHECK-LABEL: @fadd_fsub_common_op(
348 ; CHECK-NEXT: [[A:%.*]] = call float @llvm.experimental.constrained.fadd.f32(float [[Y:%.*]], float [[X:%.*]], metadata !"round.tonearest", metadata !"fpexcept.ignore")
349 ; CHECK-NEXT: [[R:%.*]] = call reassoc nsz float @llvm.experimental.constrained.fsub.f32(float [[A]], float [[Y]], metadata !"round.tonearest", metadata !"fpexcept.ignore")
350 ; CHECK-NEXT: ret float [[R]]
352 %a = call float @llvm.experimental.constrained.fadd.f32(float %y, float %x, metadata !"round.tonearest", metadata !"fpexcept.ignore")
353 %r = call reassoc nsz float @llvm.experimental.constrained.fsub.f32(float %a, float %y, metadata !"round.tonearest", metadata !"fpexcept.ignore")
359 define <2 x float> @fadd_fsub_common_op_commute_vec(<2 x float> %x, <2 x float> %y) #0 {
360 ; CHECK-LABEL: @fadd_fsub_common_op_commute_vec(
361 ; CHECK-NEXT: [[A:%.*]] = call <2 x float> @llvm.experimental.constrained.fadd.v2f32(<2 x float> [[X:%.*]], <2 x float> [[Y:%.*]], metadata !"round.tonearest", metadata !"fpexcept.ignore")
362 ; CHECK-NEXT: [[R:%.*]] = call reassoc nsz <2 x float> @llvm.experimental.constrained.fsub.v2f32(<2 x float> [[A]], <2 x float> [[Y]], metadata !"round.tonearest", metadata !"fpexcept.ignore")
363 ; CHECK-NEXT: ret <2 x float> [[R]]
365 %a = call <2 x float> @llvm.experimental.constrained.fadd.v2f32(<2 x float> %x, <2 x float> %y, metadata !"round.tonearest", metadata !"fpexcept.ignore")
366 %r = call reassoc nsz <2 x float> @llvm.experimental.constrained.fsub.v2f32(<2 x float> %a, <2 x float> %y, metadata !"round.tonearest", metadata !"fpexcept.ignore")
370 ; Negative test - negated operand needed.
373 define float @fadd_fsub_common_op_wrong_commute(float %x, float %y) #0 {
374 ; CHECK-LABEL: @fadd_fsub_common_op_wrong_commute(
375 ; CHECK-NEXT: [[A:%.*]] = call float @llvm.experimental.constrained.fadd.f32(float [[Y:%.*]], float [[X:%.*]], metadata !"round.tonearest", metadata !"fpexcept.ignore")
376 ; CHECK-NEXT: [[R:%.*]] = call reassoc nsz float @llvm.experimental.constrained.fsub.f32(float [[Y]], float [[A]], metadata !"round.tonearest", metadata !"fpexcept.ignore")
377 ; CHECK-NEXT: ret float [[R]]
379 %a = call float @llvm.experimental.constrained.fadd.f32(float %y, float %x, metadata !"round.tonearest", metadata !"fpexcept.ignore")
380 %r = call reassoc nsz float @llvm.experimental.constrained.fsub.f32(float %y, float %a, metadata !"round.tonearest", metadata !"fpexcept.ignore")
384 ; Negative test - negated operand needed.
387 define float @fadd_fsub_common_op_wrong_commute_commute(float %x, float %y) #0 {
388 ; CHECK-LABEL: @fadd_fsub_common_op_wrong_commute_commute(
389 ; CHECK-NEXT: [[A:%.*]] = call float @llvm.experimental.constrained.fadd.f32(float [[X:%.*]], float [[Y:%.*]], metadata !"round.tonearest", metadata !"fpexcept.ignore")
390 ; CHECK-NEXT: [[R:%.*]] = call reassoc nsz float @llvm.experimental.constrained.fsub.f32(float [[Y]], float [[A]], metadata !"round.tonearest", metadata !"fpexcept.ignore")
391 ; CHECK-NEXT: ret float [[R]]
393 %a = call float @llvm.experimental.constrained.fadd.f32(float %x, float %y, metadata !"round.tonearest", metadata !"fpexcept.ignore")
394 %r = call reassoc nsz float @llvm.experimental.constrained.fsub.f32(float %y, float %a, metadata !"round.tonearest", metadata !"fpexcept.ignore")
400 define <2 x float> @fsub_fadd_common_op_vec(<2 x float> %x, <2 x float> %y) #0 {
401 ; CHECK-LABEL: @fsub_fadd_common_op_vec(
402 ; CHECK-NEXT: [[S:%.*]] = call <2 x float> @llvm.experimental.constrained.fsub.v2f32(<2 x float> [[X:%.*]], <2 x float> [[Y:%.*]], metadata !"round.tonearest", metadata !"fpexcept.ignore")
403 ; CHECK-NEXT: [[R:%.*]] = call reassoc nsz <2 x float> @llvm.experimental.constrained.fadd.v2f32(<2 x float> [[Y]], <2 x float> [[S]], metadata !"round.tonearest", metadata !"fpexcept.ignore")
404 ; CHECK-NEXT: ret <2 x float> [[R]]
406 %s = call <2 x float> @llvm.experimental.constrained.fsub.v2f32(<2 x float> %x, <2 x float> %y, metadata !"round.tonearest", metadata !"fpexcept.ignore")
407 %r = call reassoc nsz <2 x float> @llvm.experimental.constrained.fadd.v2f32(<2 x float> %y, <2 x float> %s, metadata !"round.tonearest", metadata !"fpexcept.ignore")
413 define float @fsub_fadd_common_op_commute(float %x, float %y) #0 {
414 ; CHECK-LABEL: @fsub_fadd_common_op_commute(
415 ; CHECK-NEXT: [[S:%.*]] = call float @llvm.experimental.constrained.fsub.f32(float [[X:%.*]], float [[Y:%.*]], metadata !"round.tonearest", metadata !"fpexcept.ignore")
416 ; CHECK-NEXT: [[R:%.*]] = call reassoc nsz float @llvm.experimental.constrained.fadd.f32(float [[S]], float [[Y]], metadata !"round.tonearest", metadata !"fpexcept.ignore")
417 ; CHECK-NEXT: ret float [[R]]
419 %s = call float @llvm.experimental.constrained.fsub.f32(float %x, float %y, metadata !"round.tonearest", metadata !"fpexcept.ignore")
420 %r = call reassoc nsz float @llvm.experimental.constrained.fadd.f32(float %s, float %y, metadata !"round.tonearest", metadata !"fpexcept.ignore")
427 define float @fsub_fadd_common_op_wrong_commute(float %x, float %y) #0 {
428 ; CHECK-LABEL: @fsub_fadd_common_op_wrong_commute(
429 ; CHECK-NEXT: [[S:%.*]] = call float @llvm.experimental.constrained.fsub.f32(float [[Y:%.*]], float [[X:%.*]], metadata !"round.tonearest", metadata !"fpexcept.ignore")
430 ; CHECK-NEXT: [[R:%.*]] = call reassoc nsz float @llvm.experimental.constrained.fadd.f32(float [[Y]], float [[S]], metadata !"round.tonearest", metadata !"fpexcept.ignore")
431 ; CHECK-NEXT: ret float [[R]]
433 %s = call float @llvm.experimental.constrained.fsub.f32(float %y, float %x, metadata !"round.tonearest", metadata !"fpexcept.ignore")
434 %r = call reassoc nsz float @llvm.experimental.constrained.fadd.f32(float %y, float %s, metadata !"round.tonearest", metadata !"fpexcept.ignore")
441 define float @fsub_fadd_common_op_wrong_commute_commute(float %x, float %y) #0 {
442 ; CHECK-LABEL: @fsub_fadd_common_op_wrong_commute_commute(
443 ; CHECK-NEXT: [[S:%.*]] = call float @llvm.experimental.constrained.fsub.f32(float [[Y:%.*]], float [[X:%.*]], metadata !"round.tonearest", metadata !"fpexcept.ignore")
444 ; CHECK-NEXT: [[R:%.*]] = call reassoc nsz float @llvm.experimental.constrained.fadd.f32(float [[S]], float [[Y]], metadata !"round.tonearest", metadata !"fpexcept.ignore")
445 ; CHECK-NEXT: ret float [[R]]
447 %s = call float @llvm.experimental.constrained.fsub.f32(float %y, float %x, metadata !"round.tonearest", metadata !"fpexcept.ignore")
448 %r = call reassoc nsz float @llvm.experimental.constrained.fadd.f32(float %s, float %y, metadata !"round.tonearest", metadata !"fpexcept.ignore")
452 ; Originally PR46627 - https://bugs.llvm.org/show_bug.cgi?id=46627
454 define float @maxnum_with_poszero_op(float %a) #0 {
455 ; CHECK-LABEL: @maxnum_with_poszero_op(
456 ; CHECK-NEXT: [[MAX:%.*]] = call float @llvm.experimental.constrained.maxnum.f32(float [[A:%.*]], float 0.000000e+00, metadata !"fpexcept.ignore")
457 ; CHECK-NEXT: [[FABS:%.*]] = call float @llvm.fabs.f32(float [[MAX]]) #[[ATTR0]]
458 ; CHECK-NEXT: ret float [[FABS]]
460 %max = call float @llvm.experimental.constrained.maxnum.f32(float %a, float 0.0, metadata !"fpexcept.ignore")
461 %fabs = call float @llvm.fabs.f32(float %max) #0
465 define float @maxnum_with_poszero_op_commute(float %a) #0 {
466 ; CHECK-LABEL: @maxnum_with_poszero_op_commute(
467 ; CHECK-NEXT: [[SQRT:%.*]] = call float @llvm.experimental.constrained.sqrt.f32(float [[A:%.*]], metadata !"round.tonearest", metadata !"fpexcept.ignore")
468 ; CHECK-NEXT: [[MAX:%.*]] = call float @llvm.experimental.constrained.maxnum.f32(float 0.000000e+00, float [[SQRT]], metadata !"fpexcept.ignore")
469 ; CHECK-NEXT: [[FABS:%.*]] = call float @llvm.fabs.f32(float [[MAX]]) #[[ATTR0]]
470 ; CHECK-NEXT: ret float [[FABS]]
472 %sqrt = call float @llvm.experimental.constrained.sqrt.f32(float %a, metadata !"round.tonearest", metadata !"fpexcept.ignore")
473 %max = call float @llvm.experimental.constrained.maxnum.f32(float 0.0, float %sqrt, metadata !"fpexcept.ignore")
474 %fabs = call float @llvm.fabs.f32(float %max) #0
478 define float @maxnum_with_negzero_op(float %a) #0 {
479 ; CHECK-LABEL: @maxnum_with_negzero_op(
480 ; CHECK-NEXT: [[NNAN:%.*]] = call nnan float @llvm.experimental.constrained.sqrt.f32(float [[A:%.*]], metadata !"round.tonearest", metadata !"fpexcept.ignore")
481 ; CHECK-NEXT: [[FABSA:%.*]] = call float @llvm.fabs.f32(float [[NNAN]]) #[[ATTR0]]
482 ; CHECK-NEXT: [[MAX:%.*]] = call float @llvm.experimental.constrained.maxnum.f32(float -0.000000e+00, float [[FABSA]], metadata !"fpexcept.ignore")
483 ; CHECK-NEXT: [[FABS:%.*]] = call float @llvm.fabs.f32(float [[MAX]]) #[[ATTR0]]
484 ; CHECK-NEXT: ret float [[FABS]]
486 %nnan = call nnan float @llvm.experimental.constrained.sqrt.f32(float %a, metadata !"round.tonearest", metadata !"fpexcept.ignore")
487 %fabsa = call float @llvm.fabs.f32(float %nnan) #0
488 %max = call float @llvm.experimental.constrained.maxnum.f32(float -0.0, float %fabsa, metadata !"fpexcept.ignore")
489 %fabs = call float @llvm.fabs.f32(float %max) #0
493 define float @maxnum_with_negzero_op_commute(float %a) #0 {
494 ; CHECK-LABEL: @maxnum_with_negzero_op_commute(
495 ; CHECK-NEXT: [[NNAN:%.*]] = call nnan float @llvm.experimental.constrained.sqrt.f32(float [[A:%.*]], metadata !"round.tonearest", metadata !"fpexcept.ignore")
496 ; CHECK-NEXT: [[FABSA:%.*]] = call float @llvm.fabs.f32(float [[NNAN]]) #[[ATTR0]]
497 ; CHECK-NEXT: [[MAX:%.*]] = call float @llvm.experimental.constrained.maxnum.f32(float [[FABSA]], float -0.000000e+00, metadata !"fpexcept.ignore")
498 ; CHECK-NEXT: [[FABS:%.*]] = call float @llvm.fabs.f32(float [[MAX]]) #[[ATTR0]]
499 ; CHECK-NEXT: ret float [[FABS]]
501 %nnan = call nnan float @llvm.experimental.constrained.sqrt.f32(float %a, metadata !"round.tonearest", metadata !"fpexcept.ignore")
502 %fabsa = call float @llvm.fabs.f32(float %nnan) #0
503 %max = call float @llvm.experimental.constrained.maxnum.f32(float %fabsa, float -0.0, metadata !"fpexcept.ignore")
504 %fabs = call float @llvm.fabs.f32(float %max) #0
508 ; If an operand is strictly greater than 0.0, we know the sign of the result of maxnum.
510 define float @maxnum_with_pos_one_op(float %a) #0 {
511 ; CHECK-LABEL: @maxnum_with_pos_one_op(
512 ; CHECK-NEXT: [[MAX:%.*]] = call float @llvm.experimental.constrained.maxnum.f32(float [[A:%.*]], float 1.000000e+00, metadata !"fpexcept.ignore")
513 ; CHECK-NEXT: [[FABS:%.*]] = call float @llvm.fabs.f32(float [[MAX]]) #[[ATTR0]]
514 ; CHECK-NEXT: ret float [[FABS]]
516 %max = call float @llvm.experimental.constrained.maxnum.f32(float %a, float 1.0, metadata !"fpexcept.ignore")
517 %fabs = call float @llvm.fabs.f32(float %max) #0
521 declare float @llvm.fabs.f32(float)
522 declare <2 x float> @llvm.fabs.v2f32(<2 x float>)
524 declare float @llvm.experimental.constrained.fadd.f32(float, float, metadata, metadata)
525 declare <2 x float> @llvm.experimental.constrained.fadd.v2f32(<2 x float>, <2 x float>, metadata, metadata)
527 declare float @llvm.experimental.constrained.fsub.f32(float, float, metadata, metadata)
528 declare <2 x float> @llvm.experimental.constrained.fsub.v2f32(<2 x float>, <2 x float>, metadata, metadata)
530 declare double @llvm.experimental.constrained.fmul.f64(double, double, metadata, metadata)
531 declare <4 x float> @llvm.experimental.constrained.fmul.v4f32(<4 x float>, <4 x float>, metadata, metadata)
533 declare float @llvm.experimental.constrained.fdiv.f32(float, float, metadata, metadata)
535 declare float @llvm.experimental.constrained.maxnum.f32(float, float, metadata)
536 declare float @llvm.experimental.constrained.sqrt.f32(float, metadata, metadata)
538 attributes #0 = { strictfp }