[llvm] ae5ff3c - [SLP]Fix PR62665: compiler crash when trying to access non-existing mask
Alexey Bataev via llvm-commits
llvm-commits at lists.llvm.org
Mon May 22 13:46:16 PDT 2023
Author: Alexey Bataev
Date: 2023-05-22T13:43:25-07:00
New Revision: ae5ff3ca0cd923a9fb2b46701641acab3dd15e4b
URL: https://github.com/llvm/llvm-project/commit/ae5ff3ca0cd923a9fb2b46701641acab3dd15e4b
DIFF: https://github.com/llvm/llvm-project/commit/ae5ff3ca0cd923a9fb2b46701641acab3dd15e4b.diff
LOG: [SLP]Fix PR62665: compiler crash when trying to access non-existing mask
element.
Need to check at first if the SubMask element is PoisonMaskElem to avoid
compiler crash.
Added:
llvm/test/Transforms/SLPVectorizer/X86/poison-element-shuffle.ll
Modified:
llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index 75780ca2f0e73..c379c6db74327 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -961,9 +961,9 @@ static void addMask(SmallVectorImpl<int> &Mask, ArrayRef<int> SubMask,
SmallVector<int> NewMask(SubMask.size(), PoisonMaskElem);
int TermValue = std::min(Mask.size(), SubMask.size());
for (int I = 0, E = SubMask.size(); I < E; ++I) {
- if ((!ExtendingManyInputs &&
- (SubMask[I] >= TermValue || Mask[SubMask[I]] >= TermValue)) ||
- SubMask[I] == PoisonMaskElem)
+ if (SubMask[I] == PoisonMaskElem ||
+ (!ExtendingManyInputs &&
+ (SubMask[I] >= TermValue || Mask[SubMask[I]] >= TermValue)))
continue;
NewMask[I] = Mask[SubMask[I]];
}
diff --git a/llvm/test/Transforms/SLPVectorizer/X86/poison-element-shuffle.ll b/llvm/test/Transforms/SLPVectorizer/X86/poison-element-shuffle.ll
new file mode 100644
index 0000000000000..32ae2143e350a
--- /dev/null
+++ b/llvm/test/Transforms/SLPVectorizer/X86/poison-element-shuffle.ll
@@ -0,0 +1,48 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 2
+; RUN: opt --passes=slp-vectorizer -S -mtriple=x86_64-unknown-linux-gnu %s -o - | FileCheck %s
+
+define i32 @main(i32 %v) {
+; CHECK-LABEL: define i32 @main
+; CHECK-SAME: (i32 [[V:%.*]]) {
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[V1:%.*]] = sext i1 false to i32
+; CHECK-NEXT: br i1 false, label [[IF_END11:%.*]], label [[Q41:%.*]]
+; CHECK: if.end11:
+; CHECK-NEXT: [[P1:%.*]] = phi i32 [ [[V1]], [[ENTRY:%.*]] ], [ [[P6:%.*]], [[Q41]] ], [ [[V]], [[IF_END11]] ]
+; CHECK-NEXT: [[P2:%.*]] = phi i32 [ [[V1]], [[ENTRY]] ], [ [[P6]], [[Q41]] ], [ [[V]], [[IF_END11]] ]
+; CHECK-NEXT: [[P3:%.*]] = phi i32 [ [[V1]], [[ENTRY]] ], [ [[P6]], [[Q41]] ], [ 0, [[IF_END11]] ]
+; CHECK-NEXT: [[P4:%.*]] = phi i32 [ [[V1]], [[ENTRY]] ], [ [[P6]], [[Q41]] ], [ 0, [[IF_END11]] ]
+; CHECK-NEXT: [[P5:%.*]] = phi i32 [ [[V1]], [[ENTRY]] ], [ [[P6]], [[Q41]] ], [ 0, [[IF_END11]] ]
+; CHECK-NEXT: [[S_14:%.*]] = phi i32 [ 0, [[ENTRY]] ], [ [[S_3:%.*]], [[Q41]] ], [ [[V]], [[IF_END11]] ]
+; CHECK-NEXT: [[V_1:%.*]] = phi i32 [ undef, [[ENTRY]] ], [ [[V_4:%.*]], [[Q41]] ], [ 0, [[IF_END11]] ]
+; CHECK-NEXT: [[Q_1:%.*]] = phi i32 [ 0, [[ENTRY]] ], [ [[Q_2:%.*]], [[Q41]] ], [ 0, [[IF_END11]] ]
+; CHECK-NEXT: br i1 false, label [[Q41]], label [[IF_END11]]
+; CHECK: q41:
+; CHECK-NEXT: [[P6]] = phi i32 [ [[V]], [[ENTRY]] ], [ 0, [[IF_END11]] ]
+; CHECK-NEXT: [[S_3]] = phi i32 [ undef, [[ENTRY]] ], [ 0, [[IF_END11]] ]
+; CHECK-NEXT: [[V_4]] = phi i32 [ undef, [[ENTRY]] ], [ 0, [[IF_END11]] ]
+; CHECK-NEXT: [[Q_2]] = phi i32 [ undef, [[ENTRY]] ], [ 0, [[IF_END11]] ]
+; CHECK-NEXT: br label [[IF_END11]]
+;
+entry:
+ %v1 = sext i1 false to i32
+ br i1 false, label %if.end11, label %q41
+
+if.end11:
+ %p1 = phi i32 [ %v1, %entry ], [ %p6, %q41 ], [ %v, %if.end11 ]
+ %p2 = phi i32 [ %v1, %entry ], [ %p6, %q41 ], [ %v, %if.end11 ]
+ %p3 = phi i32 [ %v1, %entry ], [ %p6, %q41 ], [ 0, %if.end11 ]
+ %p4 = phi i32 [ %v1, %entry ], [ %p6, %q41 ], [ 0, %if.end11 ]
+ %p5 = phi i32 [ %v1, %entry ], [ %p6, %q41 ], [ 0, %if.end11 ]
+ %s.14 = phi i32 [ 0, %entry ], [ %s.3, %q41 ], [ %v, %if.end11 ]
+ %v.1 = phi i32 [ undef, %entry ], [ %v.4, %q41 ], [ 0, %if.end11 ]
+ %q.1 = phi i32 [ 0, %entry ], [ %q.2, %q41 ], [ 0, %if.end11 ]
+ br i1 false, label %q41, label %if.end11
+
+q41:
+ %p6 = phi i32 [ %v, %entry ], [ 0, %if.end11 ]
+ %s.3 = phi i32 [ undef, %entry ], [ 0, %if.end11 ]
+ %v.4 = phi i32 [ undef, %entry ], [ 0, %if.end11 ]
+ %q.2 = phi i32 [ undef, %entry ], [ 0, %if.end11 ]
+ br label %if.end11
+}
More information about the llvm-commits
mailing list