Skip to content

Commit a1ab5b4

Browse files
committed
[SLP]Check the MainOp matches the requirements for the instructions
Need to include MainOp into the analysis of the instructions in getSameOpcode to be sure that it is checked for the requirements to prevent crashes during further analysis.
1 parent 22687aa commit a1ab5b4

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -963,8 +963,9 @@ static InstructionsState getSameOpcode(ArrayRef<Value *> VL,
963963
return InstructionsState::invalid();
964964
}
965965
bool AnyPoison = InstCnt != VL.size();
966-
// Skip MainOp.
967-
for (Value *V : iterator_range(It + 1, VL.end())) {
966+
// Check MainOp too to be sure that it matches the requirements for the
967+
// instructions.
968+
for (Value *V : iterator_range(It, VL.end())) {
968969
auto *I = dyn_cast<Instruction>(V);
969970
if (!I)
970971
continue;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
2+
; RUN: opt -S --passes=slp-vectorizer -mtriple=thumb7 -mcpu=swift < %s | FileCheck %s
3+
4+
define i32 @test(ptr %0) {
5+
; CHECK-LABEL: define i32 @test(
6+
; CHECK-SAME: ptr [[TMP0:%.*]]) #[[ATTR0:[0-9]+]] {
7+
; CHECK-NEXT: [[CONT2:.*:]]
8+
; CHECK-NEXT: [[ARRAYIDX518:%.*]] = getelementptr i16, ptr [[TMP0]], i32 0
9+
; CHECK-NEXT: [[CMP524_NOT:%.*]] = icmp eq ptr [[ARRAYIDX518]], null
10+
; CHECK-NEXT: [[ARRAYIDX482_2:%.*]] = getelementptr [4 x i16], ptr null, i32 0, i32 0
11+
; CHECK-NEXT: [[CMP487_NOT_2:%.*]] = icmp eq ptr [[ARRAYIDX482_2]], null
12+
; CHECK-NEXT: ret i32 0
13+
;
14+
cont2:
15+
%arrayidx518 = getelementptr i16, ptr %0, i32 0
16+
%cmp524.not = icmp eq ptr %arrayidx518, null
17+
%cmp487.not.3 = icmp eq ptr null, null
18+
%arrayidx482.2 = getelementptr [4 x i16], ptr null, i32 0, i32 0
19+
%cmp487.not.2 = icmp eq ptr %arrayidx482.2, null
20+
%cmp487.not.1 = icmp eq ptr null, null
21+
ret i32 0
22+
}

0 commit comments

Comments
 (0)