Skip to content

Commit 7a4fc74

Browse files
authored
[SLP][REVEC] Fix insertelement has multiple uses. (#102329)
1 parent 899f648 commit 7a4fc74

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6419,6 +6419,16 @@ BoUpSLP::TreeEntry::EntryState BoUpSLP::getScalarsVectorizationState(
64196419
return TreeEntry::NeedToGather;
64206420
}
64216421

6422+
if (any_of(VL, [&SourceVectors](Value *V) {
6423+
// The last InsertElement can have multiple uses.
6424+
return SourceVectors.contains(V) && !V->hasOneUse();
6425+
})) {
6426+
assert(SLPReVec && "Only supported by REVEC.");
6427+
LLVM_DEBUG(dbgs() << "SLP: Gather of insertelement vectors with "
6428+
"multiple uses.\n");
6429+
return TreeEntry::NeedToGather;
6430+
}
6431+
64226432
return TreeEntry::Vectorize;
64236433
}
64246434
case Instruction::Load: {

llvm/test/Transforms/SLPVectorizer/revec.ll

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,26 @@ entry:
124124
store <8 x i1> %6, ptr %7, align 1
125125
ret void
126126
}
127+
128+
define void @test5(ptr %ptr0, ptr %ptr1) {
129+
; CHECK-LABEL: @test5(
130+
; CHECK-NEXT: entry:
131+
; CHECK-NEXT: [[GETELEMENTPTR0:%.*]] = getelementptr i8, ptr null, i64 0
132+
; CHECK-NEXT: [[TMP0:%.*]] = insertelement <4 x ptr> <ptr null, ptr null, ptr undef, ptr undef>, ptr [[GETELEMENTPTR0]], i32 2
133+
; CHECK-NEXT: [[TMP1:%.*]] = insertelement <4 x ptr> [[TMP0]], ptr null, i32 3
134+
; CHECK-NEXT: [[TMP2:%.*]] = icmp ult <4 x ptr> zeroinitializer, [[TMP1]]
135+
; CHECK-NEXT: [[TMP3:%.*]] = insertelement <4 x ptr> <ptr poison, ptr null, ptr null, ptr null>, ptr [[PTR0:%.*]], i32 0
136+
; CHECK-NEXT: [[TMP4:%.*]] = insertelement <4 x ptr> [[TMP1]], ptr [[PTR1:%.*]], i32 3
137+
; CHECK-NEXT: [[TMP5:%.*]] = icmp ult <4 x ptr> [[TMP3]], [[TMP4]]
138+
; CHECK-NEXT: ret void
139+
;
140+
entry:
141+
%getelementptr0 = getelementptr i8, ptr null, i64 0
142+
%0 = insertelement <4 x ptr> <ptr null, ptr null, ptr undef, ptr undef>, ptr %getelementptr0, i32 2
143+
%1 = insertelement <4 x ptr> %0, ptr null, i32 3
144+
%2 = icmp ult <4 x ptr> zeroinitializer, %1
145+
%3 = insertelement <4 x ptr> <ptr poison, ptr null, ptr null, ptr null>, ptr %ptr0, i32 0
146+
%4 = insertelement <4 x ptr> %1, ptr %ptr1, i32 3
147+
%5 = icmp ult <4 x ptr> %3, %4
148+
ret void
149+
}

0 commit comments

Comments
 (0)