1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=instsimplify -S | FileCheck %s
6 define double @fadd_nan_op0(double %x) {
7 ; CHECK-LABEL: @fadd_nan_op0(
8 ; CHECK-NEXT: ret double 0x7FF8000000000000
10 %r = fadd double 0x7FF8000000000000, %x
16 define double @fadd_nan_op1(double %x) {
17 ; CHECK-LABEL: @fadd_nan_op1(
18 ; CHECK-NEXT: ret double 0xFFF8000000000000
20 %r = fadd double %x, 0xFFF8000000000000
26 define float @fsub_nan_op0(float %x) {
27 ; CHECK-LABEL: @fsub_nan_op0(
28 ; CHECK-NEXT: ret float 0x7FFFFF0000000000
30 %r = fsub float 0x7FFFFF0000000000, %x
34 ; Signaling - make quiet and preserve the payload and signbit
36 define float @fsub_nan_op1(float %x) {
37 ; CHECK-LABEL: @fsub_nan_op1(
38 ; CHECK-NEXT: ret float 0x7FF9000000000000
40 %r = fsub float %x, 0x7FF1000000000000
44 define <2 x float> @fsub_nan_op1_vec(<2 x float> %x) {
45 ; CHECK-LABEL: @fsub_nan_op1_vec(
46 ; CHECK-NEXT: ret <2 x float> <float 0x7FF9000000000000, float 0xFFF9000000000000>
48 %r = fsub <2 x float> %x, <float 0x7FF1000000000000, float 0xFFF1000000000000>
52 define <vscale x 1 x float> @fsub_nan_op1_scalable_vec_0(<vscale x 1 x float> %x) {
53 ; CHECK-LABEL: @fsub_nan_op1_scalable_vec_0(
54 ; CHECK-NEXT: ret <vscale x 1 x float> splat (float 0x7FF9000000000000)
56 %r = fsub <vscale x 1 x float> %x, splat (float 0x7FF1000000000000)
57 ret <vscale x 1 x float> %r
60 define <vscale x 1 x float> @fsub_nan_op1_scalable_vec_1(<vscale x 1 x float> %x) {
61 ; CHECK-LABEL: @fsub_nan_op1_scalable_vec_1(
62 ; CHECK-NEXT: ret <vscale x 1 x float> splat (float 0xFFF9000000000000)
64 %r = fsub <vscale x 1 x float> %x, splat (float 0xFFF1000000000000)
65 ret <vscale x 1 x float> %r
68 ; Signaling and signed - make quiet and preserve the payload and signbit
70 define double @fmul_nan_op0(double %x) {
71 ; CHECK-LABEL: @fmul_nan_op0(
72 ; CHECK-NEXT: ret double 0xFFF8000000000001
74 %r = fmul double 0xFFF0000000000001, %x
78 define <2 x double> @fmul_nan_op0_vec(<2 x double> %x) {
79 ; CHECK-LABEL: @fmul_nan_op0_vec(
80 ; CHECK-NEXT: ret <2 x double> <double 0xFFF8000000000001, double 0xFFF8DEADDEADDEAD>
82 %r = fmul <2 x double> <double 0xFFF0000000000001, double 0xFFF0DEADDEADDEAD>, %x
86 define <vscale x 1 x double> @fmul_nan_op0_scalable_vec_0(<vscale x 1 x double> %x) {
87 ; CHECK-LABEL: @fmul_nan_op0_scalable_vec_0(
88 ; CHECK-NEXT: ret <vscale x 1 x double> splat (double 0xFFF8000000000001)
90 %r = fmul <vscale x 1 x double> splat (double 0xFFF0000000000001), %x
91 ret <vscale x 1 x double> %r
94 define <vscale x 1 x double> @fmul_nan_op0_scalable_vec_1(<vscale x 1 x double> %x) {
95 ; CHECK-LABEL: @fmul_nan_op0_scalable_vec_1(
96 ; CHECK-NEXT: ret <vscale x 1 x double> splat (double 0xFFF8DEADDEADDEAD)
98 %r = fmul <vscale x 1 x double> splat (double 0xFFF0DEADDEADDEAD), %x
99 ret <vscale x 1 x double> %r
104 define <2 x float> @fmul_nan_op1(<2 x float> %x) {
105 ; CHECK-LABEL: @fmul_nan_op1(
106 ; CHECK-NEXT: ret <2 x float> splat (float 0x7FF8000000000000)
108 %r = fmul <2 x float> %x, <float 0x7FF8000000000000, float 0x7FF8000000000000>
112 define <vscale x 1 x double> @fmul_nan_op1_scalable_vec(<vscale x 1 x double> %x) {
113 ; CHECK-LABEL: @fmul_nan_op1_scalable_vec(
114 ; CHECK-NEXT: ret <vscale x 1 x double> splat (double 0x7FF8000000000000)
116 %r = fmul <vscale x 1 x double> %x, splat (double 0x7FF8000000000000)
117 ret <vscale x 1 x double> %r
120 ; Vector signed and non-zero payload
122 define <2 x double> @fdiv_nan_op0(<2 x double> %x) {
123 ; CHECK-LABEL: @fdiv_nan_op0(
124 ; CHECK-NEXT: ret <2 x double> splat (double 0xFFF800000000000F)
126 %r = fdiv <2 x double> <double 0xFFF800000000000F, double 0xFFF800000000000F>, %x
130 define <vscale x 1 x double> @fdivl_nan_op0_scalable_vec(<vscale x 1 x double> %x) {
131 ; CHECK-LABEL: @fdivl_nan_op0_scalable_vec(
132 ; CHECK-NEXT: ret <vscale x 1 x double> splat (double 0xFFF800000000000F)
134 %r = fdiv <vscale x 1 x double> splat (double 0xFFF800000000000F), %x
135 ret <vscale x 1 x double> %r
138 ; Vector with different NaN constant elements
140 define <2 x half> @fdiv_nan_op1(<2 x half> %x) {
141 ; CHECK-LABEL: @fdiv_nan_op1(
142 ; CHECK-NEXT: ret <2 x half> <half 0xH7FFF, half 0xHFF00>
144 %r = fdiv <2 x half> %x, <half 0xH7FFF, half 0xHFF00>
148 define <vscale x 1 x half> @fdiv_nan_op1_scalable_vec(<vscale x 1 x half> %x) {
149 ; CHECK-LABEL: @fdiv_nan_op1_scalable_vec(
150 ; CHECK-NEXT: ret <vscale x 1 x half> splat (half 0xH7FFF)
152 %r = fdiv <vscale x 1 x half> %x, splat (half 0xH7FFF)
153 ret <vscale x 1 x half> %r
156 ; Vector with poison element
158 define <2 x double> @fsub_nan_poison_op1(<2 x double> %x) {
159 ; CHECK-LABEL: @fsub_nan_poison_op1(
160 ; CHECK-NEXT: ret <2 x double> <double 0xFFFF00000000DEAD, double poison>
162 %r = fsub <2 x double> %x, <double 0xFFFF00000000DEAD, double poison>
166 ; Vector with poison element
168 define <2 x double> @frem_nan_poison_op0(<2 x double> %x) {
169 ; CHECK-LABEL: @frem_nan_poison_op0(
170 ; CHECK-NEXT: ret <2 x double> <double 0xFFFF00000000DEAD, double poison>
172 %r = frem <2 x double> <double 0xFFFF00000000DEAD, double poison>, %x
176 ; Vector with poison and undef elements
178 define <3 x double> @fadd_nan_poison_undef_op1(<3 x double> %x) {
179 ; CHECK-LABEL: @fadd_nan_poison_undef_op1(
180 ; CHECK-NEXT: [[R:%.*]] = fadd <3 x double> [[X:%.*]], <double 0xFFFF00000000DEAD, double poison, double undef>
181 ; CHECK-NEXT: ret <3 x double> [[R]]
183 %r = fadd <3 x double> %x, <double 0xFFFF00000000DEAD, double poison, double undef>
187 define float @frem_nan_op1(float %x) {
188 ; CHECK-LABEL: @frem_nan_op1(
189 ; CHECK-NEXT: ret float 0x7FF8000000000000
191 %r = frem float %x, 0x7FF8000000000000
195 ; Special-case: fneg must only change the sign bit (this is handled by constant folding).
197 define double @fneg_nan_1(double %x) {
198 ; CHECK-LABEL: @fneg_nan_1(
199 ; CHECK-NEXT: ret double 0x7FFABCDEF0123456
201 %r = fsub double -0.0, 0x7FFABCDEF0123456
205 define double @unary_fneg_nan_1(double %x) {
206 ; CHECK-LABEL: @unary_fneg_nan_1(
207 ; CHECK-NEXT: ret double 0xFFFABCDEF0123456
209 %r = fneg double 0x7FFABCDEF0123456
213 define <2 x double> @fneg_nan_2(<2 x double> %x) {
214 ; CHECK-LABEL: @fneg_nan_2(
215 ; CHECK-NEXT: ret <2 x double> <double 0xFFF9234567890ABC, double 0x7FF8000000000001>
217 %r = fsub <2 x double> <double -0.0, double -0.0>, <double 0xFFF1234567890ABC, double 0x7FF0000000000001>
221 define <vscale x 1 x double> @fneg_nan_2_scalable_vec() {
222 ; CHECK-LABEL: @fneg_nan_2_scalable_vec(
223 ; CHECK-NEXT: ret <vscale x 1 x double> splat (double 0xFFF9234567890ABC)
225 %r = fsub <vscale x 1 x double> splat (double -0.0), splat (double 0xFFF1234567890ABC)
226 ret <vscale x 1 x double> %r
229 define <2 x double> @unary_fneg_nan_2(<2 x double> %x) {
230 ; CHECK-LABEL: @unary_fneg_nan_2(
231 ; CHECK-NEXT: ret <2 x double> <double 0x7FF1234567890ABC, double 0xFFF0000000000001>
233 %r = fneg <2 x double> <double 0xFFF1234567890ABC, double 0x7FF0000000000001>
237 ; FIXME: This doesn't behave the same way as the fixed-length vectors above
238 define <vscale x 1 x double> @unary_fneg_nan_2_scalable_vec_0() {
239 ; CHECK-LABEL: @unary_fneg_nan_2_scalable_vec_0(
240 ; CHECK-NEXT: ret <vscale x 1 x double> splat (double 0x7FF1234567890ABC)
242 %r = fneg <vscale x 1 x double> splat (double 0xFFF1234567890ABC)
243 ret <vscale x 1 x double> %r
246 ; FIXME: This doesn't behave the same way as the fixed-length vectors above
247 define <vscale x 1 x double> @unary_fneg_nan_2_scalable_vec_1() {
248 ; CHECK-LABEL: @unary_fneg_nan_2_scalable_vec_1(
249 ; CHECK-NEXT: ret <vscale x 1 x double> splat (double 0xFFF0000000000001)
251 %r = fneg <vscale x 1 x double> splat (double 0x7FF0000000000001)
252 ret <vscale x 1 x double> %r
255 ; Repeat all tests with fast-math-flags. Alternate 'nnan' and 'fast' for more coverage.
257 define float @fadd_nan_op0_nnan(float %x) {
258 ; CHECK-LABEL: @fadd_nan_op0_nnan(
259 ; CHECK-NEXT: ret float poison
261 %r = fadd nnan float 0x7FF8000000000000, %x
265 define float @fadd_nan_op1_fast(float %x) {
266 ; CHECK-LABEL: @fadd_nan_op1_fast(
267 ; CHECK-NEXT: ret float poison
269 %r = fadd fast float %x, 0x7FF8000000000000
273 define float @fsub_nan_op0_fast(float %x) {
274 ; CHECK-LABEL: @fsub_nan_op0_fast(
275 ; CHECK-NEXT: ret float poison
277 %r = fsub fast float 0x7FF8000000000000, %x
281 define float @fsub_nan_op1_nnan(float %x) {
282 ; CHECK-LABEL: @fsub_nan_op1_nnan(
283 ; CHECK-NEXT: ret float poison
285 %r = fsub nnan float %x, 0x7FF8000000000000
289 define float @fmul_nan_op0_nnan(float %x) {
290 ; CHECK-LABEL: @fmul_nan_op0_nnan(
291 ; CHECK-NEXT: ret float poison
293 %r = fmul nnan float 0x7FF8000000000000, %x
297 define float @fmul_nan_op1_fast(float %x) {
298 ; CHECK-LABEL: @fmul_nan_op1_fast(
299 ; CHECK-NEXT: ret float poison
301 %r = fmul fast float %x, 0x7FF8000000000000
305 define float @fdiv_nan_op0_fast(float %x) {
306 ; CHECK-LABEL: @fdiv_nan_op0_fast(
307 ; CHECK-NEXT: ret float poison
309 %r = fdiv fast float 0x7FF8000000000000, %x
313 define float @fdiv_nan_op1_nnan(float %x) {
314 ; CHECK-LABEL: @fdiv_nan_op1_nnan(
315 ; CHECK-NEXT: ret float poison
317 %r = fdiv nnan float %x, 0x7FF8000000000000
321 define float @frem_nan_op0_nnan(float %x) {
322 ; CHECK-LABEL: @frem_nan_op0_nnan(
323 ; CHECK-NEXT: ret float poison
325 %r = frem nnan float 0x7FF8000000000000, %x
329 define float @frem_nan_op1_fast(float %x) {
330 ; CHECK-LABEL: @frem_nan_op1_fast(
331 ; CHECK-NEXT: ret float poison
333 %r = frem fast float %x, 0x7FF8000000000000