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: movd %xmm0, %eax
114 ; CHECK-NEXT: andl $3, %eax
115 ; CHECK-NEXT: movd %eax, %xmm0
118 %bc1 = bitcast float %x to i32
119 %and = and i32 %bc1, 3
120 %bc2 = bitcast i32 %and to float
124 ; Swap operands of the logic op.
126 define float @f8(float %x) {
129 ; CHECK-NEXT: movd %xmm0, %eax
130 ; CHECK-NEXT: andl $4, %eax
131 ; CHECK-NEXT: movd %eax, %xmm0
134 %bc1 = bitcast float %x to i32
135 %and = and i32 4, %bc1
136 %bc2 = bitcast i32 %and to float
140 ; 2 FP operands, int result
142 define i32 @f9(float %x, float %y) {
145 ; CHECK-NEXT: andps %xmm1, %xmm0
146 ; CHECK-NEXT: movd %xmm0, %eax
149 %bc1 = bitcast float %x to i32
150 %bc2 = bitcast float %y to i32
151 %and = and i32 %bc1, %bc2
155 ; 2 FP operands, FP result
157 define float @f10(float %x, float %y) {
160 ; CHECK-NEXT: andps %xmm1, %xmm0
163 %bc1 = bitcast float %x to i32
164 %bc2 = bitcast float %y to i32
165 %and = and i32 %bc1, %bc2
166 %bc3 = bitcast i32 %and to float
170 define float @or(float %x, float %y) {
173 ; CHECK-NEXT: orps %xmm1, %xmm0
176 %bc1 = bitcast float %x to i32
177 %bc2 = bitcast float %y to i32
178 %and = or i32 %bc1, %bc2
179 %bc3 = bitcast i32 %and to float
183 define float @xor(float %x, float %y) {
186 ; CHECK-NEXT: xorps %xmm1, %xmm0
189 %bc1 = bitcast float %x to i32
190 %bc2 = bitcast float %y to i32
191 %and = xor i32 %bc1, %bc2
192 %bc3 = bitcast i32 %and to float
196 ; Make sure that doubles work too.
198 define double @doubles(double %x, double %y) {
199 ; CHECK-LABEL: doubles:
201 ; CHECK-NEXT: andpd %xmm1, %xmm0
204 %bc1 = bitcast double %x to i64
205 %bc2 = bitcast double %y to i64
206 %and = and i64 %bc1, %bc2
207 %bc3 = bitcast i64 %and to double