Skip to content

Commit b5d91ab

Browse files
committed
[SLP]Fix PR58863: Mask index beyond mask size for non-power-2 insertelement analysis.
Need to check if the insertelement mask size is reached during cost analysis to avoid compiler crash. Differential Revision: https://reviews.llvm.org/D137639
1 parent 42bce72 commit b5d91ab

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6702,7 +6702,8 @@ InstructionCost BoUpSLP::getEntryCost(const TreeEntry *E,
67026702
if (Mask[I] != UndefMaskElem)
67036703
Mask[I] = I + VecSz;
67046704
for (unsigned I = OffsetEnd + 1 - Offset; I < VecSz; ++I)
6705-
Mask[I] = InMask.test(I) ? UndefMaskElem : I;
6705+
Mask[I] =
6706+
((I >= InMask.size()) || InMask.test(I)) ? UndefMaskElem : I;
67066707
Cost += TTI->getShuffleCost(TTI::SK_PermuteTwoSrc, InsertVecTy, Mask);
67076708
}
67086709
}
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
2+
; RUN: opt -S -passes=slp-vectorizer < %s | FileCheck %s
3+
4+
define void @PR58863() {
5+
; CHECK-LABEL: @PR58863(
6+
; CHECK-NEXT: entry:
7+
; CHECK-NEXT: [[MUL_I:%.*]] = fmul float poison, poison
8+
; CHECK-NEXT: [[MUL11_I:%.*]] = fmul float poison, poison
9+
; CHECK-NEXT: [[I:%.*]] = insertelement <3 x float> <float poison, float 0.000000e+00, float poison>, float [[MUL_I]], i64 0
10+
; CHECK-NEXT: [[I1:%.*]] = insertelement <3 x float> [[I]], float [[MUL11_I]], i64 2
11+
; CHECK-NEXT: ret void
12+
;
13+
entry:
14+
%mul.i = fmul float poison, poison
15+
%mul11.i = fmul float poison, poison
16+
%i = insertelement <3 x float> <float poison, float 0.000000e+00, float poison>, float %mul.i, i64 0
17+
%i1 = insertelement <3 x float> %i, float %mul11.i, i64 2
18+
ret void
19+
}

0 commit comments

Comments
 (0)