Skip to content

Commit ac93b61

Browse files
committed
[SLP]Fix PR59098: check if the vector type is scalarized for
extractelements. If the resulting type is going to be scalarized, no need to adjust the cost of removed extractelement and insert/extract subvector costs. Otherwise, the compiler can crash because of the wrong type sizes.
1 parent 70180ee commit ac93b61

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6275,6 +6275,10 @@ InstructionCost BoUpSLP::getEntryCost(const TreeEntry *E,
62756275
// FIXME: it tries to fix a problem with MSVC buildbots.
62766276
TargetTransformInfo *TTI = this->TTI;
62776277
auto AdjustExtractsCost = [=](InstructionCost &Cost) {
6278+
// If the resulting type is scalarized, do not adjust the cost.
6279+
unsigned VecNumParts = TTI->getNumberOfParts(VecTy);
6280+
if (VecNumParts == VecTy->getNumElements())
6281+
return;
62786282
DenseMap<Value *, int> ExtractVectorsTys;
62796283
SmallPtrSet<Value *, 4> CheckedExtracts;
62806284
for (auto *V : VL) {
@@ -6296,8 +6300,7 @@ InstructionCost BoUpSLP::getEntryCost(const TreeEntry *E,
62966300
if (!EEIdx)
62976301
continue;
62986302
unsigned Idx = *EEIdx;
6299-
if (TTI->getNumberOfParts(VecTy) !=
6300-
TTI->getNumberOfParts(EE->getVectorOperandType())) {
6303+
if (VecNumParts != TTI->getNumberOfParts(EE->getVectorOperandType())) {
63016304
auto It =
63026305
ExtractVectorsTys.try_emplace(EE->getVectorOperand(), Idx).first;
63036306
It->getSecond() = std::min<int>(It->second, Idx);
@@ -6328,7 +6331,7 @@ InstructionCost BoUpSLP::getEntryCost(const TreeEntry *E,
63286331
unsigned NumElts = VecTy->getNumElements();
63296332
if (Data.second % NumElts == 0)
63306333
continue;
6331-
if (TTI->getNumberOfParts(EEVTy) > TTI->getNumberOfParts(VecTy)) {
6334+
if (TTI->getNumberOfParts(EEVTy) > VecNumParts) {
63326335
unsigned Idx = (Data.second / NumElts) * NumElts;
63336336
unsigned EENumElts = EEVTy->getNumElements();
63346337
if (Idx + NumElts <= EENumElts) {
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2+
; RUN: opt -passes=slp-vectorizer -mtriple=x86_64-unknown-linux-gnu -S < %s | FileCheck %s
3+
4+
define void @test() {
5+
; CHECK-LABEL: @test(
6+
; CHECK-NEXT: entry:
7+
; CHECK-NEXT: [[TMP0:%.*]] = extractelement <8 x half> zeroinitializer, i64 1
8+
; CHECK-NEXT: [[TOBOOL:%.*]] = fcmp une half [[TMP0]], 0xH0000
9+
; CHECK-NEXT: [[TMP1:%.*]] = extractelement <8 x half> zeroinitializer, i64 1
10+
; CHECK-NEXT: [[TOBOOL3:%.*]] = fcmp une half [[TMP1]], 0xH0000
11+
; CHECK-NEXT: ret void
12+
;
13+
entry:
14+
%0 = extractelement <8 x half> zeroinitializer, i64 1
15+
%tobool = fcmp une half %0, 0xH0000
16+
%1 = extractelement <8 x half> zeroinitializer, i64 1
17+
%tobool3 = fcmp une half %1, 0xH0000
18+
ret void
19+
}

0 commit comments

Comments
 (0)