[PATCH] D137639: [SLP]Fix PR58863: Mask index beyond mask size for non-power-2 insertelement analysis.
Alexey Bataev via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 8 06:19:46 PST 2022
ABataev created this revision.
ABataev added reviewers: RKSimon, vdmitrie.
Herald added subscribers: vporpo, arphaman, hiraditya.
Herald added a project: All.
ABataev requested review of this revision.
Herald added a subscriber: pcwang-thead.
Herald added a project: LLVM.
Need to check if the insertelement mask size is reached during cost analysis to avoid compiler crash.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D137639
Files:
llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
llvm/test/Transforms/SLPVectorizer/slp-non-pow-2-insertelement.ll
Index: llvm/test/Transforms/SLPVectorizer/slp-non-pow-2-insertelement.ll
===================================================================
--- /dev/null
+++ llvm/test/Transforms/SLPVectorizer/slp-non-pow-2-insertelement.ll
@@ -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
+}
Index: llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
===================================================================
--- llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -6592,8 +6592,13 @@
I <= End; ++I)
if (Mask[I] != UndefMaskElem)
Mask[I] = I + VecSz;
- for (unsigned I = OffsetEnd + 1 - Offset; I < VecSz; ++I)
+ for (unsigned I = OffsetEnd + 1 - Offset; I < VecSz; ++I) {
+ if (I >= InMask.size()) {
+ Mask[I] = UndefMaskElem;
+ continue;
+ }
Mask[I] = InMask.test(I) ? UndefMaskElem : I;
+ }
Cost += TTI->getShuffleCost(TTI::SK_PermuteTwoSrc, InsertVecTy, Mask);
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D137639.473984.patch
Type: text/x-patch
Size: 1853 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221108/54f58dce/attachment.bin>
More information about the llvm-commits
mailing list