Skip to content

Commit b4b2e26

Browse files
committed
[SLP] Fix infinite loop in isUndefVector.
This fixes an infinite loop if isa<T>(II->getOperand(1)) is true. Update Base at the top of the loop, before the continue. Reviewed By: ABataev Differential Revision: https://reviews.llvm.org/D144292 (cherry-picked from f61c9b7)
1 parent 9eb8634 commit b4b2e26

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,9 +337,9 @@ static SmallBitVector isUndefVector(const Value *V,
337337
if (!ShuffleMask.empty()) {
338338
const Value *Base = V;
339339
while (auto *II = dyn_cast<InsertElementInst>(Base)) {
340+
Base = II->getOperand(0);
340341
if (isa<T>(II->getOperand(1)))
341342
continue;
342-
Base = II->getOperand(0);
343343
Optional<unsigned> Idx = getInsertIndex(II);
344344
if (!Idx)
345345
continue;

llvm/test/Transforms/SLPVectorizer/AArch64/insertelement.ll

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,25 @@ define <vscale x 2 x float> @insertelement-scalable-vector() {
3535

3636
; Function Attrs: nounwind readnone speculatable willreturn
3737
declare float @llvm.fabs.f32(float)
38+
39+
40+
define <4 x float> @insertelement_poison_lanes(ptr %0) {
41+
; CHECK-LABEL: @insertelement_poison_lanes(
42+
; CHECK-NEXT: [[INS_1:%.*]] = insertelement <4 x float> zeroinitializer, float poison, i64 0
43+
; CHECK-NEXT: [[INS_2:%.*]] = insertelement <4 x float> [[INS_1]], float 0.000000e+00, i64 0
44+
; CHECK-NEXT: [[GEP_1:%.*]] = getelementptr double, ptr [[TMP0:%.*]], i64 1
45+
; CHECK-NEXT: store <2 x double> <double 0.000000e+00, double 1.000000e+00>, ptr [[GEP_1]], align 8
46+
; CHECK-NEXT: ret <4 x float> [[INS_2]]
47+
;
48+
%trunc.1 = fptrunc double 0.000000e+00 to float
49+
%trunc.2 = fptrunc double 1.000000e+00 to float
50+
%ins.1 = insertelement <4 x float> zeroinitializer, float poison, i64 0
51+
%ins.2 = insertelement <4 x float> %ins.1, float %trunc.1, i64 0
52+
%ext.1 = fpext float %trunc.1 to double
53+
%gep.1 = getelementptr double, ptr %0, i64 1
54+
store double %ext.1, ptr %gep.1, align 8
55+
%ext.2 = fpext float %trunc.2 to double
56+
%gep.2 = getelementptr double, ptr %0, i64 2
57+
store double %ext.2, ptr %gep.2, align 8
58+
ret <4 x float> %ins.2
59+
}

0 commit comments

Comments
 (0)