[llvm] 093206b - [SLP]Fix PR78298: Assertion `GEP->getNumIndices() == 1 &&

Alexey Bataev via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 16 09:17:42 PST 2024


Author: Alexey Bataev
Date: 2024-01-16T09:17:35-08:00
New Revision: 093206bb7eddf53cf6e1ffe4c0ffc09d37785e27

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

LOG: [SLP]Fix PR78298: Assertion `GEP->getNumIndices() == 1 &&
!isa<Constant>(GEPIdx)' failed.

The non-constant index might be folded to constant during earlier stages
of vectorization. Need to consider this option and filter out out GEP
with the constant indices from the candidates list.

Added: 
    llvm/test/Transforms/SLPVectorizer/X86/gep-nonconst-idx-transformed-to-const.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 caf686c445a2f7..482970bbf30612 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -16241,10 +16241,13 @@ bool SLPVectorizerPass::vectorizeGEPIndices(BasicBlock *BB, BoUpSLP &R) {
       SetVector<Value *> Candidates(GEPList.begin(), GEPList.end());
 
       // Some of the candidates may have already been vectorized after we
-      // initially collected them. If so, they are marked as deleted, so remove
-      // them from the set of candidates.
-      Candidates.remove_if(
-          [&R](Value *I) { return R.isDeleted(cast<Instruction>(I)); });
+      // initially collected them or their index is optimized to constant value.
+      // If so, they are marked as deleted, so remove them from the set of
+      // candidates.
+      Candidates.remove_if([&R](Value *I) {
+        return R.isDeleted(cast<Instruction>(I)) ||
+               isa<Constant>(cast<GetElementPtrInst>(I)->idx_begin()->get());
+      });
 
       // Remove from the set of candidates all pairs of getelementptrs with
       // constant 
diff erences. Such getelementptrs are likely not good

diff  --git a/llvm/test/Transforms/SLPVectorizer/X86/gep-nonconst-idx-transformed-to-const.ll b/llvm/test/Transforms/SLPVectorizer/X86/gep-nonconst-idx-transformed-to-const.ll
new file mode 100644
index 00000000000000..a95ede01b907e5
--- /dev/null
+++ b/llvm/test/Transforms/SLPVectorizer/X86/gep-nonconst-idx-transformed-to-const.ll
@@ -0,0 +1,19 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 4
+; RUN: opt -passes=slp-vectorizer -mtriple=x86_64-unknown-linux-gnu -S < %s | FileCheck %s
+
+define void @foo(i64 %0) {
+; CHECK-LABEL: define void @foo(
+; CHECK-SAME: i64 [[TMP0:%.*]]) {
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    [[TMP1:%.*]] = insertelement <8 x i64> zeroinitializer, i64 0, i64 0
+; CHECK-NEXT:    [[TMP2:%.*]] = getelementptr i32, ptr addrspace(1) null, i64 0
+; CHECK-NEXT:    [[TMP3:%.*]] = getelementptr i32, ptr addrspace(1) null, i64 [[TMP0]]
+; CHECK-NEXT:    ret void
+;
+entry:
+  %1 = or i64 0, 0
+  %2 = insertelement <8 x i64> zeroinitializer, i64 %1, i64 0
+  %3 = getelementptr i32, ptr addrspace(1) null, i64 %1
+  %4 = getelementptr i32, ptr addrspace(1) null, i64 %0
+  ret void
+}


        


More information about the llvm-commits mailing list