[llvm] 87c60bf - [X86] Add test case for situation where constant folding PMADDWD was causing an infinite loop in PCMPGT commuting between 2 constant values.

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 28 07:34:25 PDT 2024


Author: Simon Pilgrim
Date: 2024-06-28T15:33:48+01:00
New Revision: 87c60bfe561ba213d627a65b694554b0a580fa95

URL: https://github.com/llvm/llvm-project/commit/87c60bfe561ba213d627a65b694554b0a580fa95
DIFF: https://github.com/llvm/llvm-project/commit/87c60bfe561ba213d627a65b694554b0a580fa95.diff

LOG: [X86] Add test case for situation where constant folding PMADDWD was causing an infinite loop in PCMPGT commuting between 2 constant values.

Reported by @alexfh

Added: 
    

Modified: 
    llvm/test/CodeGen/X86/combine-pmadd.ll

Removed: 
    


################################################################################
diff  --git a/llvm/test/CodeGen/X86/combine-pmadd.ll b/llvm/test/CodeGen/X86/combine-pmadd.ll
index c5f9c8506f291..83cce1061bc1e 100644
--- a/llvm/test/CodeGen/X86/combine-pmadd.ll
+++ b/llvm/test/CodeGen/X86/combine-pmadd.ll
@@ -226,3 +226,46 @@ define i32 @combine_pmaddubsw_constant_sat() {
   %3 = sext i16 %2 to i32
   ret i32 %3
 }
+
+; Constant folding PMADDWD was causing an infinite loop in the PCMPGT commuting between 2 constant values.
+define i1 @pmaddwd_pcmpgt_infinite_loop() {
+; SSE-LABEL: pmaddwd_pcmpgt_infinite_loop:
+; SSE:       # %bb.0:
+; SSE-NEXT:    movdqa {{.*#+}} xmm0 = [2147483647,2147483647,2147483647,2147483647]
+; SSE-NEXT:    paddd {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0
+; SSE-NEXT:    pcmpgtd {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0
+; SSE-NEXT:    movmskps %xmm0, %eax
+; SSE-NEXT:    testl %eax, %eax
+; SSE-NEXT:    sete %al
+; SSE-NEXT:    retq
+;
+; AVX1-LABEL: pmaddwd_pcmpgt_infinite_loop:
+; AVX1:       # %bb.0:
+; AVX1-NEXT:    vpcmpeqd %xmm0, %xmm0, %xmm0
+; AVX1-NEXT:    vbroadcastss {{.*#+}} xmm1 = [2147483647,2147483647,2147483647,2147483647]
+; AVX1-NEXT:    vpaddd {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm1, %xmm1
+; AVX1-NEXT:    vpcmpgtd {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm1, %xmm1
+; AVX1-NEXT:    vtestps %xmm1, %xmm0
+; AVX1-NEXT:    sete %al
+; AVX1-NEXT:    retq
+;
+; AVX2-LABEL: pmaddwd_pcmpgt_infinite_loop:
+; AVX2:       # %bb.0:
+; AVX2-NEXT:    vpcmpeqd %xmm0, %xmm0, %xmm0
+; AVX2-NEXT:    vpbroadcastd {{.*#+}} xmm1 = [2147483647,2147483647,2147483647,2147483647]
+; AVX2-NEXT:    vpaddd {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm1, %xmm1
+; AVX2-NEXT:    vpcmpgtd {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm1, %xmm1
+; AVX2-NEXT:    vtestps %xmm1, %xmm0
+; AVX2-NEXT:    sete %al
+; AVX2-NEXT:    retq
+  %1 = tail call <4 x i32> @llvm.x86.sse2.pmadd.wd(<8 x i16> <i16 -32768, i16 -32768, i16 -32768, i16 -32768, i16 -32768, i16 -32768, i16 -32768, i16 -32768>, <8 x i16> <i16 -32768, i16 -32768, i16 -32768, i16 -32768, i16 -32768, i16 -32768, i16 -32768, i16 -32768>)
+  %2 = icmp eq <4 x i32> %1, <i32 -2147483648, i32 -2147483648, i32 -2147483648, i32 -2147483648>
+  %3 = select <4 x i1> %2, <4 x i32> <i32 2147483647, i32 2147483647, i32 2147483647, i32 2147483647>, <4 x i32> zeroinitializer
+  %4 = add <4 x i32> %3, <i32 -8, i32 -9, i32 -10, i32 -11>
+  %.not = trunc <4 x i32> %3 to <4 x i1>
+  %5 = icmp sgt <4 x i32> %4, <i32 2147483640, i32 2147483639, i32 2147483638, i32 2147483637>
+  %6 = select <4 x i1> %.not, <4 x i1> %5, <4 x i1> zeroinitializer
+  %7 = bitcast <4 x i1> %6 to i4
+  %8 = icmp eq i4 %7, 0
+  ret i1 %8
+}


        


More information about the llvm-commits mailing list