blob: 95f15789789fbb3662475d9350c88c8888efbbc0 [file] [log] [blame]
Sanjay Patelbab5d6c2015-09-20 15:58:00 +00001; 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
22define 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
36define 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
50define 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
64define 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
78define 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
94define 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
110define 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
126define 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
142define i32 @f9(float %x, float %y) {
143; CHECK-LABEL: f9:
144; CHECK: # BB#0:
Sanjay Pateldf2495f2015-09-23 17:00:06 +0000145; CHECK-NEXT: andps %xmm1, %xmm0
146; CHECK-NEXT: movd %xmm0, %eax
Sanjay Patelbab5d6c2015-09-20 15:58:00 +0000147; 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
157define float @f10(float %x, float %y) {
158; CHECK-LABEL: f10:
159; CHECK: # BB#0:
Sanjay Pateldf2495f2015-09-23 17:00:06 +0000160; CHECK-NEXT: andps %xmm1, %xmm0
Sanjay Patelbab5d6c2015-09-20 15:58:00 +0000161; 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
170define float @or(float %x, float %y) {
171; CHECK-LABEL: or:
172; CHECK: # BB#0:
Sanjay Patelaba37552015-09-23 18:19:07 +0000173; CHECK-NEXT: orps %xmm1, %xmm0
Sanjay Patelbab5d6c2015-09-20 15:58:00 +0000174; CHECK-NEXT: retq
175
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
180 ret float %bc3
181}
182
183define float @xor(float %x, float %y) {
184; CHECK-LABEL: xor:
185; CHECK: # BB#0:
186; CHECK-NEXT: movd %xmm0, %eax
187; CHECK-NEXT: movd %xmm1, %ecx
188; CHECK-NEXT: xorl %eax, %ecx
189; CHECK-NEXT: movd %ecx, %xmm0
190; CHECK-NEXT: retq
191
192 %bc1 = bitcast float %x to i32
193 %bc2 = bitcast float %y to i32
194 %and = xor i32 %bc1, %bc2
195 %bc3 = bitcast i32 %and to float
196 ret float %bc3
197}
198
199; Make sure that doubles work too.
200
201define double @doubles(double %x, double %y) {
202; CHECK-LABEL: doubles:
203; CHECK: # BB#0:
Sanjay Pateldf2495f2015-09-23 17:00:06 +0000204; CHECK-NEXT: andpd %xmm1, %xmm0
Sanjay Patelbab5d6c2015-09-20 15:58:00 +0000205; CHECK-NEXT: retq
206
207 %bc1 = bitcast double %x to i64
208 %bc2 = bitcast double %y to i64
209 %and = and i64 %bc1, %bc2
210 %bc3 = bitcast i64 %and to double
211 ret double %bc3
212}
213