[llvm] [SLP]Initial support for vector register spills/reloads estimation (PR #187594)

Alexey Bataev via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 24 05:37:44 PDT 2026


https://github.com/alexey-bataev updated https://github.com/llvm/llvm-project/pull/187594

>From 002d42ebd4744877d228e9e7660357d9aa1c42ea Mon Sep 17 00:00:00 2001
From: Alexey Bataev <a.bataev at outlook.com>
Date: Thu, 19 Mar 2026 14:39:00 -0700
Subject: [PATCH 1/2] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20in?=
 =?UTF-8?q?itial=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.7
---
 .../Transforms/Vectorize/SLPVectorizer.cpp    |  44 +++-
 .../AArch64/externally-used-copyables.ll      | 231 ++++++++++++------
 .../SLPVectorizer/AArch64/revec-reductions.ll |  68 ++----
 .../Transforms/SLPVectorizer/NVPTX/v2f16.ll   |  23 +-
 .../X86/parent-node-non-schedulable.ll        | 119 ++++-----
 5 files changed, 291 insertions(+), 194 deletions(-)

diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index 1ed3f200a9244..887109fab85d8 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -15285,6 +15285,43 @@ BoUpSLP::getEntryCost(const TreeEntry *E, ArrayRef<Value *> VectorizedVals,
   unsigned EntryVF = E->getVectorFactor();
   auto *FinalVecTy = getWidenedType(ScalarTy, EntryVF);
 
+  InstructionCost SpillsReloads = 0;
+  // Used regs by this node + its operands.
+  unsigned NumUsedRegs = 0;
+  if (E->hasState() && E->getOpcode() != Instruction::Store &&
+      E->getOpcode() != Instruction::InsertElement &&
+      E->getOpcode() != Instruction::ExtractElement &&
+      E->getOpcode() != Instruction::ExtractValue &&
+      E->getOpcode() != Instruction::Freeze &&
+      (E->getOpcode() != Instruction::Load ||
+       E->State == TreeEntry::ScatterVectorize)) {
+    for (unsigned Idx : seq<unsigned>(E->getNumOperands())) {
+      ArrayRef<Value *> Ops = E->getOperand(Idx);
+      if (Ops.empty())
+        continue;
+      Value *Op = Ops.front();
+      if (!Op)
+        continue;
+      auto *OpVecTy = getWidenedType(Op->getType(), Ops.size());
+      NumUsedRegs += ::getNumberOfParts(*TTI, OpVecTy);
+    }
+  }
+  const unsigned RegClass =
+      TTI->getRegisterClassForType(/*Vector=*/true, FinalVecTy);
+  const unsigned NumAvailRegs = TTI->getNumberOfRegisters(RegClass);
+  // Used all the registers - definitely need spill/reload, so include the
+  // cost.
+  if (NumUsedRegs > NumAvailRegs) {
+    InstructionCost SingleRegSpillReload =
+        TTI->getRegisterClassReloadCost(RegClass, CostKind);
+    // No need to spill for reduction and non-returning instructions, like
+    // stores.
+    if (E->Idx > 0 || !UserIgnoreList || VL[0]->getType()->isVoidTy())
+      SingleRegSpillReload +=
+          TTI->getRegisterClassSpillCost(RegClass, CostKind);
+    SpillsReloads =
+        SingleRegSpillReload * (NumUsedRegs / NumAvailRegs) * NumAvailRegs;
+  }
   if (E->isGather() || TransformedToGatherNodes.contains(E)) {
     if (allConstant(VL))
       return 0;
@@ -15292,8 +15329,9 @@ BoUpSLP::getEntryCost(const TreeEntry *E, ArrayRef<Value *> VectorizedVals,
       return InstructionCost::getInvalid();
     if (isa<CmpInst>(VL.front()))
       ScalarTy = VL.front()->getType();
-    return processBuildVector<ShuffleCostEstimator, InstructionCost>(
-        E, ScalarTy, *TTI, VectorizedVals, *this, CheckedExtracts);
+    return SpillsReloads +
+           processBuildVector<ShuffleCostEstimator, InstructionCost>(
+               E, ScalarTy, *TTI, VectorizedVals, *this, CheckedExtracts);
   }
   if (E->State == TreeEntry::SplitVectorize) {
     assert(E->CombinedEntriesWithIndices.size() == 2 &&
@@ -15318,6 +15356,7 @@ BoUpSLP::getEntryCost(const TreeEntry *E, ArrayRef<Value *> VectorizedVals,
                                     getWidenedType(ScalarTy, CommonVF),
                                     E->getSplitMask(), CostKind);
     }
+    VectorCost += SpillsReloads;
     LLVM_DEBUG(dumpTreeCosts(E, 0, VectorCost, 0, "Calculated costs for Tree"));
     return VectorCost;
   }
@@ -15433,6 +15472,7 @@ BoUpSLP::getEntryCost(const TreeEntry *E, ArrayRef<Value *> VectorizedVals,
             }
           }
         }
+        VecCost += SpillsReloads;
         LLVM_DEBUG(dumpTreeCosts(E, CommonCost, VecCost - CommonCost,
                                  ScalarCost, "Calculated costs for Tree"));
         return VecCost - ScalarCost;
diff --git a/llvm/test/Transforms/SLPVectorizer/AArch64/externally-used-copyables.ll b/llvm/test/Transforms/SLPVectorizer/AArch64/externally-used-copyables.ll
index 77a1c812c52a0..0eeb72570635c 100644
--- a/llvm/test/Transforms/SLPVectorizer/AArch64/externally-used-copyables.ll
+++ b/llvm/test/Transforms/SLPVectorizer/AArch64/externally-used-copyables.ll
@@ -5,88 +5,171 @@ define void @test(i64 %0, i64 %1, i64 %2, i64 %3, i64 %.sroa.3341.0.copyload, i6
 ; CHECK-LABEL: define void @test(
 ; CHECK-SAME: i64 [[TMP0:%.*]], i64 [[TMP1:%.*]], i64 [[TMP2:%.*]], i64 [[TMP3:%.*]], i64 [[DOTSROA_3341_0_COPYLOAD:%.*]], i64 [[DOTSROA_3308_0_COPYLOAD:%.*]], i64 [[DOTNEG1:%.*]], i64 [[INDVAR3788:%.*]], i64 [[TMP4:%.*]], i64 [[TMP5:%.*]], i64 [[TMP6:%.*]], i64 [[TMP7:%.*]], i64 [[TMP8:%.*]]) #[[ATTR0:[0-9]+]] {
 ; CHECK-NEXT:  [[_LR_PH_PREHEADER:.*:]]
-; CHECK-NEXT:    [[TMP9:%.*]] = insertelement <4 x i64> poison, i64 [[TMP0]], i32 0
-; CHECK-NEXT:    [[TMP10:%.*]] = shufflevector <4 x i64> [[TMP9]], <4 x i64> poison, <4 x i32> zeroinitializer
-; CHECK-NEXT:    [[TMP11:%.*]] = shufflevector <4 x i64> [[TMP10]], <4 x i64> <i64 48, i64 40, i64 24, i64 poison>, <4 x i32> <i32 4, i32 5, i32 6, i32 0>
-; CHECK-NEXT:    [[TMP12:%.*]] = mul <4 x i64> [[TMP10]], [[TMP11]]
+; CHECK-NEXT:    [[TMP9:%.*]] = mul i64 [[TMP0]], 24
+; CHECK-NEXT:    [[TMP10:%.*]] = mul i64 [[TMP0]], 40
+; CHECK-NEXT:    [[TMP11:%.*]] = mul i64 [[TMP0]], 48
+; CHECK-NEXT:    [[TMP12:%.*]] = add i64 [[TMP0]], 1
+; CHECK-NEXT:    [[TMP13:%.*]] = sub i64 1, [[TMP0]]
 ; CHECK-NEXT:    [[TMP14:%.*]] = shl i64 [[TMP0]], 11
-; CHECK-NEXT:    [[TMP21:%.*]] = shufflevector <4 x i64> [[TMP10]], <4 x i64> <i64 poison, i64 1, i64 poison, i64 1>, <4 x i32> <i32 0, i32 5, i32 poison, i32 7>
-; CHECK-NEXT:    [[TMP15:%.*]] = insertelement <4 x i64> poison, i64 [[TMP14]], i32 0
-; CHECK-NEXT:    [[TMP16:%.*]] = shufflevector <4 x i64> [[TMP15]], <4 x i64> poison, <4 x i32> <i32 poison, i32 poison, i32 0, i32 poison>
-; CHECK-NEXT:    [[TMP22:%.*]] = shufflevector <4 x i64> [[TMP21]], <4 x i64> [[TMP16]], <4 x i32> <i32 0, i32 1, i32 6, i32 3>
-; CHECK-NEXT:    [[TMP32:%.*]] = shufflevector <4 x i64> [[TMP10]], <4 x i64> [[TMP22]], <4 x i32> <i32 poison, i32 0, i32 poison, i32 6>
-; CHECK-NEXT:    [[TMP33:%.*]] = shufflevector <4 x i64> [[TMP32]], <4 x i64> <i64 -1, i64 poison, i64 -8, i64 poison>, <4 x i32> <i32 4, i32 1, i32 6, i32 3>
-; CHECK-NEXT:    [[TMP20:%.*]] = sub <4 x i64> [[TMP22]], [[TMP33]]
+; CHECK-NEXT:    [[TMP15:%.*]] = sub i64 1, [[TMP14]]
+; CHECK-NEXT:    [[TMP16:%.*]] = add i64 [[TMP14]], 8
+; CHECK-NEXT:    [[TMP17:%.*]] = or i64 [[TMP0]], 1
 ; CHECK-NEXT:    [[TMP18:%.*]] = shl i64 [[TMP0]], 1
 ; CHECK-NEXT:    [[TMP19:%.*]] = or i64 [[TMP18]], [[TMP0]]
-; CHECK-NEXT:    [[TMP23:%.*]] = shufflevector <4 x i64> [[TMP22]], <4 x i64> <i64 poison, i64 poison, i64 poison, i64 1>, <4 x i32> <i32 2, i32 0, i32 poison, i32 7>
-; CHECK-NEXT:    [[TMP81:%.*]] = insertelement <4 x i64> poison, i64 [[TMP19]], i32 0
-; CHECK-NEXT:    [[TMP82:%.*]] = shufflevector <4 x i64> [[TMP81]], <4 x i64> poison, <4 x i32> <i32 poison, i32 poison, i32 0, i32 poison>
-; CHECK-NEXT:    [[TMP17:%.*]] = shufflevector <4 x i64> [[TMP23]], <4 x i64> [[TMP82]], <4 x i32> <i32 0, i32 1, i32 6, i32 3>
-; CHECK-NEXT:    [[TMP37:%.*]] = shufflevector <4 x i64> [[TMP17]], <4 x i64> <i64 -8, i64 1, i64 1, i64 poison>, <4 x i32> <i32 4, i32 5, i32 6, i32 0>
-; CHECK-NEXT:    [[TMP38:%.*]] = sub <4 x i64> [[TMP17]], [[TMP37]]
-; CHECK-NEXT:    [[TMP29:%.*]] = or <4 x i64> [[TMP17]], [[TMP37]]
-; CHECK-NEXT:    [[TMP83:%.*]] = shufflevector <4 x i64> [[TMP38]], <4 x i64> [[TMP29]], <4 x i32> <i32 0, i32 5, i32 6, i32 3>
-; CHECK-NEXT:    [[TMP31:%.*]] = shufflevector <4 x i64> [[TMP17]], <4 x i64> poison, <4 x i32> <i32 1, i32 1, i32 1, i32 1>
-; CHECK-NEXT:    [[TMP24:%.*]] = shufflevector <4 x i64> [[TMP17]], <4 x i64> poison, <8 x i32> <i32 1, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison>
-; CHECK-NEXT:    [[TMP25:%.*]] = shufflevector <8 x i64> [[TMP24]], <8 x i64> <i64 poison, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1>, <8 x i32> <i32 0, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15>
-; CHECK-NEXT:    [[TMP42:%.*]] = shufflevector <4 x i64> [[TMP17]], <4 x i64> poison, <2 x i32> <i32 1, i32 1>
-; CHECK-NEXT:    [[TMP80:%.*]] = insertelement <64 x i64> <i64 poison, i64 poison, i64 poison, i64 poison, i64 poison, i64 poison, i64 poison, i64 poison, i64 poison, i64 poison, i64 poison, i64 poison, i64 poison, i64 poison, i64 poison, i64 poison, i64 poison, i64 poison, i64 poison, i64 poison, i64 poison, i64 poison, i64 poison, i64 poison, i64 poison, i64 poison, i64 poison, i64 1, i64 poison, i64 poison, i64 poison, i64 poison, i64 poison, i64 poison, i64 poison, i64 poison, i64 poison, i64 poison, i64 poison, i64 poison, i64 poison, i64 poison, i64 poison, i64 poison, i64 poison, i64 poison, i64 poison, i64 poison, i64 poison, i64 poison, i64 poison, i64 poison, i64 poison, i64 poison, i64 poison, i64 poison, i64 poison, i64 poison, i64 poison, i64 poison, i64 poison, i64 poison, i64 poison, i64 poison>, i64 [[TMP1]], i32 11
-; CHECK-NEXT:    [[TMP28:%.*]] = shufflevector <4 x i64> [[TMP12]], <4 x i64> poison, <28 x i32> <i32 0, i32 1, i32 2, i32 3, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison>
-; CHECK-NEXT:    [[TMP84:%.*]] = shufflevector <4 x i64> [[TMP17]], <4 x i64> poison, <14 x i32> <i32 poison, i32 1, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison>
-; CHECK-NEXT:    [[TMP45:%.*]] = insertelement <2 x i64> poison, i64 [[TMP0]], i32 0
-; CHECK-NEXT:    [[TMP85:%.*]] = shufflevector <2 x i64> [[TMP45]], <2 x i64> poison, <2 x i32> zeroinitializer
-; CHECK-NEXT:    [[TMP86:%.*]] = shufflevector <2 x i64> [[TMP85]], <2 x i64> <i64 poison, i64 1>, <2 x i32> <i32 0, i32 3>
-; CHECK-NEXT:    [[TMP87:%.*]] = mul <2 x i64> [[TMP85]], [[TMP86]]
-; CHECK-NEXT:    [[TMP88:%.*]] = or <2 x i64> [[TMP85]], [[TMP86]]
-; CHECK-NEXT:    [[TMP89:%.*]] = shufflevector <2 x i64> [[TMP87]], <2 x i64> [[TMP88]], <2 x i32> <i32 0, i32 3>
-; CHECK-NEXT:    [[TMP90:%.*]] = shufflevector <2 x i64> [[TMP89]], <2 x i64> poison, <64 x i32> <i32 0, i32 1, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison>
+; CHECK-NEXT:    [[TMP20:%.*]] = or i64 [[TMP19]], 1
+; CHECK-NEXT:    [[TMP21:%.*]] = mul i64 [[TMP0]], [[TMP0]]
 ; CHECK-NEXT:    br label %[[DOTLR_PH1977_US:.*]]
 ; CHECK:       [[_LR_PH1977_US:.*:]]
 ; CHECK-NEXT:    [[INDVAR37888:%.*]] = phi i64 [ 0, [[DOTLR_PH_PREHEADER:%.*]] ], [ 1, %[[DOTLR_PH1977_US]] ]
-; CHECK-NEXT:    [[TMP34:%.*]] = mul <4 x i64> [[TMP83]], [[TMP31]]
-; CHECK-NEXT:    [[TMP35:%.*]] = shufflevector <4 x i64> [[TMP34]], <4 x i64> poison, <8 x i32> <i32 0, i32 1, i32 1, i32 1, i32 1, i32 2, i32 3, i32 3>
-; CHECK-NEXT:    [[TMP36:%.*]] = mul <4 x i64> [[TMP20]], [[TMP31]]
+; CHECK-NEXT:    [[TMP22:%.*]] = mul i64 [[TMP16]], [[TMP0]]
+; CHECK-NEXT:    [[TMP23:%.*]] = mul i64 [[TMP20]], [[TMP0]]
+; CHECK-NEXT:    [[TMP24:%.*]] = mul i64 [[TMP15]], [[TMP0]]
+; CHECK-NEXT:    [[TMP25:%.*]] = mul i64 [[TMP17]], [[TMP0]]
 ; CHECK-NEXT:    [[TMP26:%.*]] = call i64 @llvm.vscale.i64()
-; CHECK-NEXT:    [[TMP40:%.*]] = or <2 x i64> [[TMP42]], splat (i64 1)
-; CHECK-NEXT:    [[TMP41:%.*]] = shl <2 x i64> [[TMP42]], splat (i64 1)
+; CHECK-NEXT:    [[DIFF_CHECK3783:%.*]] = icmp ult i64 [[TMP11]], [[TMP26]]
+; CHECK-NEXT:    [[DIFF_CHECK3790:%.*]] = icmp ult i64 [[INDVAR37888]], [[TMP0]]
+; CHECK-NEXT:    [[CONFLICT_RDX3791:%.*]] = or i1 [[DIFF_CHECK3783]], [[DIFF_CHECK3790]]
 ; CHECK-NEXT:    [[TMP39:%.*]] = mul i64 [[TMP0]], [[TMP0]]
-; CHECK-NEXT:    [[TMP43:%.*]] = add <8 x i64> [[TMP35]], [[TMP25]]
-; CHECK-NEXT:    [[TMP44:%.*]] = insertelement <64 x i64> [[TMP80]], i64 [[INDVAR37888]], i32 1
-; CHECK-NEXT:    [[TMP46:%.*]] = shufflevector <64 x i64> [[TMP44]], <64 x i64> [[TMP90]], <64 x i32> <i32 poison, i32 1, i32 64, i32 65, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 11, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 27, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison>
-; CHECK-NEXT:    [[TMP47:%.*]] = shufflevector <8 x i64> [[TMP35]], <8 x i64> poison, <64 x i32> <i32 poison, i32 1, i32 poison, i32 poison, i32 poison, i32 5, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison>
-; CHECK-NEXT:    [[TMP48:%.*]] = shufflevector <4 x i64> [[TMP34]], <4 x i64> poison, <64 x i32> <i32 0, i32 1, i32 2, i32 3, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison>
-; CHECK-NEXT:    [[TMP49:%.*]] = shufflevector <64 x i64> [[TMP46]], <64 x i64> [[TMP48]], <64 x i32> <i32 poison, i32 1, i32 2, i32 3, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 11, i32 poison, i32 65, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 66, i32 27, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison>
-; CHECK-NEXT:    [[TMP50:%.*]] = insertelement <64 x i64> [[TMP49]], i64 [[TMP39]], i32 17
-; CHECK-NEXT:    [[TMP51:%.*]] = shufflevector <64 x i64> [[TMP50]], <64 x i64> poison, <28 x i32> <i32 poison, i32 1, i32 2, i32 3, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 11, i32 poison, i32 13, i32 poison, i32 poison, i32 poison, i32 17, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 26, i32 27>
-; CHECK-NEXT:    [[TMP52:%.*]] = shufflevector <8 x i64> [[TMP43]], <8 x i64> poison, <28 x i32> <i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 poison, i32 poison, i32 poison, i32 poison>
-; CHECK-NEXT:    [[TMP53:%.*]] = shufflevector <28 x i64> [[TMP52]], <28 x i64> [[TMP28]], <28 x i32> <i32 28, i32 29, i32 30, i32 31, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23, i32 poison, i32 poison, i32 poison, i32 poison>
-; CHECK-NEXT:    [[TMP54:%.*]] = shufflevector <4 x i64> [[TMP36]], <4 x i64> poison, <28 x i32> <i32 0, i32 1, i32 2, i32 3, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison>
-; CHECK-NEXT:    [[TMP55:%.*]] = shufflevector <28 x i64> [[TMP53]], <28 x i64> [[TMP54]], <28 x i32> <i32 0, i32 1, i32 2, i32 3, i32 poison, i32 poison, i32 poison, i32 poison, i32 28, i32 29, i32 30, i32 31, i32 poison, i32 poison, i32 poison, i32 poison, i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23, i32 poison, i32 poison, i32 poison, i32 poison>
-; CHECK-NEXT:    [[TMP56:%.*]] = shufflevector <2 x i64> [[TMP40]], <2 x i64> poison, <28 x i32> <i32 0, i32 1, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison>
-; CHECK-NEXT:    [[TMP57:%.*]] = shufflevector <28 x i64> [[TMP55]], <28 x i64> [[TMP56]], <28 x i32> <i32 0, i32 1, i32 2, i32 3, i32 poison, i32 poison, i32 poison, i32 poison, i32 8, i32 9, i32 10, i32 11, i32 poison, i32 poison, i32 28, i32 29, i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23, i32 poison, i32 poison, i32 poison, i32 poison>
-; CHECK-NEXT:    [[TMP58:%.*]] = shufflevector <2 x i64> [[TMP41]], <2 x i64> poison, <28 x i32> <i32 0, i32 1, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison>
-; CHECK-NEXT:    [[TMP59:%.*]] = shufflevector <28 x i64> [[TMP57]], <28 x i64> [[TMP58]], <28 x i32> <i32 0, i32 1, i32 2, i32 3, i32 poison, i32 poison, i32 poison, i32 poison, i32 8, i32 9, i32 10, i32 11, i32 poison, i32 poison, i32 14, i32 15, i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23, i32 poison, i32 poison, i32 28, i32 29>
-; CHECK-NEXT:    [[TMP60:%.*]] = shufflevector <28 x i64> [[TMP59]], <28 x i64> poison, <64 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15, i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23, i32 24, i32 25, i32 26, i32 27, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison>
-; CHECK-NEXT:    [[TMP61:%.*]] = shufflevector <64 x i64> [[TMP60]], <64 x i64> [[TMP50]], <28 x i32> <i32 0, i32 65, i32 66, i32 67, i32 14, i32 15, i32 16, i32 17, i32 18, i32 19, i32 20, i32 75, i32 21, i32 77, i32 26, i32 27, i32 1, i32 81, i32 8, i32 9, i32 22, i32 10, i32 2, i32 3, i32 11, i32 23, i32 90, i32 91>
-; CHECK-NEXT:    [[TMP62:%.*]] = shufflevector <28 x i64> [[TMP61]], <28 x i64> poison, <64 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15, i32 11, i32 16, i32 1, i32 17, i32 18, i32 19, i32 20, i32 11, i32 21, i32 13, i32 11, i32 11, i32 13, i32 11, i32 14, i32 15, i32 22, i32 11, i32 1, i32 17, i32 23, i32 24, i32 11, i32 11, i32 21, i32 13, i32 11, i32 11, i32 13, i32 11, i32 15, i32 22, i32 1, i32 17, i32 25, i32 21, i32 21, i32 21, i32 11, i32 11, i32 26, i32 13, i32 14, i32 11, i32 1, i32 17, i32 11, i32 27>
-; CHECK-NEXT:    [[TMP63:%.*]] = shufflevector <28 x i64> [[TMP61]], <28 x i64> poison, <14 x i32> <i32 poison, i32 poison, i32 11, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison>
-; CHECK-NEXT:    [[TMP64:%.*]] = shufflevector <14 x i64> [[TMP84]], <14 x i64> [[TMP63]], <14 x i32> <i32 poison, i32 1, i32 16, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison>
-; CHECK-NEXT:    [[TMP65:%.*]] = insertelement <14 x i64> [[TMP64]], i64 [[DOTNEG1]], i32 3
-; CHECK-NEXT:    [[TMP66:%.*]] = insertelement <14 x i64> [[TMP65]], i64 [[TMP2]], i32 4
-; CHECK-NEXT:    [[TMP67:%.*]] = insertelement <14 x i64> [[TMP66]], i64 [[TMP3]], i32 5
-; CHECK-NEXT:    [[TMP68:%.*]] = insertelement <14 x i64> [[TMP67]], i64 [[TMP4]], i32 6
-; CHECK-NEXT:    [[TMP69:%.*]] = insertelement <14 x i64> [[TMP68]], i64 [[INDVAR3788]], i32 7
-; CHECK-NEXT:    [[TMP70:%.*]] = insertelement <14 x i64> [[TMP69]], i64 [[TMP5]], i32 8
-; CHECK-NEXT:    [[TMP71:%.*]] = insertelement <14 x i64> [[TMP70]], i64 [[TMP6]], i32 9
-; CHECK-NEXT:    [[TMP72:%.*]] = insertelement <14 x i64> [[TMP71]], i64 [[TMP7]], i32 10
-; CHECK-NEXT:    [[TMP73:%.*]] = insertelement <14 x i64> [[TMP72]], i64 [[DOTSROA_3341_0_COPYLOAD]], i32 11
-; CHECK-NEXT:    [[TMP74:%.*]] = insertelement <14 x i64> [[TMP73]], i64 [[TMP8]], i32 12
-; CHECK-NEXT:    [[TMP75:%.*]] = insertelement <14 x i64> [[TMP74]], i64 [[DOTSROA_3308_0_COPYLOAD]], i32 13
-; CHECK-NEXT:    [[TMP76:%.*]] = insertelement <14 x i64> [[TMP75]], i64 [[TMP26]], i32 0
-; CHECK-NEXT:    [[TMP77:%.*]] = shufflevector <14 x i64> [[TMP76]], <14 x i64> poison, <64 x i32> <i32 0, i32 1, i32 1, i32 2, i32 2, i32 2, i32 3, i32 1, i32 1, i32 1, i32 1, i32 4, i32 1, i32 1, i32 2, i32 2, i32 1, i32 1, i32 1, i32 1, i32 1, i32 1, i32 1, i32 5, i32 1, i32 2, i32 6, i32 7, i32 1, i32 1, i32 2, i32 2, i32 1, i32 4, i32 1, i32 1, i32 1, i32 1, i32 8, i32 9, i32 1, i32 2, i32 10, i32 11, i32 1, i32 1, i32 2, i32 1, i32 1, i32 1, i32 1, i32 1, i32 2, i32 4, i32 12, i32 13, i32 1, i32 1, i32 2, i32 1, i32 1, i32 1, i32 4, i32 0>
-; CHECK-NEXT:    [[TMP78:%.*]] = icmp ult <64 x i64> [[TMP62]], [[TMP77]]
-; CHECK-NEXT:    [[TMP79:%.*]] = call i1 @llvm.vector.reduce.or.v64i1(<64 x i1> [[TMP78]])
+; CHECK-NEXT:    [[DIFF_CHECK3793:%.*]] = icmp ult i64 [[TMP39]], [[TMP0]]
+; CHECK-NEXT:    [[CONFLICT_RDX3794:%.*]] = or i1 [[CONFLICT_RDX3791]], [[DIFF_CHECK3793]]
+; CHECK-NEXT:    [[TMP28:%.*]] = or i64 [[TMP0]], 1
+; CHECK-NEXT:    [[DIFF_CHECK3796:%.*]] = icmp ult i64 [[TMP28]], [[TMP1]]
+; CHECK-NEXT:    [[CONFLICT_RDX3797:%.*]] = or i1 [[CONFLICT_RDX3794]], [[DIFF_CHECK3796]]
+; CHECK-NEXT:    [[TMP29:%.*]] = or i64 [[TMP0]], 1
+; CHECK-NEXT:    [[DIFF_CHECK3799:%.*]] = icmp ult i64 [[TMP29]], [[TMP1]]
+; CHECK-NEXT:    [[CONFLICT_RDX3800:%.*]] = or i1 [[CONFLICT_RDX3797]], [[DIFF_CHECK3799]]
+; CHECK-NEXT:    [[TMP30:%.*]] = or i64 [[TMP0]], 1
+; CHECK-NEXT:    [[DIFF_CHECK3802:%.*]] = icmp ult i64 [[TMP30]], [[TMP1]]
+; CHECK-NEXT:    [[CONFLICT_RDX3803:%.*]] = or i1 [[CONFLICT_RDX3800]], [[DIFF_CHECK3802]]
+; CHECK-NEXT:    [[DIFF_CHECK3805:%.*]] = icmp ugt i64 [[TMP26]], 1
+; CHECK-NEXT:    [[CONFLICT_RDX3806:%.*]] = or i1 [[CONFLICT_RDX3803]], [[DIFF_CHECK3805]]
+; CHECK-NEXT:    [[TMP31:%.*]] = add i64 [[TMP22]], [[TMP0]]
+; CHECK-NEXT:    [[DIFF_CHECK3807:%.*]] = icmp ult i64 [[TMP31]], [[DOTNEG1]]
+; CHECK-NEXT:    [[CONFLICT_RDX3808:%.*]] = or i1 [[CONFLICT_RDX3806]], [[DIFF_CHECK3807]]
+; CHECK-NEXT:    [[TMP32:%.*]] = add i64 [[TMP25]], 1
+; CHECK-NEXT:    [[DIFF_CHECK3809:%.*]] = icmp ult i64 [[TMP32]], [[TMP0]]
+; CHECK-NEXT:    [[CONFLICT_RDX3810:%.*]] = or i1 [[CONFLICT_RDX3808]], [[DIFF_CHECK3809]]
+; CHECK-NEXT:    [[TMP33:%.*]] = add i64 [[TMP25]], 1
+; CHECK-NEXT:    [[DIFF_CHECK3811:%.*]] = icmp ult i64 [[TMP33]], [[TMP0]]
+; CHECK-NEXT:    [[CONFLICT_RDX3812:%.*]] = or i1 [[CONFLICT_RDX3810]], [[DIFF_CHECK3811]]
+; CHECK-NEXT:    [[TMP34:%.*]] = add i64 [[TMP25]], 1
+; CHECK-NEXT:    [[DIFF_CHECK3813:%.*]] = icmp ult i64 [[TMP34]], [[TMP0]]
+; CHECK-NEXT:    [[CONFLICT_RDX3814:%.*]] = or i1 [[CONFLICT_RDX3812]], [[DIFF_CHECK3813]]
+; CHECK-NEXT:    [[TMP35:%.*]] = add i64 [[TMP25]], 1
+; CHECK-NEXT:    [[DIFF_CHECK3815:%.*]] = icmp ult i64 [[TMP35]], [[TMP0]]
+; CHECK-NEXT:    [[CONFLICT_RDX3816:%.*]] = or i1 [[CONFLICT_RDX3814]], [[DIFF_CHECK3815]]
+; CHECK-NEXT:    [[DIFF_CHECK3817:%.*]] = icmp ult i64 [[TMP1]], [[TMP2]]
+; CHECK-NEXT:    [[CONFLICT_RDX3818:%.*]] = or i1 [[CONFLICT_RDX3816]], [[DIFF_CHECK3817]]
+; CHECK-NEXT:    [[TMP36:%.*]] = add i64 [[TMP23]], 1
+; CHECK-NEXT:    [[DIFF_CHECK3820:%.*]] = icmp ult i64 [[TMP36]], [[TMP0]]
+; CHECK-NEXT:    [[CONFLICT_RDX3821:%.*]] = or i1 [[CONFLICT_RDX3818]], [[DIFF_CHECK3820]]
+; CHECK-NEXT:    [[DIFF_CHECK3822:%.*]] = icmp ult i64 [[TMP25]], [[TMP0]]
+; CHECK-NEXT:    [[CONFLICT_RDX3823:%.*]] = or i1 [[CONFLICT_RDX3821]], [[DIFF_CHECK3822]]
+; CHECK-NEXT:    [[TMP37:%.*]] = shl i64 [[TMP0]], 1
+; CHECK-NEXT:    [[DIFF_CHECK3824:%.*]] = icmp ult i64 [[TMP37]], [[TMP1]]
+; CHECK-NEXT:    [[CONFLICT_RDX3825:%.*]] = or i1 [[CONFLICT_RDX3823]], [[DIFF_CHECK3824]]
+; CHECK-NEXT:    [[TMP38:%.*]] = shl i64 [[TMP0]], 1
+; CHECK-NEXT:    [[DIFF_CHECK3826:%.*]] = icmp ult i64 [[TMP38]], [[TMP1]]
+; CHECK-NEXT:    [[CONFLICT_RDX3827:%.*]] = or i1 [[CONFLICT_RDX3825]], [[DIFF_CHECK3826]]
+; CHECK-NEXT:    [[DIFF_CHECK3830:%.*]] = icmp ult i64 [[TMP1]], [[TMP0]]
+; CHECK-NEXT:    [[CONFLICT_RDX3831:%.*]] = or i1 [[CONFLICT_RDX3827]], [[DIFF_CHECK3830]]
+; CHECK-NEXT:    [[DIFF_CHECK3832:%.*]] = icmp ult i64 [[TMP10]], [[TMP0]]
+; CHECK-NEXT:    [[CONFLICT_RDX3833:%.*]] = or i1 [[CONFLICT_RDX3831]], [[DIFF_CHECK3832]]
+; CHECK-NEXT:    [[DIFF_CHECK3834:%.*]] = icmp ult i64 [[INDVAR37888]], [[TMP0]]
+; CHECK-NEXT:    [[CONFLICT_RDX3835:%.*]] = or i1 [[CONFLICT_RDX3833]], [[DIFF_CHECK3834]]
+; CHECK-NEXT:    [[TMP44:%.*]] = mul i64 [[TMP0]], [[TMP0]]
+; CHECK-NEXT:    [[DIFF_CHECK3836:%.*]] = icmp ult i64 [[TMP44]], [[TMP0]]
+; CHECK-NEXT:    [[CONFLICT_RDX3837:%.*]] = or i1 [[CONFLICT_RDX3835]], [[DIFF_CHECK3836]]
+; CHECK-NEXT:    [[TMP40:%.*]] = mul i64 [[TMP12]], [[TMP0]]
+; CHECK-NEXT:    [[DIFF_CHECK3838:%.*]] = icmp ult i64 [[TMP40]], [[TMP0]]
+; CHECK-NEXT:    [[CONFLICT_RDX3839:%.*]] = or i1 [[CONFLICT_RDX3837]], [[DIFF_CHECK3838]]
+; CHECK-NEXT:    [[TMP41:%.*]] = mul i64 [[TMP13]], [[TMP0]]
+; CHECK-NEXT:    [[DIFF_CHECK3840:%.*]] = icmp ult i64 [[TMP41]], [[TMP0]]
+; CHECK-NEXT:    [[CONFLICT_RDX3841:%.*]] = or i1 [[CONFLICT_RDX3839]], [[DIFF_CHECK3840]]
+; CHECK-NEXT:    [[TMP42:%.*]] = add i64 [[TMP24]], 1
+; CHECK-NEXT:    [[DIFF_CHECK3842:%.*]] = icmp ult i64 [[TMP42]], [[TMP0]]
+; CHECK-NEXT:    [[CONFLICT_RDX3843:%.*]] = or i1 [[CONFLICT_RDX3841]], [[DIFF_CHECK3842]]
+; CHECK-NEXT:    [[DIFF_CHECK3846:%.*]] = icmp ult i64 [[TMP1]], [[TMP3]]
+; CHECK-NEXT:    [[CONFLICT_RDX3847:%.*]] = or i1 [[CONFLICT_RDX3843]], [[DIFF_CHECK3846]]
+; CHECK-NEXT:    [[DIFF_CHECK3848:%.*]] = icmp ult i64 [[TMP22]], [[TMP0]]
+; CHECK-NEXT:    [[CONFLICT_RDX3849:%.*]] = or i1 [[CONFLICT_RDX3847]], [[DIFF_CHECK3848]]
+; CHECK-NEXT:    [[DIFF_CHECK3850:%.*]] = icmp ult i64 [[TMP25]], [[TMP1]]
+; CHECK-NEXT:    [[CONFLICT_RDX3851:%.*]] = or i1 [[CONFLICT_RDX3849]], [[DIFF_CHECK3850]]
+; CHECK-NEXT:    [[DIFF_CHECK3852:%.*]] = icmp ult i64 [[TMP1]], [[TMP4]]
+; CHECK-NEXT:    [[CONFLICT_RDX3853:%.*]] = or i1 [[CONFLICT_RDX3851]], [[DIFF_CHECK3852]]
+; CHECK-NEXT:    [[DIFF_CHECK3854:%.*]] = icmp ult i64 [[TMP1]], [[INDVAR3788]]
+; CHECK-NEXT:    [[CONFLICT_RDX3855:%.*]] = or i1 [[CONFLICT_RDX3853]], [[DIFF_CHECK3854]]
+; CHECK-NEXT:    [[DIFF_CHECK3856:%.*]] = icmp ult i64 [[TMP25]], [[TMP0]]
+; CHECK-NEXT:    [[CONFLICT_RDX3857:%.*]] = or i1 [[CONFLICT_RDX3855]], [[DIFF_CHECK3856]]
+; CHECK-NEXT:    [[DIFF_CHECK3860:%.*]] = icmp ult i64 [[TMP1]], [[TMP0]]
+; CHECK-NEXT:    [[CONFLICT_RDX3861:%.*]] = or i1 [[CONFLICT_RDX3857]], [[DIFF_CHECK3860]]
+; CHECK-NEXT:    [[DIFF_CHECK3862:%.*]] = icmp ult i64 [[TMP37]], [[TMP1]]
+; CHECK-NEXT:    [[CONFLICT_RDX3863:%.*]] = or i1 [[CONFLICT_RDX3861]], [[DIFF_CHECK3862]]
+; CHECK-NEXT:    [[DIFF_CHECK3864:%.*]] = icmp ult i64 [[TMP38]], [[TMP1]]
+; CHECK-NEXT:    [[CONFLICT_RDX3865:%.*]] = or i1 [[CONFLICT_RDX3863]], [[DIFF_CHECK3864]]
+; CHECK-NEXT:    [[DIFF_CHECK3866:%.*]] = icmp ult i64 [[TMP9]], [[TMP0]]
+; CHECK-NEXT:    [[CONFLICT_RDX3867:%.*]] = or i1 [[CONFLICT_RDX3865]], [[DIFF_CHECK3866]]
+; CHECK-NEXT:    [[DIFF_CHECK3868:%.*]] = icmp ult i64 [[TMP1]], [[TMP2]]
+; CHECK-NEXT:    [[CONFLICT_RDX3869:%.*]] = or i1 [[CONFLICT_RDX3867]], [[DIFF_CHECK3868]]
+; CHECK-NEXT:    [[DIFF_CHECK3870:%.*]] = icmp ult i64 [[INDVAR37888]], [[TMP0]]
+; CHECK-NEXT:    [[CONFLICT_RDX3871:%.*]] = or i1 [[CONFLICT_RDX3869]], [[DIFF_CHECK3870]]
+; CHECK-NEXT:    [[DIFF_CHECK3872:%.*]] = icmp ult i64 [[TMP44]], [[TMP0]]
+; CHECK-NEXT:    [[CONFLICT_RDX3873:%.*]] = or i1 [[CONFLICT_RDX3871]], [[DIFF_CHECK3872]]
+; CHECK-NEXT:    [[DIFF_CHECK3876:%.*]] = icmp ult i64 [[TMP21]], [[TMP0]]
+; CHECK-NEXT:    [[DIFF_CHECK3878:%.*]] = icmp ult i64 [[TMP24]], [[TMP0]]
+; CHECK-NEXT:    [[CONFLICT_RDX3877:%.*]] = or i1 [[CONFLICT_RDX3873]], [[DIFF_CHECK3876]]
+; CHECK-NEXT:    [[CONFLICT_RDX3879:%.*]] = or i1 [[CONFLICT_RDX3877]], [[DIFF_CHECK3878]]
+; CHECK-NEXT:    [[DIFF_CHECK3882:%.*]] = icmp ult i64 [[TMP1]], [[TMP5]]
+; CHECK-NEXT:    [[CONFLICT_RDX3883:%.*]] = or i1 [[CONFLICT_RDX3879]], [[DIFF_CHECK3882]]
+; CHECK-NEXT:    [[DIFF_CHECK3884:%.*]] = icmp ult i64 [[TMP1]], [[TMP6]]
+; CHECK-NEXT:    [[CONFLICT_RDX3885:%.*]] = or i1 [[CONFLICT_RDX3883]], [[DIFF_CHECK3884]]
+; CHECK-NEXT:    [[DIFF_CHECK3886:%.*]] = icmp ult i64 [[TMP22]], [[TMP0]]
+; CHECK-NEXT:    [[CONFLICT_RDX3887:%.*]] = or i1 [[CONFLICT_RDX3885]], [[DIFF_CHECK3886]]
+; CHECK-NEXT:    [[DIFF_CHECK3890:%.*]] = icmp ult i64 [[TMP25]], [[TMP1]]
+; CHECK-NEXT:    [[CONFLICT_RDX3891:%.*]] = or i1 [[CONFLICT_RDX3887]], [[DIFF_CHECK3890]]
+; CHECK-NEXT:    [[DIFF_CHECK3892:%.*]] = icmp ult i64 [[TMP1]], [[TMP7]]
+; CHECK-NEXT:    [[CONFLICT_RDX3893:%.*]] = or i1 [[CONFLICT_RDX3891]], [[DIFF_CHECK3892]]
+; CHECK-NEXT:    [[DIFF_CHECK3894:%.*]] = icmp ult i64 [[TMP1]], [[DOTSROA_3341_0_COPYLOAD]]
+; CHECK-NEXT:    [[CONFLICT_RDX3895:%.*]] = or i1 [[CONFLICT_RDX3893]], [[DIFF_CHECK3894]]
+; CHECK-NEXT:    [[DIFF_CHECK3896:%.*]] = icmp ult i64 [[TMP25]], [[TMP0]]
+; CHECK-NEXT:    [[CONFLICT_RDX3897:%.*]] = or i1 [[CONFLICT_RDX3895]], [[DIFF_CHECK3896]]
+; CHECK-NEXT:    [[DIFF_CHECK3898:%.*]] = icmp ult i64 [[TMP1]], [[TMP0]]
+; CHECK-NEXT:    [[CONFLICT_RDX3899:%.*]] = or i1 [[CONFLICT_RDX3897]], [[DIFF_CHECK3898]]
+; CHECK-NEXT:    [[DIFF_CHECK3900:%.*]] = icmp ult i64 [[TMP38]], [[TMP1]]
+; CHECK-NEXT:    [[CONFLICT_RDX3901:%.*]] = or i1 [[CONFLICT_RDX3899]], [[DIFF_CHECK3900]]
+; CHECK-NEXT:    [[DIFF_CHECK3902:%.*]] = icmp ult i64 [[TMP9]], [[TMP0]]
+; CHECK-NEXT:    [[CONFLICT_RDX3903:%.*]] = or i1 [[CONFLICT_RDX3901]], [[DIFF_CHECK3902]]
+; CHECK-NEXT:    [[DIFF_CHECK3904:%.*]] = icmp ult i64 [[INDVAR37888]], [[TMP0]]
+; CHECK-NEXT:    [[CONFLICT_RDX3905:%.*]] = or i1 [[CONFLICT_RDX3903]], [[DIFF_CHECK3904]]
+; CHECK-NEXT:    [[DIFF_CHECK3906:%.*]] = icmp ult i64 [[TMP44]], [[TMP0]]
+; CHECK-NEXT:    [[CONFLICT_RDX3907:%.*]] = or i1 [[CONFLICT_RDX3905]], [[DIFF_CHECK3906]]
+; CHECK-NEXT:    [[TMP43:%.*]] = add i64 [[TMP24]], 1
+; CHECK-NEXT:    [[DIFF_CHECK3912:%.*]] = icmp ult i64 [[TMP43]], [[TMP0]]
+; CHECK-NEXT:    [[CONFLICT_RDX3913:%.*]] = or i1 [[CONFLICT_RDX3907]], [[DIFF_CHECK3912]]
+; CHECK-NEXT:    [[DIFF_CHECK3916:%.*]] = icmp ult i64 [[TMP22]], [[TMP0]]
+; CHECK-NEXT:    [[CONFLICT_RDX3917:%.*]] = or i1 [[CONFLICT_RDX3913]], [[DIFF_CHECK3916]]
+; CHECK-NEXT:    [[DIFF_CHECK3920:%.*]] = icmp ult i64 [[TMP22]], [[TMP1]]
+; CHECK-NEXT:    [[CONFLICT_RDX3921:%.*]] = or i1 [[CONFLICT_RDX3917]], [[DIFF_CHECK3920]]
+; CHECK-NEXT:    [[DIFF_CHECK3922:%.*]] = icmp ult i64 [[TMP22]], [[TMP2]]
+; CHECK-NEXT:    [[CONFLICT_RDX3923:%.*]] = or i1 [[CONFLICT_RDX3921]], [[DIFF_CHECK3922]]
+; CHECK-NEXT:    [[DIFF_CHECK3924:%.*]] = icmp ult i64 [[TMP1]], [[TMP8]]
+; CHECK-NEXT:    [[CONFLICT_RDX3925:%.*]] = or i1 [[CONFLICT_RDX3923]], [[DIFF_CHECK3924]]
+; CHECK-NEXT:    [[DIFF_CHECK3926:%.*]] = icmp ult i64 [[TMP1]], [[DOTSROA_3308_0_COPYLOAD]]
+; CHECK-NEXT:    [[CONFLICT_RDX3927:%.*]] = or i1 [[CONFLICT_RDX3925]], [[DIFF_CHECK3926]]
+; CHECK-NEXT:    [[DIFF_CHECK3928:%.*]] = icmp ult i64 [[TMP23]], [[TMP0]]
+; CHECK-NEXT:    [[CONFLICT_RDX3929:%.*]] = or i1 [[CONFLICT_RDX3927]], [[DIFF_CHECK3928]]
+; CHECK-NEXT:    [[DIFF_CHECK3930:%.*]] = icmp ult i64 [[TMP25]], [[TMP0]]
+; CHECK-NEXT:    [[CONFLICT_RDX3931:%.*]] = or i1 [[CONFLICT_RDX3929]], [[DIFF_CHECK3930]]
+; CHECK-NEXT:    [[DIFF_CHECK3932:%.*]] = icmp ult i64 [[TMP37]], [[TMP1]]
+; CHECK-NEXT:    [[CONFLICT_RDX3933:%.*]] = or i1 [[CONFLICT_RDX3931]], [[DIFF_CHECK3932]]
+; CHECK-NEXT:    [[DIFF_CHECK3934:%.*]] = icmp ult i64 [[TMP1]], [[TMP0]]
+; CHECK-NEXT:    [[CONFLICT_RDX3935:%.*]] = or i1 [[CONFLICT_RDX3933]], [[DIFF_CHECK3934]]
+; CHECK-NEXT:    [[DIFF_CHECK3936:%.*]] = icmp ult i64 [[INDVAR37888]], [[TMP0]]
+; CHECK-NEXT:    [[CONFLICT_RDX3937:%.*]] = or i1 [[CONFLICT_RDX3935]], [[DIFF_CHECK3936]]
+; CHECK-NEXT:    [[DIFF_CHECK3938:%.*]] = icmp ult i64 [[TMP44]], [[TMP0]]
+; CHECK-NEXT:    [[CONFLICT_RDX3939:%.*]] = or i1 [[CONFLICT_RDX3937]], [[DIFF_CHECK3938]]
+; CHECK-NEXT:    [[DIFF_CHECK3950:%.*]] = icmp ult i64 [[TMP1]], [[TMP2]]
+; CHECK-NEXT:    [[TMP79:%.*]] = or i1 [[CONFLICT_RDX3939]], [[DIFF_CHECK3950]]
 ; CHECK-NEXT:    br i1 [[TMP79]], label %[[SCALAR_PH4023:.*]], label %[[DOTLR_PH1977_US]]
 ; CHECK:       [[SCALAR_PH4023]]:
 ; CHECK-NEXT:    ret void
diff --git a/llvm/test/Transforms/SLPVectorizer/AArch64/revec-reductions.ll b/llvm/test/Transforms/SLPVectorizer/AArch64/revec-reductions.ll
index 92701dadbfc1b..4f0e38ebf34bd 100644
--- a/llvm/test/Transforms/SLPVectorizer/AArch64/revec-reductions.ll
+++ b/llvm/test/Transforms/SLPVectorizer/AArch64/revec-reductions.ll
@@ -4,55 +4,25 @@
 define <16 x i64> @test() {
 ; CHECK-LABEL: define <16 x i64> @test() {
 ; CHECK-NEXT:  [[ENTRY:.*:]]
-; CHECK-NEXT:    [[TMP0:%.*]] = call <64 x i64> @llvm.smin.v64i64(<64 x i64> <i64 -1, i64 -1, i64 -1, i64 -1, i64 -1, i64 -1, i64 -1, i64 -1, i64 -1, i64 -1, i64 -1, i64 -1, i64 -1, i64 -1, i64 -1, i64 -1, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0>, <64 x i64> zeroinitializer)
-; CHECK-NEXT:    [[TMP1:%.*]] = shufflevector <64 x i64> [[TMP0]], <64 x i64> poison, <4 x i32> <i32 0, i32 16, i32 32, i32 48>
-; CHECK-NEXT:    [[TMP2:%.*]] = call i64 @llvm.vector.reduce.smin.v4i64(<4 x i64> [[TMP1]])
-; CHECK-NEXT:    [[TMP3:%.*]] = insertelement <16 x i64> poison, i64 [[TMP2]], i64 0
-; CHECK-NEXT:    [[TMP4:%.*]] = shufflevector <64 x i64> [[TMP0]], <64 x i64> poison, <4 x i32> <i32 1, i32 17, i32 33, i32 49>
-; CHECK-NEXT:    [[TMP5:%.*]] = call i64 @llvm.vector.reduce.smin.v4i64(<4 x i64> [[TMP4]])
-; CHECK-NEXT:    [[TMP6:%.*]] = insertelement <16 x i64> [[TMP3]], i64 [[TMP5]], i64 1
-; CHECK-NEXT:    [[TMP7:%.*]] = shufflevector <64 x i64> [[TMP0]], <64 x i64> poison, <4 x i32> <i32 2, i32 18, i32 34, i32 50>
-; CHECK-NEXT:    [[TMP8:%.*]] = call i64 @llvm.vector.reduce.smin.v4i64(<4 x i64> [[TMP7]])
-; CHECK-NEXT:    [[TMP9:%.*]] = insertelement <16 x i64> [[TMP6]], i64 [[TMP8]], i64 2
-; CHECK-NEXT:    [[TMP10:%.*]] = shufflevector <64 x i64> [[TMP0]], <64 x i64> poison, <4 x i32> <i32 3, i32 19, i32 35, i32 51>
-; CHECK-NEXT:    [[TMP11:%.*]] = call i64 @llvm.vector.reduce.smin.v4i64(<4 x i64> [[TMP10]])
-; CHECK-NEXT:    [[TMP12:%.*]] = insertelement <16 x i64> [[TMP9]], i64 [[TMP11]], i64 3
-; CHECK-NEXT:    [[TMP13:%.*]] = shufflevector <64 x i64> [[TMP0]], <64 x i64> poison, <4 x i32> <i32 4, i32 20, i32 36, i32 52>
-; CHECK-NEXT:    [[TMP14:%.*]] = call i64 @llvm.vector.reduce.smin.v4i64(<4 x i64> [[TMP13]])
-; CHECK-NEXT:    [[TMP15:%.*]] = insertelement <16 x i64> [[TMP12]], i64 [[TMP14]], i64 4
-; CHECK-NEXT:    [[TMP16:%.*]] = shufflevector <64 x i64> [[TMP0]], <64 x i64> poison, <4 x i32> <i32 5, i32 21, i32 37, i32 53>
-; CHECK-NEXT:    [[TMP17:%.*]] = call i64 @llvm.vector.reduce.smin.v4i64(<4 x i64> [[TMP16]])
-; CHECK-NEXT:    [[TMP18:%.*]] = insertelement <16 x i64> [[TMP15]], i64 [[TMP17]], i64 5
-; CHECK-NEXT:    [[TMP19:%.*]] = shufflevector <64 x i64> [[TMP0]], <64 x i64> poison, <4 x i32> <i32 6, i32 22, i32 38, i32 54>
-; CHECK-NEXT:    [[TMP20:%.*]] = call i64 @llvm.vector.reduce.smin.v4i64(<4 x i64> [[TMP19]])
-; CHECK-NEXT:    [[TMP21:%.*]] = insertelement <16 x i64> [[TMP18]], i64 [[TMP20]], i64 6
-; CHECK-NEXT:    [[TMP22:%.*]] = shufflevector <64 x i64> [[TMP0]], <64 x i64> poison, <4 x i32> <i32 7, i32 23, i32 39, i32 55>
-; CHECK-NEXT:    [[TMP23:%.*]] = call i64 @llvm.vector.reduce.smin.v4i64(<4 x i64> [[TMP22]])
-; CHECK-NEXT:    [[TMP24:%.*]] = insertelement <16 x i64> [[TMP21]], i64 [[TMP23]], i64 7
-; CHECK-NEXT:    [[TMP25:%.*]] = shufflevector <64 x i64> [[TMP0]], <64 x i64> poison, <4 x i32> <i32 8, i32 24, i32 40, i32 56>
-; CHECK-NEXT:    [[TMP26:%.*]] = call i64 @llvm.vector.reduce.smin.v4i64(<4 x i64> [[TMP25]])
-; CHECK-NEXT:    [[TMP27:%.*]] = insertelement <16 x i64> [[TMP24]], i64 [[TMP26]], i64 8
-; CHECK-NEXT:    [[TMP28:%.*]] = shufflevector <64 x i64> [[TMP0]], <64 x i64> poison, <4 x i32> <i32 9, i32 25, i32 41, i32 57>
-; CHECK-NEXT:    [[TMP29:%.*]] = call i64 @llvm.vector.reduce.smin.v4i64(<4 x i64> [[TMP28]])
-; CHECK-NEXT:    [[TMP30:%.*]] = insertelement <16 x i64> [[TMP27]], i64 [[TMP29]], i64 9
-; CHECK-NEXT:    [[TMP31:%.*]] = shufflevector <64 x i64> [[TMP0]], <64 x i64> poison, <4 x i32> <i32 10, i32 26, i32 42, i32 58>
-; CHECK-NEXT:    [[TMP32:%.*]] = call i64 @llvm.vector.reduce.smin.v4i64(<4 x i64> [[TMP31]])
-; CHECK-NEXT:    [[TMP33:%.*]] = insertelement <16 x i64> [[TMP30]], i64 [[TMP32]], i64 10
-; CHECK-NEXT:    [[TMP34:%.*]] = shufflevector <64 x i64> [[TMP0]], <64 x i64> poison, <4 x i32> <i32 11, i32 27, i32 43, i32 59>
-; CHECK-NEXT:    [[TMP35:%.*]] = call i64 @llvm.vector.reduce.smin.v4i64(<4 x i64> [[TMP34]])
-; CHECK-NEXT:    [[TMP36:%.*]] = insertelement <16 x i64> [[TMP33]], i64 [[TMP35]], i64 11
-; CHECK-NEXT:    [[TMP37:%.*]] = shufflevector <64 x i64> [[TMP0]], <64 x i64> poison, <4 x i32> <i32 12, i32 28, i32 44, i32 60>
-; CHECK-NEXT:    [[TMP38:%.*]] = call i64 @llvm.vector.reduce.smin.v4i64(<4 x i64> [[TMP37]])
-; CHECK-NEXT:    [[TMP39:%.*]] = insertelement <16 x i64> [[TMP36]], i64 [[TMP38]], i64 12
-; CHECK-NEXT:    [[TMP40:%.*]] = shufflevector <64 x i64> [[TMP0]], <64 x i64> poison, <4 x i32> <i32 13, i32 29, i32 45, i32 61>
-; CHECK-NEXT:    [[TMP41:%.*]] = call i64 @llvm.vector.reduce.smin.v4i64(<4 x i64> [[TMP40]])
-; CHECK-NEXT:    [[TMP42:%.*]] = insertelement <16 x i64> [[TMP39]], i64 [[TMP41]], i64 13
-; CHECK-NEXT:    [[TMP43:%.*]] = shufflevector <64 x i64> [[TMP0]], <64 x i64> poison, <4 x i32> <i32 14, i32 30, i32 46, i32 62>
-; CHECK-NEXT:    [[TMP44:%.*]] = call i64 @llvm.vector.reduce.smin.v4i64(<4 x i64> [[TMP43]])
-; CHECK-NEXT:    [[TMP45:%.*]] = insertelement <16 x i64> [[TMP42]], i64 [[TMP44]], i64 14
-; CHECK-NEXT:    [[TMP46:%.*]] = shufflevector <64 x i64> [[TMP0]], <64 x i64> poison, <4 x i32> <i32 15, i32 31, i32 47, i32 63>
-; CHECK-NEXT:    [[TMP47:%.*]] = call i64 @llvm.vector.reduce.smin.v4i64(<4 x i64> [[TMP46]])
-; CHECK-NEXT:    [[TMP48:%.*]] = insertelement <16 x i64> [[TMP45]], i64 [[TMP47]], i64 15
+; CHECK-NEXT:    [[TMP0:%.*]] = zext <16 x i8> splat (i8 1) to <16 x i64>
+; CHECK-NEXT:    [[TMP1:%.*]] = sub <16 x i64> zeroinitializer, [[TMP0]]
+; CHECK-NEXT:    [[TMP2:%.*]] = zext <16 x i8> zeroinitializer to <16 x i64>
+; CHECK-NEXT:    [[TMP3:%.*]] = sub <16 x i64> zeroinitializer, [[TMP2]]
+; CHECK-NEXT:    [[TMP4:%.*]] = call <16 x i64> @llvm.smin.v16i64(<16 x i64> [[TMP1]], <16 x i64> [[TMP3]])
+; CHECK-NEXT:    [[TMP5:%.*]] = zext <16 x i8> zeroinitializer to <16 x i64>
+; CHECK-NEXT:    [[TMP6:%.*]] = sub <16 x i64> zeroinitializer, [[TMP5]]
+; CHECK-NEXT:    [[TMP7:%.*]] = call <16 x i64> @llvm.smin.v16i64(<16 x i64> [[TMP4]], <16 x i64> [[TMP6]])
+; CHECK-NEXT:    [[TMP8:%.*]] = zext <16 x i8> zeroinitializer to <16 x i64>
+; CHECK-NEXT:    [[TMP9:%.*]] = sub <16 x i64> zeroinitializer, [[TMP8]]
+; CHECK-NEXT:    [[TMP10:%.*]] = call <16 x i64> @llvm.smin.v16i64(<16 x i64> [[TMP7]], <16 x i64> [[TMP9]])
+; CHECK-NEXT:    [[TMP11:%.*]] = sub <16 x i64> zeroinitializer, zeroinitializer
+; CHECK-NEXT:    [[TMP12:%.*]] = call <16 x i64> @llvm.smin.v16i64(<16 x i64> [[TMP10]], <16 x i64> [[TMP11]])
+; CHECK-NEXT:    [[TMP13:%.*]] = sub <16 x i64> zeroinitializer, zeroinitializer
+; CHECK-NEXT:    [[TMP14:%.*]] = call <16 x i64> @llvm.smin.v16i64(<16 x i64> [[TMP12]], <16 x i64> [[TMP13]])
+; CHECK-NEXT:    [[TMP15:%.*]] = sub <16 x i64> zeroinitializer, zeroinitializer
+; CHECK-NEXT:    [[TMP16:%.*]] = call <16 x i64> @llvm.smin.v16i64(<16 x i64> [[TMP14]], <16 x i64> [[TMP15]])
+; CHECK-NEXT:    [[TMP17:%.*]] = sub <16 x i64> zeroinitializer, zeroinitializer
+; CHECK-NEXT:    [[TMP48:%.*]] = call <16 x i64> @llvm.smin.v16i64(<16 x i64> [[TMP16]], <16 x i64> [[TMP17]])
 ; CHECK-NEXT:    ret <16 x i64> [[TMP48]]
 ;
 entry:
diff --git a/llvm/test/Transforms/SLPVectorizer/NVPTX/v2f16.ll b/llvm/test/Transforms/SLPVectorizer/NVPTX/v2f16.ll
index 866b3170e98ea..3fafc07d65e8b 100644
--- a/llvm/test/Transforms/SLPVectorizer/NVPTX/v2f16.ll
+++ b/llvm/test/Transforms/SLPVectorizer/NVPTX/v2f16.ll
@@ -25,17 +25,17 @@ define void @fusion(ptr noalias nocapture align 256 dereferenceable(19267584) %a
 ; NOVECTOR-NEXT:    [[TMP4:%.*]] = zext i32 [[TMP3]] to i64
 ; NOVECTOR-NEXT:    [[TMP10:%.*]] = or disjoint i64 [[TMP4]], 1
 ; NOVECTOR-NEXT:    [[TMP5:%.*]] = getelementptr inbounds half, ptr [[ARG1:%.*]], i64 [[TMP4]]
+; NOVECTOR-NEXT:    [[TMP7:%.*]] = load half, ptr [[TMP5]], align 8
+; NOVECTOR-NEXT:    [[TMP8:%.*]] = fmul fast half [[TMP7]], 0xH5380
+; NOVECTOR-NEXT:    [[TMP9:%.*]] = fadd fast half [[TMP8]], 0xH57F0
 ; NOVECTOR-NEXT:    [[TMP6:%.*]] = getelementptr inbounds half, ptr [[ARG:%.*]], i64 [[TMP4]]
+; NOVECTOR-NEXT:    store half [[TMP9]], ptr [[TMP6]], align 8
 ; NOVECTOR-NEXT:    [[TMP11:%.*]] = getelementptr inbounds half, ptr [[ARG1]], i64 [[TMP10]]
 ; NOVECTOR-NEXT:    [[TMP12:%.*]] = load half, ptr [[TMP11]], align 2
-; NOVECTOR-NEXT:    [[TMP17:%.*]] = load half, ptr [[TMP5]], align 8
-; NOVECTOR-NEXT:    [[TMP13:%.*]] = fmul fast half [[TMP12]], 0xH5380
-; NOVECTOR-NEXT:    [[TMP18:%.*]] = fmul fast half [[TMP17]], 0xH5380
-; NOVECTOR-NEXT:    [[TMP14:%.*]] = fadd fast half [[TMP13]], 0xH57F0
+; NOVECTOR-NEXT:    [[TMP18:%.*]] = fmul fast half [[TMP12]], 0xH5380
 ; NOVECTOR-NEXT:    [[TMP19:%.*]] = fadd fast half [[TMP18]], 0xH57F0
-; NOVECTOR-NEXT:    [[TMP15:%.*]] = insertelement <2 x half> poison, half [[TMP19]], i32 0
-; NOVECTOR-NEXT:    [[TMP16:%.*]] = insertelement <2 x half> [[TMP15]], half [[TMP14]], i32 1
-; NOVECTOR-NEXT:    store <2 x half> [[TMP16]], ptr [[TMP6]], align 8
+; NOVECTOR-NEXT:    [[TMP15:%.*]] = getelementptr inbounds half, ptr [[ARG]], i64 [[TMP10]]
+; NOVECTOR-NEXT:    store half [[TMP19]], ptr [[TMP15]], align 2
 ; NOVECTOR-NEXT:    ret void
 ;
   %1 = shl nuw nsw i32 %arg2, 6
@@ -64,16 +64,15 @@ define ptx_kernel void @add_f16(ptr addrspace(1) %0, { half, half } %1, { half,
 ; VECTOR-NEXT:    [[TMP5:%.*]] = extractvalue { half, half } [[TMP1]], 1
 ; VECTOR-NEXT:    [[TMP6:%.*]] = extractvalue { half, half } [[TMP2:%.*]], 0
 ; VECTOR-NEXT:    [[TMP7:%.*]] = extractvalue { half, half } [[TMP2]], 1
-; VECTOR-NEXT:    [[TMP8:%.*]] = insertelement <2 x half> poison, half [[TMP4]], i32 0
-; VECTOR-NEXT:    [[TMP9:%.*]] = insertelement <2 x half> [[TMP8]], half [[TMP5]], i32 1
-; VECTOR-NEXT:    [[TMP10:%.*]] = insertelement <2 x half> poison, half [[TMP6]], i32 0
-; VECTOR-NEXT:    [[TMP11:%.*]] = insertelement <2 x half> [[TMP10]], half [[TMP7]], i32 1
-; VECTOR-NEXT:    [[TMP12:%.*]] = fadd <2 x half> [[TMP9]], [[TMP11]]
+; VECTOR-NEXT:    [[TMP8:%.*]] = fadd half [[TMP4]], [[TMP6]]
+; VECTOR-NEXT:    [[TMP9:%.*]] = fadd half [[TMP5]], [[TMP7]]
 ; VECTOR-NEXT:    [[TMP13:%.*]] = call i32 @llvm.nvvm.read.ptx.sreg.tid.x()
 ; VECTOR-NEXT:    [[TMP14:%.*]] = shl i32 [[TMP13]], 1
 ; VECTOR-NEXT:    [[TMP15:%.*]] = and i32 [[TMP14]], 62
 ; VECTOR-NEXT:    [[TMP16:%.*]] = zext nneg i32 [[TMP15]] to i64
 ; VECTOR-NEXT:    [[TMP17:%.*]] = getelementptr half, ptr addrspace(1) [[TMP0:%.*]], i64 [[TMP16]]
+; VECTOR-NEXT:    [[TMP18:%.*]] = insertelement <2 x half> poison, half [[TMP8]], i64 0
+; VECTOR-NEXT:    [[TMP12:%.*]] = insertelement <2 x half> [[TMP18]], half [[TMP9]], i64 1
 ; VECTOR-NEXT:    store <2 x half> [[TMP12]], ptr addrspace(1) [[TMP17]], align 4
 ; VECTOR-NEXT:    ret void
 ;
diff --git a/llvm/test/Transforms/SLPVectorizer/X86/parent-node-non-schedulable.ll b/llvm/test/Transforms/SLPVectorizer/X86/parent-node-non-schedulable.ll
index 2623366d2b91e..95199448c6485 100644
--- a/llvm/test/Transforms/SLPVectorizer/X86/parent-node-non-schedulable.ll
+++ b/llvm/test/Transforms/SLPVectorizer/X86/parent-node-non-schedulable.ll
@@ -4,81 +4,86 @@
 define void @test(ptr %0, i64 %1, i64 %2, i1 %3, i64 %4, i64 %5) {
 ; CHECK-LABEL: define void @test(
 ; CHECK-SAME: ptr [[TMP0:%.*]], i64 [[TMP1:%.*]], i64 [[TMP2:%.*]], i1 [[TMP3:%.*]], i64 [[TMP4:%.*]], i64 [[TMP5:%.*]]) #[[ATTR0:[0-9]+]] {
+; CHECK-NEXT:    [[TMP9:%.*]] = getelementptr i8, ptr [[TMP0]], i32 248
+; CHECK-NEXT:    [[TMP8:%.*]] = load i64, ptr [[TMP9]], align 4
 ; CHECK-NEXT:    [[TMP7:%.*]] = getelementptr i8, ptr [[TMP0]], i32 240
-; CHECK-NEXT:    [[TMP9:%.*]] = insertelement <4 x i64> poison, i64 [[TMP1]], i32 0
-; CHECK-NEXT:    [[TMP10:%.*]] = shufflevector <4 x i64> [[TMP9]], <4 x i64> poison, <4 x i32> zeroinitializer
-; CHECK-NEXT:    [[TMP11:%.*]] = insertelement <4 x i64> <i64 1, i64 1, i64 1, i64 poison>, i64 [[TMP2]], i32 3
-; CHECK-NEXT:    [[TMP12:%.*]] = add <4 x i64> [[TMP10]], [[TMP11]]
-; CHECK-NEXT:    [[TMP8:%.*]] = getelementptr i8, ptr [[TMP0]], i32 128
-; CHECK-NEXT:    [[TMP13:%.*]] = load <2 x i64>, ptr [[TMP7]], align 4
+; CHECK-NEXT:    [[TMP10:%.*]] = load i64, ptr [[TMP7]], align 4
 ; CHECK-NEXT:    [[TMP14:%.*]] = load i64, ptr null, align 4
-; CHECK-NEXT:    [[TMP15:%.*]] = load <2 x i64>, ptr [[TMP8]], align 4
-; CHECK-NEXT:    [[TMP16:%.*]] = shufflevector <2 x i64> [[TMP13]], <2 x i64> [[TMP15]], <6 x i32> <i32 0, i32 1, i32 poison, i32 3, i32 2, i32 2>
-; CHECK-NEXT:    [[TMP17:%.*]] = insertelement <6 x i64> poison, i64 [[TMP14]], i32 0
-; CHECK-NEXT:    [[TMP18:%.*]] = shufflevector <6 x i64> [[TMP17]], <6 x i64> poison, <6 x i32> <i32 poison, i32 poison, i32 0, i32 poison, i32 poison, i32 poison>
-; CHECK-NEXT:    [[TMP19:%.*]] = shufflevector <6 x i64> [[TMP16]], <6 x i64> [[TMP18]], <6 x i32> <i32 0, i32 1, i32 8, i32 3, i32 4, i32 5>
-; CHECK-NEXT:    [[TMP20:%.*]] = shufflevector <4 x i64> [[TMP10]], <4 x i64> poison, <6 x i32> <i32 0, i32 1, i32 2, i32 3, i32 poison, i32 0>
-; CHECK-NEXT:    [[TMP21:%.*]] = shufflevector <6 x i64> [[TMP20]], <6 x i64> <i64 0, i64 0, i64 0, i64 0, i64 0, i64 poison>, <6 x i32> <i32 6, i32 7, i32 8, i32 9, i32 10, i32 0>
-; CHECK-NEXT:    [[TMP22:%.*]] = add <6 x i64> [[TMP19]], [[TMP21]]
-; CHECK-NEXT:    [[TMP23:%.*]] = shufflevector <2 x i64> [[TMP13]], <2 x i64> poison, <4 x i32> <i32 0, i32 1, i32 0, i32 1>
-; CHECK-NEXT:    [[TMP24:%.*]] = shufflevector <4 x i64> [[TMP10]], <4 x i64> [[TMP23]], <4 x i32> <i32 0, i32 1, i32 4, i32 5>
-; CHECK-NEXT:    [[TMP25:%.*]] = sub <4 x i64> zeroinitializer, [[TMP24]]
-; CHECK-NEXT:    [[TMP26:%.*]] = sub <6 x i64> zeroinitializer, [[TMP22]]
-; CHECK-NEXT:    [[TMP27:%.*]] = shufflevector <6 x i64> [[TMP19]], <6 x i64> poison, <2 x i32> <i32 2, i32 2>
-; CHECK-NEXT:    [[TMP28:%.*]] = add <2 x i64> [[TMP27]], splat (i64 1)
-; CHECK-NEXT:    [[TMP29:%.*]] = ashr <2 x i64> [[TMP28]], splat (i64 14)
-; CHECK-NEXT:    [[TMP30:%.*]] = shufflevector <6 x i64> [[TMP26]], <6 x i64> poison, <14 x i32> <i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 poison, i32 poison>
-; CHECK-NEXT:    [[TMP31:%.*]] = shufflevector <4 x i64> [[TMP12]], <4 x i64> poison, <14 x i32> <i32 0, i32 1, i32 2, i32 3, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison>
-; CHECK-NEXT:    [[TMP32:%.*]] = shufflevector <14 x i64> [[TMP30]], <14 x i64> [[TMP31]], <14 x i32> <i32 14, i32 15, i32 16, i32 17, i32 poison, i32 poison, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 poison, i32 poison>
-; CHECK-NEXT:    [[TMP33:%.*]] = shufflevector <4 x i64> [[TMP25]], <4 x i64> poison, <14 x i32> <i32 0, i32 1, i32 2, i32 3, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison>
-; CHECK-NEXT:    [[TMP34:%.*]] = shufflevector <14 x i64> [[TMP32]], <14 x i64> [[TMP33]], <14 x i32> <i32 0, i32 1, i32 2, i32 3, i32 14, i32 15, i32 16, i32 17, i32 8, i32 9, i32 10, i32 11, i32 poison, i32 poison>
-; CHECK-NEXT:    [[TMP35:%.*]] = shufflevector <2 x i64> [[TMP29]], <2 x i64> poison, <14 x i32> <i32 0, i32 1, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison>
-; CHECK-NEXT:    [[TMP36:%.*]] = shufflevector <14 x i64> [[TMP34]], <14 x i64> [[TMP35]], <14 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 14, i32 15>
+; CHECK-NEXT:    [[TMP12:%.*]] = add i64 [[TMP1]], 1
+; CHECK-NEXT:    [[TMP13:%.*]] = add i64 [[TMP1]], 1
+; CHECK-NEXT:    [[TMP33:%.*]] = add i64 [[TMP1]], [[TMP2]]
+; CHECK-NEXT:    [[TMP15:%.*]] = getelementptr i8, ptr [[TMP0]], i32 136
+; CHECK-NEXT:    [[TMP16:%.*]] = load i64, ptr [[TMP15]], align 4
+; CHECK-NEXT:    [[TMP17:%.*]] = getelementptr i8, ptr [[TMP0]], i32 128
+; CHECK-NEXT:    [[TMP18:%.*]] = load i64, ptr [[TMP17]], align 4
+; CHECK-NEXT:    [[TMP19:%.*]] = add i64 [[TMP18]], [[TMP1]]
+; CHECK-NEXT:    [[TMP20:%.*]] = sub i64 0, [[TMP18]]
+; CHECK-NEXT:    [[TMP21:%.*]] = sub i64 0, [[TMP16]]
+; CHECK-NEXT:    [[TMP22:%.*]] = sub i64 0, [[TMP14]]
+; CHECK-NEXT:    [[TMP23:%.*]] = add i64 [[TMP1]], 1
+; CHECK-NEXT:    [[TMP24:%.*]] = sub i64 0, [[TMP1]]
+; CHECK-NEXT:    [[TMP25:%.*]] = sub i64 0, [[TMP1]]
+; CHECK-NEXT:    [[TMP26:%.*]] = sub i64 0, [[TMP10]]
+; CHECK-NEXT:    [[TMP27:%.*]] = sub i64 0, [[TMP8]]
+; CHECK-NEXT:    [[TMP28:%.*]] = sub i64 0, [[TMP19]]
+; CHECK-NEXT:    [[TMP29:%.*]] = add i64 [[TMP14]], 1
+; CHECK-NEXT:    [[TMP30:%.*]] = ashr i64 [[TMP29]], 14
+; CHECK-NEXT:    [[TMP31:%.*]] = add i64 [[TMP14]], 1
+; CHECK-NEXT:    [[TMP32:%.*]] = ashr i64 [[TMP31]], 14
 ; CHECK-NEXT:    br i1 [[TMP3]], label %[[BB52:.*]], label %[[BB37:.*]]
 ; CHECK:       [[BB37]]:
-; CHECK-NEXT:    [[TMP38:%.*]] = add <4 x i64> [[TMP10]], splat (i64 1)
-; CHECK-NEXT:    [[TMP39:%.*]] = shufflevector <4 x i64> [[TMP10]], <4 x i64> poison, <2 x i32> zeroinitializer
-; CHECK-NEXT:    [[TMP40:%.*]] = add <2 x i64> [[TMP39]], splat (i64 1)
-; CHECK-NEXT:    [[TMP41:%.*]] = lshr <2 x i64> [[TMP39]], splat (i64 1)
-; CHECK-NEXT:    [[TMP42:%.*]] = add <2 x i64> [[TMP40]], [[TMP41]]
-; CHECK-NEXT:    [[TMP43:%.*]] = shufflevector <4 x i64> [[TMP10]], <4 x i64> [[TMP11]], <10 x i32> <i32 0, i32 7, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison>
-; CHECK-NEXT:    [[TMP44:%.*]] = insertelement <10 x i64> [[TMP43]], i64 [[TMP4]], i32 6
-; CHECK-NEXT:    [[TMP45:%.*]] = insertelement <10 x i64> [[TMP44]], i64 [[TMP5]], i32 7
-; CHECK-NEXT:    [[TMP46:%.*]] = shufflevector <4 x i64> [[TMP38]], <4 x i64> poison, <10 x i32> <i32 poison, i32 poison, i32 poison, i32 poison, i32 0, i32 1, i32 2, i32 3, i32 poison, i32 poison>
-; CHECK-NEXT:    [[TMP47:%.*]] = shufflevector <2 x i64> [[TMP42]], <2 x i64> poison, <10 x i32> <i32 0, i32 1, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison>
-; CHECK-NEXT:    [[TMP48:%.*]] = shufflevector <10 x i64> [[TMP46]], <10 x i64> [[TMP47]], <10 x i32> <i32 poison, i32 poison, i32 poison, i32 poison, i32 4, i32 5, i32 6, i32 7, i32 10, i32 11>
-; CHECK-NEXT:    [[TMP49:%.*]] = shufflevector <10 x i64> [[TMP48]], <10 x i64> [[TMP45]], <10 x i32> <i32 10, i32 11, i32 4, i32 5, i32 6, i32 7, i32 16, i32 17, i32 8, i32 9>
-; CHECK-NEXT:    [[TMP50:%.*]] = shufflevector <10 x i64> [[TMP49]], <10 x i64> poison, <14 x i32> <i32 0, i32 1, i32 0, i32 2, i32 0, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 0, i32 0>
-; CHECK-NEXT:    [[TMP51:%.*]] = ashr <14 x i64> [[TMP50]], splat (i64 2)
+; CHECK-NEXT:    [[TMP34:%.*]] = ashr i64 [[TMP2]], 2
+; CHECK-NEXT:    [[TMP35:%.*]] = ashr i64 [[TMP1]], 2
+; CHECK-NEXT:    [[TMP36:%.*]] = add i64 [[TMP1]], 1
+; CHECK-NEXT:    [[TMP37:%.*]] = ashr i64 [[TMP36]], 2
+; CHECK-NEXT:    [[TMP38:%.*]] = add i64 [[TMP1]], 1
+; CHECK-NEXT:    [[TMP39:%.*]] = lshr i64 [[TMP1]], 1
+; CHECK-NEXT:    [[TMP40:%.*]] = add i64 [[TMP38]], [[TMP39]]
+; CHECK-NEXT:    [[TMP41:%.*]] = ashr i64 [[TMP40]], 2
+; CHECK-NEXT:    [[TMP42:%.*]] = add i64 [[TMP1]], 1
+; CHECK-NEXT:    [[TMP43:%.*]] = lshr i64 [[TMP1]], 1
+; CHECK-NEXT:    [[TMP44:%.*]] = add i64 [[TMP42]], [[TMP43]]
+; CHECK-NEXT:    [[TMP45:%.*]] = ashr i64 [[TMP44]], 2
+; CHECK-NEXT:    [[TMP46:%.*]] = ashr i64 [[TMP5]], 2
+; CHECK-NEXT:    [[TMP47:%.*]] = ashr i64 [[TMP4]], 2
+; CHECK-NEXT:    [[TMP48:%.*]] = ashr i64 [[TMP1]], 2
+; CHECK-NEXT:    [[TMP49:%.*]] = ashr i64 [[TMP1]], 2
+; CHECK-NEXT:    [[TMP50:%.*]] = ashr i64 [[TMP1]], 2
+; CHECK-NEXT:    [[TMP51:%.*]] = ashr i64 [[TMP1]], 2
+; CHECK-NEXT:    [[TMP52:%.*]] = add i64 [[TMP1]], 1
+; CHECK-NEXT:    [[TMP53:%.*]] = ashr i64 [[TMP52]], 2
+; CHECK-NEXT:    [[TMP78:%.*]] = add i64 [[TMP1]], 1
+; CHECK-NEXT:    [[TMP79:%.*]] = ashr i64 [[TMP78]], 2
+; CHECK-NEXT:    [[TMP80:%.*]] = add i64 [[TMP1]], 1
+; CHECK-NEXT:    [[TMP81:%.*]] = ashr i64 [[TMP80]], 2
 ; CHECK-NEXT:    br label %[[BB52]]
 ; CHECK:       [[BB52]]:
-; CHECK-NEXT:    [[TMP53:%.*]] = phi <14 x i64> [ [[TMP51]], %[[BB37]] ], [ [[TMP36]], [[TMP6:%.*]] ]
-; CHECK-NEXT:    [[TMP54:%.*]] = extractelement <14 x i64> [[TMP53]], i32 0
-; CHECK-NEXT:    [[TMP55:%.*]] = extractelement <14 x i64> [[TMP53]], i32 13
+; CHECK-NEXT:    [[TMP57:%.*]] = phi i64 [ [[TMP51]], %[[BB37]] ], [ [[TMP24]], [[TMP6:%.*]] ]
+; CHECK-NEXT:    [[TMP58:%.*]] = phi i64 [ [[TMP50]], %[[BB37]] ], [ [[TMP32]], [[TMP6]] ]
+; CHECK-NEXT:    [[TMP64:%.*]] = phi i64 [ [[TMP53]], %[[BB37]] ], [ [[TMP25]], [[TMP6]] ]
+; CHECK-NEXT:    [[TMP71:%.*]] = phi i64 [ [[TMP79]], %[[BB37]] ], [ [[TMP26]], [[TMP6]] ]
+; CHECK-NEXT:    [[TMP77:%.*]] = phi i64 [ [[TMP81]], %[[BB37]] ], [ [[TMP27]], [[TMP6]] ]
+; CHECK-NEXT:    [[TMP55:%.*]] = phi i64 [ [[TMP49]], %[[BB37]] ], [ [[TMP30]], [[TMP6]] ]
+; CHECK-NEXT:    [[TMP54:%.*]] = phi i64 [ [[TMP48]], %[[BB37]] ], [ [[TMP23]], [[TMP6]] ]
+; CHECK-NEXT:    [[TMP65:%.*]] = phi i64 [ [[TMP47]], %[[BB37]] ], [ [[TMP22]], [[TMP6]] ]
+; CHECK-NEXT:    [[TMP69:%.*]] = phi i64 [ [[TMP46]], %[[BB37]] ], [ [[TMP21]], [[TMP6]] ]
+; CHECK-NEXT:    [[TMP74:%.*]] = phi i64 [ [[TMP45]], %[[BB37]] ], [ [[TMP20]], [[TMP6]] ]
+; CHECK-NEXT:    [[TMP76:%.*]] = phi i64 [ [[TMP41]], %[[BB37]] ], [ [[TMP28]], [[TMP6]] ]
+; CHECK-NEXT:    [[TMP60:%.*]] = phi i64 [ [[TMP34]], %[[BB37]] ], [ [[TMP12]], [[TMP6]] ]
+; CHECK-NEXT:    [[TMP61:%.*]] = phi i64 [ [[TMP35]], %[[BB37]] ], [ [[TMP13]], [[TMP6]] ]
+; CHECK-NEXT:    [[TMP67:%.*]] = phi i64 [ [[TMP37]], %[[BB37]] ], [ [[TMP33]], [[TMP6]] ]
 ; CHECK-NEXT:    [[TMP56:%.*]] = or i64 [[TMP54]], [[TMP55]]
-; CHECK-NEXT:    [[TMP57:%.*]] = extractelement <14 x i64> [[TMP53]], i32 4
-; CHECK-NEXT:    [[TMP58:%.*]] = extractelement <14 x i64> [[TMP53]], i32 12
 ; CHECK-NEXT:    [[TMP59:%.*]] = or i64 [[TMP57]], [[TMP58]]
-; CHECK-NEXT:    [[TMP60:%.*]] = extractelement <14 x i64> [[TMP53]], i32 1
-; CHECK-NEXT:    [[TMP61:%.*]] = extractelement <14 x i64> [[TMP53]], i32 2
 ; CHECK-NEXT:    [[TMP62:%.*]] = or i64 [[TMP60]], [[TMP61]]
 ; CHECK-NEXT:    [[TMP63:%.*]] = or i64 [[TMP59]], [[TMP56]]
-; CHECK-NEXT:    [[TMP64:%.*]] = extractelement <14 x i64> [[TMP53]], i32 5
-; CHECK-NEXT:    [[TMP65:%.*]] = extractelement <14 x i64> [[TMP53]], i32 8
 ; CHECK-NEXT:    [[TMP66:%.*]] = or i64 [[TMP64]], [[TMP65]]
-; CHECK-NEXT:    [[TMP67:%.*]] = extractelement <14 x i64> [[TMP53]], i32 3
 ; CHECK-NEXT:    [[TMP68:%.*]] = or i64 [[TMP67]], [[TMP62]]
-; CHECK-NEXT:    [[TMP69:%.*]] = extractelement <14 x i64> [[TMP53]], i32 9
 ; CHECK-NEXT:    [[TMP70:%.*]] = or i64 [[TMP69]], [[TMP66]]
-; CHECK-NEXT:    [[TMP71:%.*]] = extractelement <14 x i64> [[TMP53]], i32 6
 ; CHECK-NEXT:    [[TMP72:%.*]] = or i64 [[TMP71]], [[TMP70]]
 ; CHECK-NEXT:    [[TMP73:%.*]] = or i64 [[TMP63]], [[TMP72]]
-; CHECK-NEXT:    [[TMP74:%.*]] = extractelement <14 x i64> [[TMP53]], i32 10
 ; CHECK-NEXT:    [[TMP75:%.*]] = or i64 [[TMP74]], [[TMP73]]
 ; CHECK-NEXT:    store i64 [[TMP68]], ptr [[TMP0]], align 4
-; CHECK-NEXT:    [[TMP76:%.*]] = extractelement <14 x i64> [[TMP53]], i32 11
 ; CHECK-NEXT:    store i64 [[TMP76]], ptr null, align 4
-; CHECK-NEXT:    [[TMP77:%.*]] = extractelement <14 x i64> [[TMP53]], i32 7
 ; CHECK-NEXT:    store i64 [[TMP77]], ptr [[TMP0]], align 4
 ; CHECK-NEXT:    store i64 [[TMP75]], ptr null, align 4
 ; CHECK-NEXT:    ret void

>From b2da42a3f9e2ce92583b3643fd237c0e1fbbe9d9 Mon Sep 17 00:00:00 2001
From: Alexey Bataev <a.bataev at outlook.com>
Date: Fri, 20 Mar 2026 04:58:11 -0700
Subject: [PATCH 2/2] Oulined, fix PHIs and split vector nodes

Created using spr 1.3.7
---
 .../Transforms/Vectorize/SLPVectorizer.cpp    | 160 +++++++++++++-----
 .../SLPVectorizer/AArch64/revec-reductions.ll |  68 +++++---
 2 files changed, 169 insertions(+), 59 deletions(-)

diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index 887109fab85d8..693776a717c9b 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -3800,6 +3800,13 @@ class slpvectorizer::BoUpSLP {
                                ArrayRef<Value *> VectorizedVals,
                                SmallPtrSetImpl<Value *> &CheckedExtracts);
 
+  /// Estimates spill/reload cost from vector register pressure for \p E at the
+  /// point of emitting its vector result type \p FinalVecTy.
+  InstructionCost getVectorSpillReloadCost(const TreeEntry *E,
+                                           VectorType *VecTy,
+                                           VectorType *FinalVecTy,
+                                           TTI::TargetCostKind CostKind) const;
+
   /// This is the recursive part of buildTree.
   void buildTreeRec(ArrayRef<Value *> Roots, unsigned Depth, const EdgeInfo &EI,
                     unsigned InterleaveFactor = 0);
@@ -15258,6 +15265,114 @@ unsigned BoUpSLP::getScaleToLoopIterations(const TreeEntry &TE, Value *Scalar,
   return 1;
 }
 
+InstructionCost
+BoUpSLP::getVectorSpillReloadCost(const TreeEntry *E, VectorType *VecTy,
+                                  VectorType *FinalVecTy,
+                                  TTI::TargetCostKind CostKind) const {
+  InstructionCost SpillsReloads = 0;
+  ArrayRef<Value *> VL = E->Scalars;
+  // Estimate vector register pressure per target register class: operand
+  // vectors plus the result. The same vector operand is counted once: by
+  // shared TreeEntry (graph edge or getSameValuesTreeEntry), or by identical
+  // external scalar bundles across operand indices. PHIs take the max pressure
+  // across incoming operand slots (only one predecessor is live at a time).
+  // All-constant operand bundles are skipped.
+  if (!E->hasState() || E->getOpcode() == Instruction::Store ||
+      E->getOpcode() == Instruction::ExtractElement ||
+      E->getOpcode() == Instruction::ExtractValue ||
+      E->getOpcode() == Instruction::Freeze ||
+      (E->getOpcode() == Instruction::Load &&
+       E->State != TreeEntry::ScatterVectorize))
+    return SpillsReloads;
+
+  SmallDenseMap<unsigned, unsigned> PressureByClass;
+  const bool IsPHI =
+      E->State == TreeEntry::Vectorize && E->getOpcode() == Instruction::PHI;
+  SmallPtrSet<const TreeEntry *, 8> CountedOpEntries;
+
+  auto AddPartsToClass = [&](unsigned RegClass, unsigned Parts) {
+    if (Parts == 0)
+      return;
+    PressureByClass[RegClass] += Parts;
+  };
+
+  if (E->State == TreeEntry::SplitVectorize) {
+    for (const auto [Idx, _] : E->CombinedEntriesWithIndices) {
+      const TreeEntry *OpTE = VectorizableTree[Idx].get();
+
+      if (!CountedOpEntries.insert(OpTE).second)
+        continue;
+      auto *OpVecTy = getWidenedType(OpTE->Scalars.front()->getType(),
+                                     OpTE->getVectorFactor());
+      const unsigned Parts = ::getNumberOfParts(*TTI, OpVecTy);
+      if (Parts == 0)
+        continue;
+      const unsigned RC =
+          TTI->getRegisterClassForType(/*Vector=*/true, OpVecTy);
+      AddPartsToClass(RC, Parts);
+    }
+  } else if (IsPHI) {
+    const unsigned Parts = ::getNumberOfParts(*TTI, VecTy);
+    if (Parts != 0) {
+      const unsigned RC = TTI->getRegisterClassForType(/*Vector=*/true, VecTy);
+      AddPartsToClass(RC, Parts);
+    }
+  } else {
+    for (unsigned Idx : seq<unsigned>(
+             E->getOpcode() == Instruction::Store ? 1 : E->getNumOperands())) {
+      if (E->getOpcode() == Instruction::InsertElement && Idx == 0)
+        continue;
+      ArrayRef<Value *> Ops = E->getOperand(Idx);
+      if (Ops.empty() || allConstant(Ops))
+        continue;
+      Value *Op = Ops.front();
+      if (!Op)
+        continue;
+      const TreeEntry *OpTE = getOperandEntry(E, Idx);
+
+      if (!CountedOpEntries.insert(OpTE).second)
+        continue;
+      auto *OpVecTy = getWidenedType(Op->getType(), Ops.size());
+      const unsigned Parts = ::getNumberOfParts(*TTI, OpVecTy);
+      if (Parts == 0)
+        continue;
+      const unsigned RC =
+          TTI->getRegisterClassForType(/*Vector=*/true, OpVecTy);
+      AddPartsToClass(RC, Parts);
+    }
+  }
+
+  const unsigned ResParts = ::getNumberOfParts(*TTI, VecTy);
+  if (ResParts > 0) {
+    const unsigned RC = TTI->getRegisterClassForType(/*Vector=*/true, VecTy);
+    AddPartsToClass(RC, ResParts);
+  }
+  if (VecTy != FinalVecTy) {
+    const unsigned FinalResParts = ::getNumberOfParts(*TTI, FinalVecTy);
+    if (FinalResParts > 0) {
+      const unsigned RC =
+          TTI->getRegisterClassForType(/*Vector=*/true, FinalVecTy);
+      AddPartsToClass(RC, FinalResParts);
+    }
+  }
+
+  for (auto [RegClass, UsedRegs] : PressureByClass) {
+    const unsigned NumAvailRegs = TTI->getNumberOfRegisters(RegClass);
+    if (NumAvailRegs == 0 || UsedRegs <= NumAvailRegs)
+      continue;
+    const unsigned SpillCount = UsedRegs - NumAvailRegs;
+    InstructionCost SingleRegSpillReload =
+        TTI->getRegisterClassReloadCost(RegClass, CostKind);
+    // No need to spill for reduction and non-returning instructions, like
+    // stores.
+    if (E->Idx > 0 || !UserIgnoreList || VL[0]->getType()->isVoidTy())
+      SingleRegSpillReload +=
+          TTI->getRegisterClassSpillCost(RegClass, CostKind);
+    SpillsReloads += SingleRegSpillReload * SpillCount;
+  }
+  return SpillsReloads;
+}
+
 InstructionCost
 BoUpSLP::getEntryCost(const TreeEntry *E, ArrayRef<Value *> VectorizedVals,
                       SmallPtrSetImpl<Value *> &CheckedExtracts) {
@@ -15285,43 +15400,8 @@ BoUpSLP::getEntryCost(const TreeEntry *E, ArrayRef<Value *> VectorizedVals,
   unsigned EntryVF = E->getVectorFactor();
   auto *FinalVecTy = getWidenedType(ScalarTy, EntryVF);
 
-  InstructionCost SpillsReloads = 0;
-  // Used regs by this node + its operands.
-  unsigned NumUsedRegs = 0;
-  if (E->hasState() && E->getOpcode() != Instruction::Store &&
-      E->getOpcode() != Instruction::InsertElement &&
-      E->getOpcode() != Instruction::ExtractElement &&
-      E->getOpcode() != Instruction::ExtractValue &&
-      E->getOpcode() != Instruction::Freeze &&
-      (E->getOpcode() != Instruction::Load ||
-       E->State == TreeEntry::ScatterVectorize)) {
-    for (unsigned Idx : seq<unsigned>(E->getNumOperands())) {
-      ArrayRef<Value *> Ops = E->getOperand(Idx);
-      if (Ops.empty())
-        continue;
-      Value *Op = Ops.front();
-      if (!Op)
-        continue;
-      auto *OpVecTy = getWidenedType(Op->getType(), Ops.size());
-      NumUsedRegs += ::getNumberOfParts(*TTI, OpVecTy);
-    }
-  }
-  const unsigned RegClass =
-      TTI->getRegisterClassForType(/*Vector=*/true, FinalVecTy);
-  const unsigned NumAvailRegs = TTI->getNumberOfRegisters(RegClass);
-  // Used all the registers - definitely need spill/reload, so include the
-  // cost.
-  if (NumUsedRegs > NumAvailRegs) {
-    InstructionCost SingleRegSpillReload =
-        TTI->getRegisterClassReloadCost(RegClass, CostKind);
-    // No need to spill for reduction and non-returning instructions, like
-    // stores.
-    if (E->Idx > 0 || !UserIgnoreList || VL[0]->getType()->isVoidTy())
-      SingleRegSpillReload +=
-          TTI->getRegisterClassSpillCost(RegClass, CostKind);
-    SpillsReloads =
-        SingleRegSpillReload * (NumUsedRegs / NumAvailRegs) * NumAvailRegs;
-  }
+  const InstructionCost SpillsReloads =
+      getVectorSpillReloadCost(E, VecTy, FinalVecTy, CostKind);
   if (E->isGather() || TransformedToGatherNodes.contains(E)) {
     if (allConstant(VL))
       return 0;
@@ -15492,7 +15572,7 @@ BoUpSLP::getEntryCost(const TreeEntry *E, ArrayRef<Value *> VectorizedVals,
     LLVM_DEBUG(dumpTreeCosts(E, 0, VecCost, ScalarCost,
                              "Calculated GEPs cost for Tree"));
 
-    return VecCost - ScalarCost;
+    return VecCost - ScalarCost + SpillsReloads;
   };
 
   auto GetMinMaxCost = [&](Type *Ty, Instruction *VI = nullptr) {
@@ -15550,7 +15630,7 @@ BoUpSLP::getEntryCost(const TreeEntry *E, ArrayRef<Value *> VectorizedVals,
                                           OpTE->Scalars.size());
     }
 
-    return CommonCost - ScalarCost;
+    return CommonCost - ScalarCost + SpillsReloads;
   }
   case Instruction::ExtractValue:
   case Instruction::ExtractElement: {
@@ -15710,7 +15790,7 @@ BoUpSLP::getEntryCost(const TreeEntry *E, ArrayRef<Value *> VectorizedVals,
             ::getShuffleCost(*TTI, TTI::SK_PermuteTwoSrc, InsertVecTy, Mask);
       }
     }
-    return Cost;
+    return Cost + SpillsReloads;
   }
   case Instruction::ZExt:
   case Instruction::SExt:
diff --git a/llvm/test/Transforms/SLPVectorizer/AArch64/revec-reductions.ll b/llvm/test/Transforms/SLPVectorizer/AArch64/revec-reductions.ll
index 4f0e38ebf34bd..92701dadbfc1b 100644
--- a/llvm/test/Transforms/SLPVectorizer/AArch64/revec-reductions.ll
+++ b/llvm/test/Transforms/SLPVectorizer/AArch64/revec-reductions.ll
@@ -4,25 +4,55 @@
 define <16 x i64> @test() {
 ; CHECK-LABEL: define <16 x i64> @test() {
 ; CHECK-NEXT:  [[ENTRY:.*:]]
-; CHECK-NEXT:    [[TMP0:%.*]] = zext <16 x i8> splat (i8 1) to <16 x i64>
-; CHECK-NEXT:    [[TMP1:%.*]] = sub <16 x i64> zeroinitializer, [[TMP0]]
-; CHECK-NEXT:    [[TMP2:%.*]] = zext <16 x i8> zeroinitializer to <16 x i64>
-; CHECK-NEXT:    [[TMP3:%.*]] = sub <16 x i64> zeroinitializer, [[TMP2]]
-; CHECK-NEXT:    [[TMP4:%.*]] = call <16 x i64> @llvm.smin.v16i64(<16 x i64> [[TMP1]], <16 x i64> [[TMP3]])
-; CHECK-NEXT:    [[TMP5:%.*]] = zext <16 x i8> zeroinitializer to <16 x i64>
-; CHECK-NEXT:    [[TMP6:%.*]] = sub <16 x i64> zeroinitializer, [[TMP5]]
-; CHECK-NEXT:    [[TMP7:%.*]] = call <16 x i64> @llvm.smin.v16i64(<16 x i64> [[TMP4]], <16 x i64> [[TMP6]])
-; CHECK-NEXT:    [[TMP8:%.*]] = zext <16 x i8> zeroinitializer to <16 x i64>
-; CHECK-NEXT:    [[TMP9:%.*]] = sub <16 x i64> zeroinitializer, [[TMP8]]
-; CHECK-NEXT:    [[TMP10:%.*]] = call <16 x i64> @llvm.smin.v16i64(<16 x i64> [[TMP7]], <16 x i64> [[TMP9]])
-; CHECK-NEXT:    [[TMP11:%.*]] = sub <16 x i64> zeroinitializer, zeroinitializer
-; CHECK-NEXT:    [[TMP12:%.*]] = call <16 x i64> @llvm.smin.v16i64(<16 x i64> [[TMP10]], <16 x i64> [[TMP11]])
-; CHECK-NEXT:    [[TMP13:%.*]] = sub <16 x i64> zeroinitializer, zeroinitializer
-; CHECK-NEXT:    [[TMP14:%.*]] = call <16 x i64> @llvm.smin.v16i64(<16 x i64> [[TMP12]], <16 x i64> [[TMP13]])
-; CHECK-NEXT:    [[TMP15:%.*]] = sub <16 x i64> zeroinitializer, zeroinitializer
-; CHECK-NEXT:    [[TMP16:%.*]] = call <16 x i64> @llvm.smin.v16i64(<16 x i64> [[TMP14]], <16 x i64> [[TMP15]])
-; CHECK-NEXT:    [[TMP17:%.*]] = sub <16 x i64> zeroinitializer, zeroinitializer
-; CHECK-NEXT:    [[TMP48:%.*]] = call <16 x i64> @llvm.smin.v16i64(<16 x i64> [[TMP16]], <16 x i64> [[TMP17]])
+; CHECK-NEXT:    [[TMP0:%.*]] = call <64 x i64> @llvm.smin.v64i64(<64 x i64> <i64 -1, i64 -1, i64 -1, i64 -1, i64 -1, i64 -1, i64 -1, i64 -1, i64 -1, i64 -1, i64 -1, i64 -1, i64 -1, i64 -1, i64 -1, i64 -1, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0>, <64 x i64> zeroinitializer)
+; CHECK-NEXT:    [[TMP1:%.*]] = shufflevector <64 x i64> [[TMP0]], <64 x i64> poison, <4 x i32> <i32 0, i32 16, i32 32, i32 48>
+; CHECK-NEXT:    [[TMP2:%.*]] = call i64 @llvm.vector.reduce.smin.v4i64(<4 x i64> [[TMP1]])
+; CHECK-NEXT:    [[TMP3:%.*]] = insertelement <16 x i64> poison, i64 [[TMP2]], i64 0
+; CHECK-NEXT:    [[TMP4:%.*]] = shufflevector <64 x i64> [[TMP0]], <64 x i64> poison, <4 x i32> <i32 1, i32 17, i32 33, i32 49>
+; CHECK-NEXT:    [[TMP5:%.*]] = call i64 @llvm.vector.reduce.smin.v4i64(<4 x i64> [[TMP4]])
+; CHECK-NEXT:    [[TMP6:%.*]] = insertelement <16 x i64> [[TMP3]], i64 [[TMP5]], i64 1
+; CHECK-NEXT:    [[TMP7:%.*]] = shufflevector <64 x i64> [[TMP0]], <64 x i64> poison, <4 x i32> <i32 2, i32 18, i32 34, i32 50>
+; CHECK-NEXT:    [[TMP8:%.*]] = call i64 @llvm.vector.reduce.smin.v4i64(<4 x i64> [[TMP7]])
+; CHECK-NEXT:    [[TMP9:%.*]] = insertelement <16 x i64> [[TMP6]], i64 [[TMP8]], i64 2
+; CHECK-NEXT:    [[TMP10:%.*]] = shufflevector <64 x i64> [[TMP0]], <64 x i64> poison, <4 x i32> <i32 3, i32 19, i32 35, i32 51>
+; CHECK-NEXT:    [[TMP11:%.*]] = call i64 @llvm.vector.reduce.smin.v4i64(<4 x i64> [[TMP10]])
+; CHECK-NEXT:    [[TMP12:%.*]] = insertelement <16 x i64> [[TMP9]], i64 [[TMP11]], i64 3
+; CHECK-NEXT:    [[TMP13:%.*]] = shufflevector <64 x i64> [[TMP0]], <64 x i64> poison, <4 x i32> <i32 4, i32 20, i32 36, i32 52>
+; CHECK-NEXT:    [[TMP14:%.*]] = call i64 @llvm.vector.reduce.smin.v4i64(<4 x i64> [[TMP13]])
+; CHECK-NEXT:    [[TMP15:%.*]] = insertelement <16 x i64> [[TMP12]], i64 [[TMP14]], i64 4
+; CHECK-NEXT:    [[TMP16:%.*]] = shufflevector <64 x i64> [[TMP0]], <64 x i64> poison, <4 x i32> <i32 5, i32 21, i32 37, i32 53>
+; CHECK-NEXT:    [[TMP17:%.*]] = call i64 @llvm.vector.reduce.smin.v4i64(<4 x i64> [[TMP16]])
+; CHECK-NEXT:    [[TMP18:%.*]] = insertelement <16 x i64> [[TMP15]], i64 [[TMP17]], i64 5
+; CHECK-NEXT:    [[TMP19:%.*]] = shufflevector <64 x i64> [[TMP0]], <64 x i64> poison, <4 x i32> <i32 6, i32 22, i32 38, i32 54>
+; CHECK-NEXT:    [[TMP20:%.*]] = call i64 @llvm.vector.reduce.smin.v4i64(<4 x i64> [[TMP19]])
+; CHECK-NEXT:    [[TMP21:%.*]] = insertelement <16 x i64> [[TMP18]], i64 [[TMP20]], i64 6
+; CHECK-NEXT:    [[TMP22:%.*]] = shufflevector <64 x i64> [[TMP0]], <64 x i64> poison, <4 x i32> <i32 7, i32 23, i32 39, i32 55>
+; CHECK-NEXT:    [[TMP23:%.*]] = call i64 @llvm.vector.reduce.smin.v4i64(<4 x i64> [[TMP22]])
+; CHECK-NEXT:    [[TMP24:%.*]] = insertelement <16 x i64> [[TMP21]], i64 [[TMP23]], i64 7
+; CHECK-NEXT:    [[TMP25:%.*]] = shufflevector <64 x i64> [[TMP0]], <64 x i64> poison, <4 x i32> <i32 8, i32 24, i32 40, i32 56>
+; CHECK-NEXT:    [[TMP26:%.*]] = call i64 @llvm.vector.reduce.smin.v4i64(<4 x i64> [[TMP25]])
+; CHECK-NEXT:    [[TMP27:%.*]] = insertelement <16 x i64> [[TMP24]], i64 [[TMP26]], i64 8
+; CHECK-NEXT:    [[TMP28:%.*]] = shufflevector <64 x i64> [[TMP0]], <64 x i64> poison, <4 x i32> <i32 9, i32 25, i32 41, i32 57>
+; CHECK-NEXT:    [[TMP29:%.*]] = call i64 @llvm.vector.reduce.smin.v4i64(<4 x i64> [[TMP28]])
+; CHECK-NEXT:    [[TMP30:%.*]] = insertelement <16 x i64> [[TMP27]], i64 [[TMP29]], i64 9
+; CHECK-NEXT:    [[TMP31:%.*]] = shufflevector <64 x i64> [[TMP0]], <64 x i64> poison, <4 x i32> <i32 10, i32 26, i32 42, i32 58>
+; CHECK-NEXT:    [[TMP32:%.*]] = call i64 @llvm.vector.reduce.smin.v4i64(<4 x i64> [[TMP31]])
+; CHECK-NEXT:    [[TMP33:%.*]] = insertelement <16 x i64> [[TMP30]], i64 [[TMP32]], i64 10
+; CHECK-NEXT:    [[TMP34:%.*]] = shufflevector <64 x i64> [[TMP0]], <64 x i64> poison, <4 x i32> <i32 11, i32 27, i32 43, i32 59>
+; CHECK-NEXT:    [[TMP35:%.*]] = call i64 @llvm.vector.reduce.smin.v4i64(<4 x i64> [[TMP34]])
+; CHECK-NEXT:    [[TMP36:%.*]] = insertelement <16 x i64> [[TMP33]], i64 [[TMP35]], i64 11
+; CHECK-NEXT:    [[TMP37:%.*]] = shufflevector <64 x i64> [[TMP0]], <64 x i64> poison, <4 x i32> <i32 12, i32 28, i32 44, i32 60>
+; CHECK-NEXT:    [[TMP38:%.*]] = call i64 @llvm.vector.reduce.smin.v4i64(<4 x i64> [[TMP37]])
+; CHECK-NEXT:    [[TMP39:%.*]] = insertelement <16 x i64> [[TMP36]], i64 [[TMP38]], i64 12
+; CHECK-NEXT:    [[TMP40:%.*]] = shufflevector <64 x i64> [[TMP0]], <64 x i64> poison, <4 x i32> <i32 13, i32 29, i32 45, i32 61>
+; CHECK-NEXT:    [[TMP41:%.*]] = call i64 @llvm.vector.reduce.smin.v4i64(<4 x i64> [[TMP40]])
+; CHECK-NEXT:    [[TMP42:%.*]] = insertelement <16 x i64> [[TMP39]], i64 [[TMP41]], i64 13
+; CHECK-NEXT:    [[TMP43:%.*]] = shufflevector <64 x i64> [[TMP0]], <64 x i64> poison, <4 x i32> <i32 14, i32 30, i32 46, i32 62>
+; CHECK-NEXT:    [[TMP44:%.*]] = call i64 @llvm.vector.reduce.smin.v4i64(<4 x i64> [[TMP43]])
+; CHECK-NEXT:    [[TMP45:%.*]] = insertelement <16 x i64> [[TMP42]], i64 [[TMP44]], i64 14
+; CHECK-NEXT:    [[TMP46:%.*]] = shufflevector <64 x i64> [[TMP0]], <64 x i64> poison, <4 x i32> <i32 15, i32 31, i32 47, i32 63>
+; CHECK-NEXT:    [[TMP47:%.*]] = call i64 @llvm.vector.reduce.smin.v4i64(<4 x i64> [[TMP46]])
+; CHECK-NEXT:    [[TMP48:%.*]] = insertelement <16 x i64> [[TMP45]], i64 [[TMP47]], i64 15
 ; CHECK-NEXT:    ret <16 x i64> [[TMP48]]
 ;
 entry:



More information about the llvm-commits mailing list