[llvm] [SLP]Improve costs in computeExtractCost() to avoid crash after D158449. (PR #67142)

Valery Dmitriev via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 25 19:41:07 PDT 2023


================
@@ -7067,30 +7067,53 @@ class BoUpSLP::ShuffleCostEstimator : public BaseShuffleAnalysis {
   /// extracted values from \p VL.
   InstructionCost computeExtractCost(ArrayRef<Value *> VL, ArrayRef<int> Mask,
                                      TTI::ShuffleKind ShuffleKind) {
-    auto *VecTy = FixedVectorType::get(VL.front()->getType(), VL.size());
+    unsigned NumElts = 0;
+    for (Value *V : VL) {
+      auto *EE = dyn_cast<ExtractElementInst>(V);
+      if (!EE)
+        continue;
+      auto *VecTy = cast<FixedVectorType>(EE->getVectorOperandType());
+      NumElts = std::max(NumElts, VecTy->getNumElements());
+    }
+    auto *VecTy = FixedVectorType::get(VL.front()->getType(), NumElts);
     unsigned NumOfParts = TTI.getNumberOfParts(VecTy);
-
-    if (ShuffleKind != TargetTransformInfo::SK_PermuteSingleSrc ||
-        !NumOfParts || VecTy->getNumElements() < NumOfParts)
+    if (!NumOfParts || NumElts < NumOfParts)
----------------
valerydmit wrote:

Found the condition originally appeared with 
```
commit 8e5f3d04f269dbe791076e775f1d1a098cbada01
Author: Fangrui Song <i at maskray.me>
Date:   Fri Apr 2 11:13:51 2021 -0700

    [SLPVectorizer] Fix divide-by-zero after D99719

    Will add a test case later.
```
But it looks like there is still no test case that executes the condition. @MaskRay , any chance to find/add the test case?

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


More information about the llvm-commits mailing list