Skip to content

Commit fdf72c9

Browse files
committed
[SLP]Fix a crash when requestin the cost for buildvector cmp nodes types.
Need to use original cmp type i1 when estimating the cost for the buildvector node, not its operand types to prevent compiler crash upon TTI cost estimation.
1 parent 57726c4 commit fdf72c9

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9465,6 +9465,8 @@ BoUpSLP::getEntryCost(const TreeEntry *E, ArrayRef<Value *> VectorizedVals,
94659465
return 0;
94669466
if (isa<InsertElementInst>(VL[0]))
94679467
return InstructionCost::getInvalid();
9468+
if (isa<CmpInst>(VL.front()))
9469+
ScalarTy = VL.front()->getType();
94689470
return processBuildVector<ShuffleCostEstimator, InstructionCost>(
94699471
E, ScalarTy, *TTI, VectorizedVals, *this, CheckedExtracts);
94709472
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
2+
; RUN: opt -S --mtriple=x86_64-yoe-linux --passes=slp-vectorizer < %s | FileCheck %s
3+
4+
declare void @fn(ptr)
5+
6+
define void @test(ptr %0, i32 %1, i1 %2) {
7+
; CHECK-LABEL: define void @test(
8+
; CHECK-SAME: ptr [[TMP0:%.*]], i32 [[TMP1:%.*]], i1 [[TMP2:%.*]]) {
9+
; CHECK-NEXT: [[TMP4:%.*]] = icmp eq ptr [[TMP0]], null
10+
; CHECK-NEXT: [[TMP5:%.*]] = select i1 [[TMP4]], i64 0, i64 33554432
11+
; CHECK-NEXT: [[TMP6:%.*]] = select i1 [[TMP2]], i64 0, i64 67108864
12+
; CHECK-NEXT: [[TMP7:%.*]] = icmp eq i32 [[TMP1]], 0
13+
; CHECK-NEXT: [[TMP8:%.*]] = select i1 [[TMP7]], i64 0, i64 134217728
14+
; CHECK-NEXT: [[TMP9:%.*]] = icmp eq i32 [[TMP1]], 0
15+
; CHECK-NEXT: [[TMP10:%.*]] = select i1 [[TMP9]], i64 0, i64 268435456
16+
; CHECK-NEXT: [[TMP11:%.*]] = or i64 [[TMP5]], [[TMP6]]
17+
; CHECK-NEXT: [[TMP12:%.*]] = or i64 [[TMP11]], [[TMP8]]
18+
; CHECK-NEXT: [[TMP13:%.*]] = or i64 [[TMP12]], [[TMP10]]
19+
; CHECK-NEXT: [[TMP14:%.*]] = inttoptr i64 [[TMP13]] to ptr
20+
; CHECK-NEXT: call void @fn(ptr [[TMP14]])
21+
; CHECK-NEXT: ret void
22+
;
23+
%4 = icmp eq ptr %0, null
24+
%5 = select i1 %4, i64 0, i64 33554432
25+
%6 = select i1 %2, i64 0, i64 67108864
26+
%7 = icmp eq i32 %1, 0
27+
%8 = select i1 %7, i64 0, i64 134217728
28+
%9 = icmp eq i32 %1, 0
29+
%10 = select i1 %9, i64 0, i64 268435456
30+
%11 = or i64 %5, %6
31+
%12 = or i64 %11, %8
32+
%13 = or i64 %12, %10
33+
%14 = inttoptr i64 %13 to ptr
34+
call void @fn(ptr %14)
35+
ret void
36+
}

0 commit comments

Comments
 (0)