[llvm] [SLP][REVEC] Fix false assumption of the source for castToScalarTyElem. (PR #99424)

Han-Kuan Chen via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 17 20:45:24 PDT 2024


https://github.com/HanKuanChen created https://github.com/llvm/llvm-project/pull/99424

The argument V may come from adjustExtracts, which is the vector operand of ExtractElementInst. In addition, it is not existed in getTreeEntry.

The vector operand of ExtractElementInst may have a type of <1 x Ty>, ensuring that the number of elements in ScalarTy and VecTy are equal.

reference: https://github.com/llvm/llvm-project/issues/99411

>From 20d17f5c0f00976c6c6423e79537785f94f2b61c Mon Sep 17 00:00:00 2001
From: Han-Kuan Chen <hankuan.chen at sifive.com>
Date: Wed, 17 Jul 2024 20:35:42 -0700
Subject: [PATCH] [SLP][REVEC] Fix false assumption of the source for
 castToScalarTyElem.

The argument V may come from adjustExtracts, which is the vector operand
of ExtractElementInst. In addition, it is not existed in getTreeEntry.

The vector operand of ExtractElementInst may have a type of <1 x Ty>,
ensuring that the number of elements in ScalarTy and VecTy are equal.

reference: https://github.com/llvm/llvm-project/issues/99411
---
 llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index ccb6734d5618c..a09bb00f3419e 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -11850,7 +11850,7 @@ class BoUpSLP::ShuffleInstructionBuilder final : public BaseShuffleAnalysis {
   Value *castToScalarTyElem(Value *V,
                             std::optional<bool> IsSigned = std::nullopt) {
     auto *VecTy = cast<VectorType>(V->getType());
-    assert(getNumElements(ScalarTy) < getNumElements(VecTy) &&
+    assert(getNumElements(ScalarTy) <= getNumElements(VecTy) &&
            (getNumElements(VecTy) % getNumElements(ScalarTy) == 0));
     if (VecTy->getElementType() == ScalarTy->getScalarType())
       return V;



More information about the llvm-commits mailing list