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

via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 18 04:54:48 PDT 2024


Author: Han-Kuan Chen
Date: 2024-07-18T19:54:46+08:00
New Revision: b634e057ddecc41dce046887d0f0854fed305374

URL: https://github.com/llvm/llvm-project/commit/b634e057ddecc41dce046887d0f0854fed305374
DIFF: https://github.com/llvm/llvm-project/commit/b634e057ddecc41dce046887d0f0854fed305374.diff

LOG: [SLP][REVEC] Fix false assumption of the source for castToScalarTyElem. (#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

Added: 
    llvm/test/Transforms/SLPVectorizer/revec-fix-99411.ll

Modified: 
    llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index d88c6307b994b..b994645cece61 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -11852,8 +11852,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) &&
-           (getNumElements(VecTy) % getNumElements(ScalarTy) == 0));
+    assert(getNumElements(VecTy) % getNumElements(ScalarTy) == 0);
     if (VecTy->getElementType() == ScalarTy->getScalarType())
       return V;
     return Builder.CreateIntCast(

diff  --git a/llvm/test/Transforms/SLPVectorizer/revec-fix-99411.ll b/llvm/test/Transforms/SLPVectorizer/revec-fix-99411.ll
new file mode 100644
index 0000000000000..655e4a1aa5483
--- /dev/null
+++ b/llvm/test/Transforms/SLPVectorizer/revec-fix-99411.ll
@@ -0,0 +1,19 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt -mtriple x86_64-unknown-linux-gnu -passes=slp-vectorizer -S %s | FileCheck %s
+
+define void @e() {
+; CHECK-LABEL: @e(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    store <2 x i64> zeroinitializer, ptr null, align 8
+; CHECK-NEXT:    ret void
+;
+entry:
+  %0 = extractelement <1 x i64> zeroinitializer, i64 0
+  %bf.value = and i64 %0, 0
+  %bf.set = or i64 0, %bf.value
+  store i64 %bf.set, ptr getelementptr inbounds (i8, ptr null, i64 8), align 8
+  %bf.value2 = and i64 0, 0
+  %bf.set4 = or i64 0, %bf.value2
+  store i64 %bf.set4, ptr null, align 8
+  ret void
+}


        


More information about the llvm-commits mailing list