[X86] Don't fold scalar_to_vector(i64 C) -> vzext_movl(scalar_to_vector(i32 C))
authorSimon Pilgrim <llvm-dev@redking.me.uk>
Wed, 14 Dec 2022 12:10:59 +0000 (12:10 +0000)
committerSimon Pilgrim <llvm-dev@redking.me.uk>
Wed, 14 Dec 2022 12:11:06 +0000 (12:11 +0000)
Fixes constant-folding infinite loop reported by @uabelho on rG5ca77541446d

llvm/lib/Target/X86/X86ISelLowering.cpp
llvm/test/CodeGen/X86/vec_insert-7.ll
llvm/test/CodeGen/X86/vector-shuffle-combining.ll

index c627d36..52933c8 100644 (file)
@@ -55531,8 +55531,11 @@ static SDValue combineScalarToVector(SDNode *N, SelectionDAG &DAG) {
         if (Ld->getExtensionType() == Ext &&
             Ld->getMemoryVT().getScalarSizeInBits() <= 32)
           return Op;
-      if (IsZeroExt && DAG.MaskedValueIsZero(Op, APInt::getHighBitsSet(64, 32)))
-        return Op;
+      if (IsZeroExt) {
+        KnownBits Known = DAG.computeKnownBits(Op);
+        if (!Known.isConstant() && Known.countMinLeadingZeros() >= 32)
+          return Op;
+      }
       return SDValue();
     };
 
index 8fd6e3d..cea0474 100644 (file)
@@ -14,7 +14,8 @@ define x86_mmx @mmx_movzl(x86_mmx %x) nounwind {
 ;
 ; X64-LABEL: mmx_movzl:
 ; X64:       ## %bb.0:
-; X64-NEXT:    movaps {{.*#+}} xmm0 = [32,0,0,0]
+; X64-NEXT:    movl $32, %eax
+; X64-NEXT:    movq %rax, %xmm0
 ; X64-NEXT:    retq
   %tmp = bitcast x86_mmx %x to <2 x i32>
   %tmp3 = insertelement <2 x i32> %tmp, i32 32, i32 0
index b8fac4d..91f2a67 100644 (file)
@@ -3530,3 +3530,30 @@ entry:
   store <4 x float> %21, ptr undef, align 16
   ret void
 }
+
+; Inifite loop test case reported on 5ca77541446d
+define void @autogen_SD25931() {
+; CHECK-LABEL: autogen_SD25931:
+; CHECK:       # %bb.0: # %BB
+; CHECK-NEXT:    .p2align 4, 0x90
+; CHECK-NEXT:  .LBB139_1: # %CF242
+; CHECK-NEXT:    # =>This Inner Loop Header: Depth=1
+; CHECK-NEXT:    jmp .LBB139_1
+BB:
+  %Cmp16 = icmp uge <2 x i1> zeroinitializer, zeroinitializer
+  %Shuff19 = shufflevector <2 x i1> zeroinitializer, <2 x i1> %Cmp16, <2 x i32> <i32 3, i32 1>
+  %Shuff33 = shufflevector <2 x i1> %Shuff19, <2 x i1> zeroinitializer, <2 x i32> <i32 0, i32 2>
+  br label %CF250
+
+CF250:                                            ; preds = %CF250, %BB
+  br i1 poison, label %CF250, label %CF259
+
+CF259:                                            ; preds = %CF250
+  %Cmp83 = icmp ule <2 x i1> %Shuff19, zeroinitializer
+  br label %CF242
+
+CF242:                                            ; preds = %CF242, %CF259
+  %Shuff153 = shufflevector <2 x i1> %Shuff33, <2 x i1> poison, <2 x i32> <i32 3, i32 1>
+  %Shuff161 = shufflevector <2 x i1> zeroinitializer, <2 x i1> %Cmp83, <2 x i32> <i32 1, i32 3>
+  br label %CF242
+}