Skip to content

Commit 093206b

Browse files
committed
[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.
1 parent 371fdba commit 093206b

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16241,10 +16241,13 @@ bool SLPVectorizerPass::vectorizeGEPIndices(BasicBlock *BB, BoUpSLP &R) {
1624116241
SetVector<Value *> Candidates(GEPList.begin(), GEPList.end());
1624216242

1624316243
// Some of the candidates may have already been vectorized after we
16244-
// initially collected them. If so, they are marked as deleted, so remove
16245-
// them from the set of candidates.
16246-
Candidates.remove_if(
16247-
[&R](Value *I) { return R.isDeleted(cast<Instruction>(I)); });
16244+
// initially collected them or their index is optimized to constant value.
16245+
// If so, they are marked as deleted, so remove them from the set of
16246+
// candidates.
16247+
Candidates.remove_if([&R](Value *I) {
16248+
return R.isDeleted(cast<Instruction>(I)) ||
16249+
isa<Constant>(cast<GetElementPtrInst>(I)->idx_begin()->get());
16250+
});
1624816251

1624916252
// Remove from the set of candidates all pairs of getelementptrs with
1625016253
// constant differences. Such getelementptrs are likely not good
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 4
2+
; RUN: opt -passes=slp-vectorizer -mtriple=x86_64-unknown-linux-gnu -S < %s | FileCheck %s
3+
4+
define void @foo(i64 %0) {
5+
; CHECK-LABEL: define void @foo(
6+
; CHECK-SAME: i64 [[TMP0:%.*]]) {
7+
; CHECK-NEXT: entry:
8+
; CHECK-NEXT: [[TMP1:%.*]] = insertelement <8 x i64> zeroinitializer, i64 0, i64 0
9+
; CHECK-NEXT: [[TMP2:%.*]] = getelementptr i32, ptr addrspace(1) null, i64 0
10+
; CHECK-NEXT: [[TMP3:%.*]] = getelementptr i32, ptr addrspace(1) null, i64 [[TMP0]]
11+
; CHECK-NEXT: ret void
12+
;
13+
entry:
14+
%1 = or i64 0, 0
15+
%2 = insertelement <8 x i64> zeroinitializer, i64 %1, i64 0
16+
%3 = getelementptr i32, ptr addrspace(1) null, i64 %1
17+
%4 = getelementptr i32, ptr addrspace(1) null, i64 %0
18+
ret void
19+
}

0 commit comments

Comments
 (0)