1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc < %s -mtriple=i686-unknown-unknown -mattr=+sse | FileCheck %s --check-prefix=X32-SSE --check-prefix=X32-SSE1
3 ; RUN: llc < %s -mtriple=i686-unknown-unknown -mattr=+sse2 | FileCheck %s --check-prefix=X32-SSE --check-prefix=X32-SSE2
4 ; RUN: llc < %s -mtriple=x86_64-unknown-unknown -mattr=-sse2 | FileCheck %s --check-prefix=X64-SSE --check-prefix=X64-SSE1
5 ; RUN: llc < %s -mtriple=x86_64-unknown-unknown -mattr=+sse2 | FileCheck %s --check-prefix=X64-SSE --check-prefix=X64-SSE2
7 ; FNEG is defined as subtraction from -0.0.
9 ; This test verifies that we use an xor with a constant to flip the sign bits; no subtraction needed.
10 define <4 x float> @t1(<4 x float> %Q) nounwind {
13 ; X32-SSE-NEXT: xorps {{\.LCPI.*}}, %xmm0
18 ; X64-SSE-NEXT: xorps {{.*}}(%rip), %xmm0
20 %tmp = fsub <4 x float> <float -0.0, float -0.0, float -0.0, float -0.0>, %Q
24 ; Possibly misplaced test, but since we're checking undef scenarios...
26 define float @scalar_fsub_neg0_undef(float %x) nounwind {
27 ; X32-SSE-LABEL: scalar_fsub_neg0_undef:
32 ; X64-SSE-LABEL: scalar_fsub_neg0_undef:
35 %r = fsub float -0.0, undef
39 define float @scalar_fneg_undef(float %x) nounwind {
40 ; X32-SSE-LABEL: scalar_fneg_undef:
45 ; X64-SSE-LABEL: scalar_fneg_undef:
52 define <4 x float> @fsub_neg0_undef(<4 x float> %Q) nounwind {
53 ; X32-SSE-LABEL: fsub_neg0_undef:
57 ; X64-SSE-LABEL: fsub_neg0_undef:
60 %r = fsub <4 x float> <float -0.0, float -0.0, float -0.0, float -0.0>, undef
64 define <4 x float> @fneg_undef(<4 x float> %Q) nounwind {
65 ; X32-SSE-LABEL: fneg_undef:
69 ; X64-SSE-LABEL: fneg_undef:
72 %r = fneg <4 x float> undef
76 define <4 x float> @fsub_neg0_undef_elts_undef(<4 x float> %x) {
77 ; X32-SSE-LABEL: fsub_neg0_undef_elts_undef:
79 ; X32-SSE-NEXT: movaps {{.*#+}} xmm0 = <NaN,u,u,NaN>
82 ; X64-SSE-LABEL: fsub_neg0_undef_elts_undef:
84 ; X64-SSE-NEXT: movaps {{.*#+}} xmm0 = <NaN,u,u,NaN>
86 %r = fsub <4 x float> <float -0.0, float undef, float undef, float -0.0>, undef
90 ; This test verifies that we generate an FP subtraction because "0.0 - x" is not an fneg.
91 define <4 x float> @t2(<4 x float> %Q) nounwind {
94 ; X32-SSE-NEXT: xorps %xmm1, %xmm1
95 ; X32-SSE-NEXT: subps %xmm0, %xmm1
96 ; X32-SSE-NEXT: movaps %xmm1, %xmm0
101 ; X64-SSE-NEXT: xorps %xmm1, %xmm1
102 ; X64-SSE-NEXT: subps %xmm0, %xmm1
103 ; X64-SSE-NEXT: movaps %xmm1, %xmm0
105 %tmp = fsub <4 x float> zeroinitializer, %Q
109 ; If we're bitcasting an integer to an FP vector, we should avoid the FPU/vector unit entirely.
110 ; Make sure that we're flipping the sign bit and only the sign bit of each float.
111 ; So instead of something like this:
113 ; xorps .LCPI2_0(%rip), %xmm0
115 ; We should generate:
116 ; movabsq (put sign bit mask in integer register))
117 ; xorq (flip sign bits)
118 ; movd (move to xmm return register)
120 define <2 x float> @fneg_bitcast(i64 %i) nounwind {
121 ; X32-SSE1-LABEL: fneg_bitcast:
123 ; X32-SSE1-NEXT: pushl %ebp
124 ; X32-SSE1-NEXT: movl %esp, %ebp
125 ; X32-SSE1-NEXT: andl $-16, %esp
126 ; X32-SSE1-NEXT: subl $32, %esp
127 ; X32-SSE1-NEXT: movl $-2147483648, %eax # imm = 0x80000000
128 ; X32-SSE1-NEXT: movl 12(%ebp), %ecx
129 ; X32-SSE1-NEXT: xorl %eax, %ecx
130 ; X32-SSE1-NEXT: movl %ecx, {{[0-9]+}}(%esp)
131 ; X32-SSE1-NEXT: xorl 8(%ebp), %eax
132 ; X32-SSE1-NEXT: movl %eax, (%esp)
133 ; X32-SSE1-NEXT: movaps (%esp), %xmm0
134 ; X32-SSE1-NEXT: movl %ebp, %esp
135 ; X32-SSE1-NEXT: popl %ebp
136 ; X32-SSE1-NEXT: retl
138 ; X32-SSE2-LABEL: fneg_bitcast:
140 ; X32-SSE2-NEXT: movl $-2147483648, %eax # imm = 0x80000000
141 ; X32-SSE2-NEXT: movl {{[0-9]+}}(%esp), %ecx
142 ; X32-SSE2-NEXT: xorl %eax, %ecx
143 ; X32-SSE2-NEXT: movd %ecx, %xmm1
144 ; X32-SSE2-NEXT: xorl {{[0-9]+}}(%esp), %eax
145 ; X32-SSE2-NEXT: movd %eax, %xmm0
146 ; X32-SSE2-NEXT: punpckldq {{.*#+}} xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
147 ; X32-SSE2-NEXT: retl
149 ; X64-SSE1-LABEL: fneg_bitcast:
151 ; X64-SSE1-NEXT: movabsq $-9223372034707292160, %rax # imm = 0x8000000080000000
152 ; X64-SSE1-NEXT: xorq %rdi, %rax
153 ; X64-SSE1-NEXT: movq %rax, -{{[0-9]+}}(%rsp)
154 ; X64-SSE1-NEXT: movaps -{{[0-9]+}}(%rsp), %xmm0
155 ; X64-SSE1-NEXT: retq
157 ; X64-SSE2-LABEL: fneg_bitcast:
159 ; X64-SSE2-NEXT: movabsq $-9223372034707292160, %rax # imm = 0x8000000080000000
160 ; X64-SSE2-NEXT: xorq %rdi, %rax
161 ; X64-SSE2-NEXT: movq %rax, %xmm0
162 ; X64-SSE2-NEXT: retq
163 %bitcast = bitcast i64 %i to <2 x float>
164 %fneg = fsub <2 x float> <float -0.0, float -0.0>, %bitcast
165 ret <2 x float> %fneg
168 define <4 x float> @fneg_undef_elts_v4f32(<4 x float> %x) {
169 ; X32-SSE-LABEL: fneg_undef_elts_v4f32:
171 ; X32-SSE-NEXT: xorps {{\.LCPI.*}}, %xmm0
174 ; X64-SSE-LABEL: fneg_undef_elts_v4f32:
176 ; X64-SSE-NEXT: xorps {{.*}}(%rip), %xmm0
178 %r = fsub <4 x float> <float -0.0, float undef, float undef, float -0.0>, %x
182 ; This isn't fneg, but similarly check that (X - 0.0) is simplified.
184 define <4 x float> @fsub0_undef_elts_v4f32(<4 x float> %x) {
185 ; X32-SSE-LABEL: fsub0_undef_elts_v4f32:
189 ; X64-SSE-LABEL: fsub0_undef_elts_v4f32:
192 %r = fsub <4 x float> %x, <float 0.0, float undef, float 0.0, float undef>
196 define <4 x float> @fneg(<4 x float> %Q) nounwind {
197 ; X32-SSE-LABEL: fneg:
199 ; X32-SSE-NEXT: xorps {{\.LCPI.*}}, %xmm0
202 ; X64-SSE-LABEL: fneg:
204 ; X64-SSE-NEXT: xorps {{.*}}(%rip), %xmm0
206 %tmp = fneg <4 x float> %Q