0b714ffe36f0b25b680f547226738c97bf647bc9
[oota-llvm.git] / test / CodeGen / X86 / fp-logic.ll
1 ; RUN: llc -mtriple=x86_64-unknown-unknown -mattr=sse2 < %s | FileCheck %s
2
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.
6 ;
7 ; f5, f6, f7, and f8 are less clear.
8 ;
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.
12 ;
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.
19
20 ; 1 FP operand, 1 int operand, int result
21
22 define i32 @f1(float %x, i32 %y) {
23 ; CHECK-LABEL: f1:
24 ; CHECK:       # BB#0:
25 ; CHECK-NEXT:    movd %xmm0, %eax
26 ; CHECK-NEXT:    andl %edi, %eax
27 ; CHECK-NEXT:    retq
28
29   %bc1 = bitcast float %x to i32
30   %and = and i32 %bc1, %y
31   ret i32 %and
32 }
33
34 ; Swap operands of the logic op.
35
36 define i32 @f2(float %x, i32 %y) {
37 ; CHECK-LABEL: f2:
38 ; CHECK:       # BB#0:
39 ; CHECK-NEXT:    movd %xmm0, %eax
40 ; CHECK-NEXT:    andl %edi, %eax
41 ; CHECK-NEXT:    retq
42
43   %bc1 = bitcast float %x to i32
44   %and = and i32 %y, %bc1
45   ret i32 %and
46 }
47
48 ; 1 FP operand, 1 constant operand, int result
49
50 define i32 @f3(float %x) {
51 ; CHECK-LABEL: f3:
52 ; CHECK:       # BB#0:
53 ; CHECK-NEXT:    movd %xmm0, %eax
54 ; CHECK-NEXT:    andl $1, %eax
55 ; CHECK-NEXT:    retq
56
57   %bc1 = bitcast float %x to i32
58   %and = and i32 %bc1, 1
59   ret i32 %and
60 }
61
62 ; Swap operands of the logic op.
63
64 define i32 @f4(float %x) {
65 ; CHECK-LABEL: f4:
66 ; CHECK:       # BB#0:
67 ; CHECK-NEXT:    movd %xmm0, %eax
68 ; CHECK-NEXT:    andl $2, %eax
69 ; CHECK-NEXT:    retq
70
71   %bc1 = bitcast float %x to i32
72   %and = and i32 2, %bc1
73   ret i32 %and
74 }
75
76 ; 1 FP operand, 1 integer operand, FP result
77
78 define float @f5(float %x, i32 %y) {
79 ; CHECK-LABEL: f5:
80 ; CHECK:       # BB#0:
81 ; CHECK-NEXT:    movd %xmm0, %eax
82 ; CHECK-NEXT:    andl %edi, %eax
83 ; CHECK-NEXT:    movd %eax, %xmm0
84 ; CHECK-NEXT:    retq
85
86   %bc1 = bitcast float %x to i32
87   %and = and i32 %bc1, %y
88   %bc2 = bitcast i32 %and to float
89   ret float %bc2
90 }
91
92 ; Swap operands of the logic op.
93
94 define float @f6(float %x, i32 %y) {
95 ; CHECK-LABEL: f6:
96 ; CHECK:       # BB#0:
97 ; CHECK-NEXT:    movd %xmm0, %eax
98 ; CHECK-NEXT:    andl %edi, %eax
99 ; CHECK-NEXT:    movd %eax, %xmm0
100 ; CHECK-NEXT:    retq
101
102   %bc1 = bitcast float %x to i32
103   %and = and i32 %y, %bc1
104   %bc2 = bitcast i32 %and to float
105   ret float %bc2
106 }
107
108 ; 1 FP operand, 1 constant operand, FP result
109
110 define float @f7(float %x) {
111 ; CHECK-LABEL: f7:
112 ; CHECK:       # BB#0:
113 ; CHECK-NEXT:    movd %xmm0, %eax
114 ; CHECK-NEXT:    andl $3, %eax
115 ; CHECK-NEXT:    movd %eax, %xmm0
116 ; CHECK-NEXT:    retq
117
118   %bc1 = bitcast float %x to i32
119   %and = and i32 %bc1, 3
120   %bc2 = bitcast i32 %and to float
121   ret float %bc2
122 }
123
124 ; Swap operands of the logic op.
125
126 define float @f8(float %x) {
127 ; CHECK-LABEL: f8:
128 ; CHECK:       # BB#0:
129 ; CHECK-NEXT:    movd %xmm0, %eax
130 ; CHECK-NEXT:    andl $4, %eax
131 ; CHECK-NEXT:    movd %eax, %xmm0
132 ; CHECK-NEXT:    retq
133
134   %bc1 = bitcast float %x to i32
135   %and = and i32 4, %bc1
136   %bc2 = bitcast i32 %and to float
137   ret float %bc2
138 }
139
140 ; 2 FP operands, int result
141
142 define i32 @f9(float %x, float %y) {
143 ; CHECK-LABEL: f9:
144 ; CHECK:       # BB#0:
145 ; CHECK-NEXT:    andps %xmm1, %xmm0
146 ; CHECK-NEXT:    movd %xmm0, %eax
147 ; CHECK-NEXT:    retq
148
149   %bc1 = bitcast float %x to i32
150   %bc2 = bitcast float %y to i32
151   %and = and i32 %bc1, %bc2
152   ret i32 %and
153 }
154
155 ; 2 FP operands, FP result
156
157 define float @f10(float %x, float %y) {
158 ; CHECK-LABEL: f10:
159 ; CHECK:       # BB#0:
160 ; CHECK-NEXT:    andps %xmm1, %xmm0
161 ; CHECK-NEXT:    retq
162
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
167   ret float %bc3
168 }
169
170 define float @or(float %x, float %y) {
171 ; CHECK-LABEL: or:
172 ; CHECK:       # BB#0:
173 ; CHECK-NEXT:    movd %xmm0, %eax
174 ; CHECK-NEXT:    movd %xmm1, %ecx
175 ; CHECK-NEXT:    orl %eax, %ecx
176 ; CHECK-NEXT:    movd %ecx, %xmm0
177 ; CHECK-NEXT:    retq
178
179   %bc1 = bitcast float %x to i32
180   %bc2 = bitcast float %y to i32
181   %and = or i32 %bc1, %bc2
182   %bc3 = bitcast i32 %and to float
183   ret float %bc3
184 }
185
186 define float @xor(float %x, float %y) {
187 ; CHECK-LABEL: xor:
188 ; CHECK:       # BB#0:
189 ; CHECK-NEXT:    movd %xmm0, %eax
190 ; CHECK-NEXT:    movd %xmm1, %ecx
191 ; CHECK-NEXT:    xorl %eax, %ecx
192 ; CHECK-NEXT:    movd %ecx, %xmm0
193 ; CHECK-NEXT:    retq
194
195   %bc1 = bitcast float %x to i32
196   %bc2 = bitcast float %y to i32
197   %and = xor i32 %bc1, %bc2
198   %bc3 = bitcast i32 %and to float
199   ret float %bc3
200 }
201
202 ; Make sure that doubles work too.
203
204 define double @doubles(double %x, double %y) {
205 ; CHECK-LABEL: doubles:
206 ; CHECK:       # BB#0:
207 ; CHECK-NEXT:    andpd %xmm1, %xmm0
208 ; CHECK-NEXT:    retq
209
210   %bc1 = bitcast double %x to i64
211   %bc2 = bitcast double %y to i64
212   %and = and i64 %bc1, %bc2
213   %bc3 = bitcast i64 %and to double
214   ret double %bc3
215 }
216