Skip to content

Commit a11523a

Browse files
committed
[X86] Add test coverage for TESTPS/TESTPD showing the failure to demand only the sign bits
Part of Issue llvm#60007
1 parent b20c1ff commit a11523a

File tree

2 files changed

+89
-0
lines changed

2 files changed

+89
-0
lines changed

llvm/test/CodeGen/X86/combine-testpd.ll

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,51 @@ define i32 @testpdnzc_256_invert0(<4 x double> %c, <4 x double> %d, i32 %a, i32
149149
ret i32 %t5
150150
}
151151

152+
;
153+
; SimplifyDemandedBits - only the sign bit is required
154+
;
155+
156+
define i32 @testpdc_128_signbit(<2 x double> %c, <2 x double> %d, i32 %a, i32 %b) {
157+
; CHECK-LABEL: testpdc_128_signbit:
158+
; CHECK: # %bb.0:
159+
; CHECK-NEXT: movl %edi, %eax
160+
; CHECK-NEXT: vpxor %xmm2, %xmm2, %xmm2
161+
; CHECK-NEXT: vpcmpgtq %xmm0, %xmm2, %xmm0
162+
; CHECK-NEXT: vtestpd %xmm1, %xmm0
163+
; CHECK-NEXT: cmovael %esi, %eax
164+
; CHECK-NEXT: retq
165+
%t0 = bitcast <2 x double> %c to <2 x i64>
166+
%t1 = ashr <2 x i64> %t0, <i64 63, i64 63>
167+
%t2 = bitcast <2 x i64> %t1 to <2 x double>
168+
%t3 = call i32 @llvm.x86.avx.vtestc.pd(<2 x double> %t2, <2 x double> %d)
169+
%t4 = icmp ne i32 %t3, 0
170+
%t5 = select i1 %t4, i32 %a, i32 %b
171+
ret i32 %t5
172+
}
173+
174+
define i32 @testpdz_256_signbit(<4 x double> %c, <4 x double> %d, i32 %a, i32 %b) {
175+
; CHECK-LABEL: testpdz_256_signbit:
176+
; CHECK: # %bb.0:
177+
; CHECK-NEXT: movl %edi, %eax
178+
; CHECK-NEXT: vextractf128 $1, %ymm0, %xmm2
179+
; CHECK-NEXT: vpxor %xmm3, %xmm3, %xmm3
180+
; CHECK-NEXT: vpcmpgtq %xmm2, %xmm3, %xmm2
181+
; CHECK-NEXT: vpcmpgtq %xmm0, %xmm3, %xmm0
182+
; CHECK-NEXT: vinsertf128 $1, %xmm2, %ymm0, %ymm0
183+
; CHECK-NEXT: vtestpd %ymm1, %ymm0
184+
; CHECK-NEXT: cmovnel %esi, %eax
185+
; CHECK-NEXT: vzeroupper
186+
; CHECK-NEXT: retq
187+
%t0 = bitcast <4 x double> %c to <4 x i64>
188+
%t1 = icmp sgt <4 x i64> zeroinitializer, %t0
189+
%t2 = sext <4 x i1> %t1 to <4 x i64>
190+
%t3 = bitcast <4 x i64> %t2 to <4 x double>
191+
%t4 = call i32 @llvm.x86.avx.vtestz.pd.256(<4 x double> %t3, <4 x double> %d)
192+
%t5 = icmp ne i32 %t4, 0
193+
%t6 = select i1 %t5, i32 %a, i32 %b
194+
ret i32 %t6
195+
}
196+
152197
declare i32 @llvm.x86.avx.vtestz.pd(<2 x double>, <2 x double>) nounwind readnone
153198
declare i32 @llvm.x86.avx.vtestc.pd(<2 x double>, <2 x double>) nounwind readnone
154199
declare i32 @llvm.x86.avx.vtestnzc.pd(<2 x double>, <2 x double>) nounwind readnone

llvm/test/CodeGen/X86/combine-testps.ll

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,50 @@ define i32 @testpsnzc_256_invert0(<8 x float> %c, <8 x float> %d, i32 %a, i32 %b
149149
ret i32 %t5
150150
}
151151

152+
;
153+
; SimplifyDemandedBits - only the sign bit is required
154+
;
155+
156+
define i32 @testpsz_128_signbit(<4 x float> %c, <4 x float> %d, i32 %a, i32 %b) {
157+
; CHECK-LABEL: testpsz_128_signbit:
158+
; CHECK: # %bb.0:
159+
; CHECK-NEXT: movl %edi, %eax
160+
; CHECK-NEXT: vpsrad $31, %xmm0, %xmm0
161+
; CHECK-NEXT: vtestps %xmm1, %xmm0
162+
; CHECK-NEXT: cmovnel %esi, %eax
163+
; CHECK-NEXT: retq
164+
%t0 = bitcast <4 x float> %c to <4 x i32>
165+
%t1 = ashr <4 x i32> %t0, <i32 31, i32 31, i32 31, i32 31>
166+
%t2 = bitcast <4 x i32> %t1 to <4 x float>
167+
%t3 = call i32 @llvm.x86.avx.vtestz.ps(<4 x float> %t2, <4 x float> %d)
168+
%t4 = icmp ne i32 %t3, 0
169+
%t5 = select i1 %t4, i32 %a, i32 %b
170+
ret i32 %t5
171+
}
172+
173+
define i32 @testpsnzc_256_signbit(<8 x float> %c, <8 x float> %d, i32 %a, i32 %b) {
174+
; CHECK-LABEL: testpsnzc_256_signbit:
175+
; CHECK: # %bb.0:
176+
; CHECK-NEXT: movl %edi, %eax
177+
; CHECK-NEXT: vextractf128 $1, %ymm0, %xmm2
178+
; CHECK-NEXT: vpxor %xmm3, %xmm3, %xmm3
179+
; CHECK-NEXT: vpcmpgtd %xmm2, %xmm3, %xmm2
180+
; CHECK-NEXT: vpcmpgtd %xmm0, %xmm3, %xmm0
181+
; CHECK-NEXT: vinsertf128 $1, %xmm2, %ymm0, %ymm0
182+
; CHECK-NEXT: vtestps %ymm1, %ymm0
183+
; CHECK-NEXT: cmovnel %esi, %eax
184+
; CHECK-NEXT: vzeroupper
185+
; CHECK-NEXT: retq
186+
%t0 = bitcast <8 x float> %c to <8 x i32>
187+
%t1 = icmp sgt <8 x i32> zeroinitializer, %t0
188+
%t2 = sext <8 x i1> %t1 to <8 x i32>
189+
%t3 = bitcast <8 x i32> %t2 to <8 x float>
190+
%t4 = call i32 @llvm.x86.avx.vtestz.ps.256(<8 x float> %t3, <8 x float> %d)
191+
%t5 = icmp ne i32 %t4, 0
192+
%t6 = select i1 %t5, i32 %a, i32 %b
193+
ret i32 %t6
194+
}
195+
152196
declare i32 @llvm.x86.avx.vtestz.ps(<4 x float>, <4 x float>) nounwind readnone
153197
declare i32 @llvm.x86.avx.vtestc.ps(<4 x float>, <4 x float>) nounwind readnone
154198
declare i32 @llvm.x86.avx.vtestnzc.ps(<4 x float>, <4 x float>) nounwind readnone

0 commit comments

Comments
 (0)