Skip to content

Commit f381cd0

Browse files
committed
[SLP]Fix PR107036: Check if the type of the user is sizable before requesting its size.
Only some instructions should be considered as potentially reducing the size of the operands types, not all instructions should be considered. Fixes #107036
1 parent 70a19ad commit f381cd0

File tree

2 files changed

+36
-4
lines changed

2 files changed

+36
-4
lines changed

llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -16055,15 +16055,16 @@ void BoUpSLP::computeMinimumValueSizes() {
1605516055
const TreeEntry *UserTE = E.UserTreeIndices.back().UserTE;
1605616056
if (TE == UserTE || !TE)
1605716057
return false;
16058+
if (!isa<CastInst, BinaryOperator, FreezeInst, PHINode,
16059+
SelectInst>(U) ||
16060+
!isa<CastInst, BinaryOperator, FreezeInst, PHINode,
16061+
SelectInst>(UserTE->getMainOp()))
16062+
return true;
1605816063
unsigned UserTESz = DL->getTypeSizeInBits(
1605916064
UserTE->Scalars.front()->getType());
1606016065
auto It = MinBWs.find(TE);
1606116066
if (It != MinBWs.end() && It->second.first > UserTESz)
1606216067
return true;
16063-
// The size of icmp is always 1 and should not be
16064-
// considered.
16065-
if (TE->getOpcode() == Instruction::ICmp)
16066-
return true;
1606716068
return DL->getTypeSizeInBits(U->getType()) > UserTESz;
1606816069
}));
1606916070
})) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
2+
; RUN: opt -S --passes=slp-vectorizer -mtriple=x86_64-unknown-linux-gnu < %s -slp-threshold=-100 | FileCheck %s
3+
4+
define void @test(ptr %i) {
5+
; CHECK-LABEL: define void @test(
6+
; CHECK-SAME: ptr [[I:%.*]]) {
7+
; CHECK-NEXT: [[BB:.*]]:
8+
; CHECK-NEXT: br label %[[BB2:.*]]
9+
; CHECK: [[BB2]]:
10+
; CHECK-NEXT: [[TMP0:%.*]] = phi <2 x i32> [ [[TMP3:%.*]], %[[BB2]] ], [ zeroinitializer, %[[BB]] ]
11+
; CHECK-NEXT: store <2 x i32> [[TMP0]], ptr [[I]], align 4
12+
; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <2 x i32> [[TMP0]], <2 x i32> <i32 0, i32 poison>, <2 x i32> <i32 2, i32 1>
13+
; CHECK-NEXT: [[TMP2:%.*]] = trunc <2 x i32> [[TMP1]] to <2 x i1>
14+
; CHECK-NEXT: [[TMP3]] = select <2 x i1> [[TMP2]], <2 x i32> zeroinitializer, <2 x i32> zeroinitializer
15+
; CHECK-NEXT: br label %[[BB2]]
16+
;
17+
bb:
18+
%i1 = getelementptr i8, ptr %i, i64 4
19+
br label %bb2
20+
21+
bb2:
22+
%i3 = phi i32 [ %i6, %bb2 ], [ 0, %bb ]
23+
%i4 = phi i32 [ %i8, %bb2 ], [ 0, %bb ]
24+
store i32 %i3, ptr %i
25+
store i32 %i4, ptr %i1
26+
%i5 = trunc i32 0 to i1
27+
%i6 = select i1 %i5, i32 0, i32 0
28+
%i7 = trunc i32 %i4 to i1
29+
%i8 = select i1 %i7, i32 0, i32 0
30+
br label %bb2
31+
}

0 commit comments

Comments
 (0)