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> shufflevector (<vscale x 1 x float> insertelement (<vscale x 1 x float> poison, float 0x7FF9000000000000, i64 0), <vscale x 1 x float> poison, <vscale x 1 x i32> zeroinitializer)
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> shufflevector (<vscale x 1 x float> insertelement (<vscale x 1 x float> poison, float 0xFFF9000000000000, i64 0), <vscale x 1 x float> poison, <vscale x 1 x i32> zeroinitializer)
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> shufflevector (<vscale x 1 x double> insertelement (<vscale x 1 x double> poison, double 0xFFF8000000000001, i64 0), <vscale x 1 x double> poison, <vscale x 1 x i32> zeroinitializer)
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> shufflevector (<vscale x 1 x double> insertelement (<vscale x 1 x double> poison, double 0xFFF8DEADDEADDEAD, i64 0), <vscale x 1 x double> poison, <vscale x 1 x i32> zeroinitializer)
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> <float 0x7FF8000000000000, 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> shufflevector (<vscale x 1 x double> insertelement (<vscale x 1 x double> poison, double 0x7FF8000000000000, i64 0), <vscale x 1 x double> poison, <vscale x 1 x i32> zeroinitializer)
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> <double 0xFFF800000000000F, 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> shufflevector (<vscale x 1 x double> insertelement (<vscale x 1 x double> poison, double 0xFFF800000000000F, i64 0), <vscale x 1 x double> poison, <vscale x 1 x i32> zeroinitializer)
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> shufflevector (<vscale x 1 x half> insertelement (<vscale x 1 x half> poison, half 0xH7FFF, i64 0), <vscale x 1 x half> poison, <vscale x 1 x i32> zeroinitializer)
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> shufflevector (<vscale x 1 x double> insertelement (<vscale x 1 x double> poison, double 0xFFF9234567890ABC, i64 0), <vscale x 1 x double> poison, <vscale x 1 x i32> zeroinitializer)
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: [[R:%.*]] = fneg <vscale x 1 x double> shufflevector (<vscale x 1 x double> insertelement (<vscale x 1 x double> poison, double 0xFFF1234567890ABC, i64 0), <vscale x 1 x double> poison, <vscale x 1 x i32> zeroinitializer)
241 ; CHECK-NEXT: ret <vscale x 1 x double> [[R]]
243 %r = fneg <vscale x 1 x double> splat (double 0xFFF1234567890ABC)
244 ret <vscale x 1 x double> %r
247 ; FIXME: This doesn't behave the same way as the fixed-length vectors above
248 define <vscale x 1 x double> @unary_fneg_nan_2_scalable_vec_1() {
249 ; CHECK-LABEL: @unary_fneg_nan_2_scalable_vec_1(
250 ; CHECK-NEXT: [[R:%.*]] = fneg <vscale x 1 x double> shufflevector (<vscale x 1 x double> insertelement (<vscale x 1 x double> poison, double 0x7FF0000000000001, i64 0), <vscale x 1 x double> poison, <vscale x 1 x i32> zeroinitializer)
251 ; CHECK-NEXT: ret <vscale x 1 x double> [[R]]
253 %r = fneg <vscale x 1 x double> splat (double 0x7FF0000000000001)
254 ret <vscale x 1 x double> %r
257 ; Repeat all tests with fast-math-flags. Alternate 'nnan' and 'fast' for more coverage.
259 define float @fadd_nan_op0_nnan(float %x) {
260 ; CHECK-LABEL: @fadd_nan_op0_nnan(
261 ; CHECK-NEXT: ret float poison
263 %r = fadd nnan float 0x7FF8000000000000, %x
267 define float @fadd_nan_op1_fast(float %x) {
268 ; CHECK-LABEL: @fadd_nan_op1_fast(
269 ; CHECK-NEXT: ret float poison
271 %r = fadd fast float %x, 0x7FF8000000000000
275 define float @fsub_nan_op0_fast(float %x) {
276 ; CHECK-LABEL: @fsub_nan_op0_fast(
277 ; CHECK-NEXT: ret float poison
279 %r = fsub fast float 0x7FF8000000000000, %x
283 define float @fsub_nan_op1_nnan(float %x) {
284 ; CHECK-LABEL: @fsub_nan_op1_nnan(
285 ; CHECK-NEXT: ret float poison
287 %r = fsub nnan float %x, 0x7FF8000000000000
291 define float @fmul_nan_op0_nnan(float %x) {
292 ; CHECK-LABEL: @fmul_nan_op0_nnan(
293 ; CHECK-NEXT: ret float poison
295 %r = fmul nnan float 0x7FF8000000000000, %x
299 define float @fmul_nan_op1_fast(float %x) {
300 ; CHECK-LABEL: @fmul_nan_op1_fast(
301 ; CHECK-NEXT: ret float poison
303 %r = fmul fast float %x, 0x7FF8000000000000
307 define float @fdiv_nan_op0_fast(float %x) {
308 ; CHECK-LABEL: @fdiv_nan_op0_fast(
309 ; CHECK-NEXT: ret float poison
311 %r = fdiv fast float 0x7FF8000000000000, %x
315 define float @fdiv_nan_op1_nnan(float %x) {
316 ; CHECK-LABEL: @fdiv_nan_op1_nnan(
317 ; CHECK-NEXT: ret float poison
319 %r = fdiv nnan float %x, 0x7FF8000000000000
323 define float @frem_nan_op0_nnan(float %x) {
324 ; CHECK-LABEL: @frem_nan_op0_nnan(
325 ; CHECK-NEXT: ret float poison
327 %r = frem nnan float 0x7FF8000000000000, %x
331 define float @frem_nan_op1_fast(float %x) {
332 ; CHECK-LABEL: @frem_nan_op1_fast(
333 ; CHECK-NEXT: ret float poison
335 %r = frem fast float %x, 0x7FF8000000000000