[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
This commit is contained in:
Alexey Bataev 2022-11-08 06:16:30 -08:00
parent 42bce72536
commit b5d91ab73e
2 changed files with 21 additions and 1 deletions

View File

@ -6702,7 +6702,8 @@ InstructionCost BoUpSLP::getEntryCost(const TreeEntry *E,
if (Mask[I] != UndefMaskElem)
Mask[I] = I + VecSz;
for (unsigned I = OffsetEnd + 1 - Offset; I < VecSz; ++I)
Mask[I] = InMask.test(I) ? UndefMaskElem : I;
Mask[I] =
((I >= InMask.size()) || InMask.test(I)) ? UndefMaskElem : I;
Cost += TTI->getShuffleCost(TTI::SK_PermuteTwoSrc, InsertVecTy, Mask);
}
}

View File

@ -0,0 +1,19 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt -S -passes=slp-vectorizer < %s | FileCheck %s
define void @PR58863() {
; CHECK-LABEL: @PR58863(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[MUL_I:%.*]] = fmul float poison, poison
; CHECK-NEXT: [[MUL11_I:%.*]] = fmul float poison, poison
; CHECK-NEXT: [[I:%.*]] = insertelement <3 x float> <float poison, float 0.000000e+00, float poison>, float [[MUL_I]], i64 0
; CHECK-NEXT: [[I1:%.*]] = insertelement <3 x float> [[I]], float [[MUL11_I]], i64 2
; CHECK-NEXT: ret void
;
entry:
%mul.i = fmul float poison, poison
%mul11.i = fmul float poison, poison
%i = insertelement <3 x float> <float poison, float 0.000000e+00, float poison>, float %mul.i, i64 0
%i1 = insertelement <3 x float> %i, float %mul11.i, i64 2
ret void
}