[llvm] aae2eaa - [SLP]Fix a crash when trying to cast scalable vector type to fixed.

Alexey Bataev via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 19 11:57:35 PDT 2023


Author: Alexey Bataev
Date: 2023-07-19T11:53:49-07:00
New Revision: aae2eaae2cefd3132059925c4592276defdb1faa

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

LOG: [SLP]Fix a crash when trying to cast scalable vector type to fixed.

Need to check for FixedVectorType, not a vector type, since later
compiler performs unconditional cast to FixedVectorType and gets the
number of elements in this type.

Added: 
    llvm/test/Transforms/SLPVectorizer/RISCV/scalable-type-to-vect.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 32279ed71f3dfb..dc306f3795f34d 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -6156,7 +6156,7 @@ unsigned BoUpSLP::canMapToVector(Type *T, const DataLayout &DL) const {
   unsigned N = 1;
   Type *EltTy = T;
 
-  while (isa<StructType, ArrayType, VectorType>(EltTy)) {
+  while (isa<StructType, ArrayType, FixedVectorType>(EltTy)) {
     if (auto *ST = dyn_cast<StructType>(EltTy)) {
       // Check that struct is homogeneous.
       for (const auto *Ty : ST->elements())
@@ -6177,7 +6177,8 @@ unsigned BoUpSLP::canMapToVector(Type *T, const DataLayout &DL) const {
   if (!isValidElementType(EltTy))
     return 0;
   uint64_t VTSize = DL.getTypeStoreSizeInBits(FixedVectorType::get(EltTy, N));
-  if (VTSize < MinVecRegSize || VTSize > MaxVecRegSize || VTSize != DL.getTypeStoreSizeInBits(T))
+  if (VTSize < MinVecRegSize || VTSize > MaxVecRegSize ||
+      VTSize != DL.getTypeStoreSizeInBits(T))
     return 0;
   return N;
 }

diff  --git a/llvm/test/Transforms/SLPVectorizer/RISCV/scalable-type-to-vect.ll b/llvm/test/Transforms/SLPVectorizer/RISCV/scalable-type-to-vect.ll
new file mode 100644
index 00000000000000..2efe92f1bf077f
--- /dev/null
+++ b/llvm/test/Transforms/SLPVectorizer/RISCV/scalable-type-to-vect.ll
@@ -0,0 +1,14 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 2
+; RUN: opt -S -passes=slp-vectorizer -mtriple=riscv64-unknown-unknown -mattr=+v < %s | FileCheck %s
+
+define { <vscale x 2 x i32>, <vscale x 2 x i32> } @foo() {
+; CHECK-LABEL: define { <vscale x 2 x i32>, <vscale x 2 x i32> } @foo
+; CHECK-SAME: () #[[ATTR0:[0-9]+]] {
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    [[TMP0:%.*]] = insertvalue { <vscale x 2 x i32>, <vscale x 2 x i32> } zeroinitializer, <vscale x 2 x i32> zeroinitializer, 0
+; CHECK-NEXT:    ret { <vscale x 2 x i32>, <vscale x 2 x i32> } zeroinitializer
+;
+entry:
+  %0 = insertvalue { <vscale x 2 x i32>, <vscale x 2 x i32> } zeroinitializer, <vscale x 2 x i32> zeroinitializer, 0
+  ret { <vscale x 2 x i32>, <vscale x 2 x i32> } zeroinitializer
+}


        


More information about the llvm-commits mailing list