[llvm] [SLP][Revec] Fix SLP crash when trying to fold trailing scalars into the reduced value (PR #203477)

Sushant Gokhale via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 15 00:06:20 PDT 2026


================
@@ -30275,11 +30275,26 @@ class HorizontalReduction {
     // Emit ordered reduction for the vectorized window.
     Builder.SetCurrentDebugLocation(
         cast<Instruction>(ReductionRoot)->getDebugLoc());
-    if (VectorizedTree)
+    if (auto *VecTy = dyn_cast<FixedVectorType>(DestTy);
+        SLPReVec && VecTy && SuccessRoot) {
+      unsigned DestTyNumElements = getNumElements(VecTy);
+      unsigned VF = getNumElements(SuccessRoot->getType()) / DestTyNumElements;
----------------
sushgokh wrote:

>What if VF is 0?

Could you tell me a specific case or existing case where this can happen? If the case is vectorized, shouldn't `SuccessRoot` be some multiple of `DestTyNumElements` ? Anyway, `for (auto I : seq<unsigned>(VF))` will not trigger for VF=0

>How it will work for non-power-of-2 number of elements?

Will add a test case for this


https://github.com/llvm/llvm-project/pull/203477


More information about the llvm-commits mailing list