1 ; RUN: llc -mtriple=x86_64-unknown-unknown -mattr=sse2 < %s | FileCheck %s
3 ; PR22428: https://llvm.org/bugs/show_bug.cgi?id=22428
4 ; f1, f2, f3, and f4 should use an integer logic instruction.
5 ; f9 and f10 should use an FP (SSE) logic instruction.
7 ; f5, f6, f7, and f8 are less clear.
9 ; For f5 and f6, we can save a register move by using an FP logic instruction,
10 ; but we may need to calculate the relative costs of an SSE op vs. int op vs.
11 ; scalar <-> SSE register moves.
13 ; For f7 and f8, the SSE instructions don't take immediate operands, so if we
14 ; use one of those, we either have to load a constant from memory or move the
15 ; scalar immediate value from an integer register over to an SSE register.
16 ; Optimizing for size may affect that decision. Also, note that there are no
17 ; scalar versions of the FP logic ops, so if we want to fold a load into a
18 ; logic op, we have to load or splat a 16-byte vector constant.
20 ; 1 FP operand, 1 int operand, int result
22 define i32 @f1(float %x, i32 %y) {
25 ; CHECK-NEXT: movd %xmm0, %eax
26 ; CHECK-NEXT: andl %edi, %eax
29 %bc1 = bitcast float %x to i32
30 %and = and i32 %bc1, %y
34 ; Swap operands of the logic op.
36 define i32 @f2(float %x, i32 %y) {
39 ; CHECK-NEXT: movd %xmm0, %eax
40 ; CHECK-NEXT: andl %edi, %eax
43 %bc1 = bitcast float %x to i32
44 %and = and i32 %y, %bc1
48 ; 1 FP operand, 1 constant operand, int result
50 define i32 @f3(float %x) {
53 ; CHECK-NEXT: movd %xmm0, %eax
54 ; CHECK-NEXT: andl $1, %eax
57 %bc1 = bitcast float %x to i32
58 %and = and i32 %bc1, 1
62 ; Swap operands of the logic op.
64 define i32 @f4(float %x) {
67 ; CHECK-NEXT: movd %xmm0, %eax
68 ; CHECK-NEXT: andl $2, %eax
71 %bc1 = bitcast float %x to i32
72 %and = and i32 2, %bc1
76 ; 1 FP operand, 1 integer operand, FP result
78 define float @f5(float %x, i32 %y) {
81 ; CHECK-NEXT: movd %xmm0, %eax
82 ; CHECK-NEXT: andl %edi, %eax
83 ; CHECK-NEXT: movd %eax, %xmm0
86 %bc1 = bitcast float %x to i32
87 %and = and i32 %bc1, %y
88 %bc2 = bitcast i32 %and to float
92 ; Swap operands of the logic op.
94 define float @f6(float %x, i32 %y) {
97 ; CHECK-NEXT: movd %xmm0, %eax
98 ; CHECK-NEXT: andl %edi, %eax
99 ; CHECK-NEXT: movd %eax, %xmm0
102 %bc1 = bitcast float %x to i32
103 %and = and i32 %y, %bc1
104 %bc2 = bitcast i32 %and to float
108 ; 1 FP operand, 1 constant operand, FP result
110 define float @f7(float %x) {
113 ; CHECK-NEXT: movss {{.*#+}} xmm1 = mem[0],zero,zero,zero
114 ; CHECK-NEXT: andps %xmm1, %xmm0
117 %bc1 = bitcast float %x to i32
118 %and = and i32 %bc1, 3
119 %bc2 = bitcast i32 %and to float
123 ; Swap operands of the logic op.
125 define float @f8(float %x) {
128 ; CHECK-NEXT: movss {{.*#+}} xmm1 = mem[0],zero,zero,zero
129 ; CHECK-NEXT: andps %xmm1, %xmm0
132 %bc1 = bitcast float %x to i32
133 %and = and i32 4, %bc1
134 %bc2 = bitcast i32 %and to float
138 ; 2 FP operands, int result
140 define i32 @f9(float %x, float %y) {
143 ; CHECK-NEXT: andps %xmm1, %xmm0
144 ; CHECK-NEXT: movd %xmm0, %eax
147 %bc1 = bitcast float %x to i32
148 %bc2 = bitcast float %y to i32
149 %and = and i32 %bc1, %bc2
153 ; 2 FP operands, FP result
155 define float @f10(float %x, float %y) {
158 ; CHECK-NEXT: andps %xmm1, %xmm0
161 %bc1 = bitcast float %x to i32
162 %bc2 = bitcast float %y to i32
163 %and = and i32 %bc1, %bc2
164 %bc3 = bitcast i32 %and to float
168 define float @or(float %x, float %y) {
171 ; CHECK-NEXT: orps %xmm1, %xmm0
174 %bc1 = bitcast float %x to i32
175 %bc2 = bitcast float %y to i32
176 %and = or i32 %bc1, %bc2
177 %bc3 = bitcast i32 %and to float
181 define float @xor(float %x, float %y) {
184 ; CHECK-NEXT: xorps %xmm1, %xmm0
187 %bc1 = bitcast float %x to i32
188 %bc2 = bitcast float %y to i32
189 %and = xor i32 %bc1, %bc2
190 %bc3 = bitcast i32 %and to float
194 define float @f7_or(float %x) {
195 ; CHECK-LABEL: f7_or:
197 ; CHECK-NEXT: movss {{.*#+}} xmm1 = mem[0],zero,zero,zero
198 ; CHECK-NEXT: orps %xmm1, %xmm0
201 %bc1 = bitcast float %x to i32
202 %and = or i32 %bc1, 3
203 %bc2 = bitcast i32 %and to float
207 define float @f7_xor(float %x) {
208 ; CHECK-LABEL: f7_xor:
210 ; CHECK-NEXT: movss {{.*#+}} xmm1 = mem[0],zero,zero,zero
211 ; CHECK-NEXT: xorps %xmm1, %xmm0
214 %bc1 = bitcast float %x to i32
215 %and = xor i32 %bc1, 3
216 %bc2 = bitcast i32 %and to float
220 ; Make sure that doubles work too.
222 define double @doubles(double %x, double %y) {
223 ; CHECK-LABEL: doubles:
225 ; CHECK-NEXT: andpd %xmm1, %xmm0
228 %bc1 = bitcast double %x to i64
229 %bc2 = bitcast double %y to i64
230 %and = and i64 %bc1, %bc2
231 %bc3 = bitcast i64 %and to double
235 define double @f7_double(double %x) {
236 ; CHECK-LABEL: f7_double:
238 ; CHECK-NEXT: movsd {{.*#+}} xmm1 = mem[0],zero
239 ; CHECK-NEXT: andpd %xmm1, %xmm0
242 %bc1 = bitcast double %x to i64
243 %and = and i64 %bc1, 3
244 %bc2 = bitcast i64 %and to double
248 ; Grabbing the sign bit is a special case that could be handled
249 ; by movmskps/movmskpd, but if we're not shifting it over, then
250 ; a simple FP logic op is cheaper.
252 define float @movmsk(float %x) {
253 ; CHECK-LABEL: movmsk:
255 ; CHECK-NEXT: movss {{.*#+}} xmm1 = mem[0],zero,zero,zero
256 ; CHECK-NEXT: andps %xmm1, %xmm0
259 %bc1 = bitcast float %x to i32
260 %and = and i32 %bc1, 2147483648
261 %bc2 = bitcast i32 %and to float