Skip to content

Commit 25af397

Browse files
JonPsson1GeorgeARM
authored andcommitted
[SLPVectorizer] Move X86 specific handling into X86TTIImpl. (llvm#137830)
`ad9909d "[SLP]Fix perfect diamond match with extractelements in scalars" ` changed SLPVectorizer getScalarizationOverhead() to call TTI.getVectorInstrCost() instead of TTI.getScalarizationOverhead() in some cases. This was due to X86 specific handlings in these (overridden) methods, and unfortunately the general preference of TTI.getScalarizationOverhead() was dropped. If VL is available it should always be preferred to use getScalarizationOverhead(), and this is indeed the case for SystemZ which has a special insertion instruction that can insert two GPR64s. Then ` 33af951 "[SLP]Synchronize cost of gather/buildvector nodes with codegen"` reworked SLPVectorizer getGatherCost() which together with ad9909d caused the SystemZ test vec-elt-insertion.ll to fail. This patch restores the SystemZ test and reverts the change in SLPVectorizer getScalarizationOverhead() so that TTI.getScalarizationOverhead() is always called again. The ForPoisonSrc argument is now passed on to the TTI method so that X86 can handle this as required. Fixes: llvm#135346
1 parent 5e8e3bc commit 25af397

16 files changed

+75
-60
lines changed

llvm/include/llvm/Analysis/TargetTransformInfo.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -941,6 +941,7 @@ class TargetTransformInfo {
941941
const APInt &DemandedElts,
942942
bool Insert, bool Extract,
943943
TTI::TargetCostKind CostKind,
944+
bool ForPoisonSrc = true,
944945
ArrayRef<Value *> VL = {}) const;
945946

946947
/// Estimate the overhead of scalarizing an instructions unique

llvm/include/llvm/Analysis/TargetTransformInfoImpl.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,8 @@ class TargetTransformInfoImplBase {
453453

454454
virtual InstructionCost getScalarizationOverhead(
455455
VectorType *Ty, const APInt &DemandedElts, bool Insert, bool Extract,
456-
TTI::TargetCostKind CostKind, ArrayRef<Value *> VL = {}) const {
456+
TTI::TargetCostKind CostKind, bool ForPoisonSrc = true,
457+
ArrayRef<Value *> VL = {}) const {
457458
return 0;
458459
}
459460

llvm/include/llvm/CodeGen/BasicTTIImpl.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -871,7 +871,8 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
871871
/// extracted from vectors.
872872
InstructionCost getScalarizationOverhead(
873873
VectorType *InTy, const APInt &DemandedElts, bool Insert, bool Extract,
874-
TTI::TargetCostKind CostKind, ArrayRef<Value *> VL = {}) const override {
874+
TTI::TargetCostKind CostKind, bool ForPoisonSrc = true,
875+
ArrayRef<Value *> VL = {}) const override {
875876
/// FIXME: a bitfield is not a reasonable abstraction for talking about
876877
/// which elements are needed from a scalable vector
877878
if (isa<ScalableVectorType>(InTy))

llvm/lib/Analysis/TargetTransformInfo.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -630,9 +630,10 @@ bool TargetTransformInfo::isTargetIntrinsicWithStructReturnOverloadAtField(
630630

631631
InstructionCost TargetTransformInfo::getScalarizationOverhead(
632632
VectorType *Ty, const APInt &DemandedElts, bool Insert, bool Extract,
633-
TTI::TargetCostKind CostKind, ArrayRef<Value *> VL) const {
633+
TTI::TargetCostKind CostKind, bool ForPoisonSrc,
634+
ArrayRef<Value *> VL) const {
634635
return TTIImpl->getScalarizationOverhead(Ty, DemandedElts, Insert, Extract,
635-
CostKind, VL);
636+
CostKind, ForPoisonSrc, VL);
636637
}
637638

638639
InstructionCost TargetTransformInfo::getOperandsScalarizationOverhead(

llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3870,7 +3870,8 @@ InstructionCost AArch64TTIImpl::getVectorInstrCost(const Instruction &I,
38703870

38713871
InstructionCost AArch64TTIImpl::getScalarizationOverhead(
38723872
VectorType *Ty, const APInt &DemandedElts, bool Insert, bool Extract,
3873-
TTI::TargetCostKind CostKind, ArrayRef<Value *> VL) const {
3873+
TTI::TargetCostKind CostKind, bool ForPoisonSrc,
3874+
ArrayRef<Value *> VL) const {
38743875
if (isa<ScalableVectorType>(Ty))
38753876
return InstructionCost::getInvalid();
38763877
if (Ty->getElementType()->isFloatingPointTy())

llvm/lib/Target/AArch64/AArch64TargetTransformInfo.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,8 @@ class AArch64TTIImpl : public BasicTTIImplBase<AArch64TTIImpl> {
462462

463463
InstructionCost getScalarizationOverhead(
464464
VectorType *Ty, const APInt &DemandedElts, bool Insert, bool Extract,
465-
TTI::TargetCostKind CostKind, ArrayRef<Value *> VL = {}) const override;
465+
TTI::TargetCostKind CostKind, bool ForPoisonSrc = true,
466+
ArrayRef<Value *> VL = {}) const override;
466467

467468
/// Return the cost of the scaling factor used in the addressing
468469
/// mode represented by AM for this target, for a load/store

llvm/lib/Target/NVPTX/NVPTXTargetTransformInfo.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ class NVPTXTTIImpl : public BasicTTIImplBase<NVPTXTTIImpl> {
112112

113113
InstructionCost getScalarizationOverhead(
114114
VectorType *InTy, const APInt &DemandedElts, bool Insert, bool Extract,
115-
TTI::TargetCostKind CostKind, ArrayRef<Value *> VL = {}) const override {
115+
TTI::TargetCostKind CostKind, bool ForPoisonSrc = true,
116+
ArrayRef<Value *> VL = {}) const override {
116117
if (!InTy->getElementCount().isFixed())
117118
return InstructionCost::getInvalid();
118119

@@ -141,7 +142,8 @@ class NVPTXTTIImpl : public BasicTTIImplBase<NVPTXTTIImpl> {
141142
Insert = false;
142143
}
143144
return Cost + BaseT::getScalarizationOverhead(InTy, DemandedElts, Insert,
144-
Extract, CostKind, VL);
145+
Extract, CostKind,
146+
ForPoisonSrc, VL);
145147
}
146148

147149
void getUnrollingPreferences(Loop *L, ScalarEvolution &SE,

llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -860,7 +860,8 @@ static unsigned isM1OrSmaller(MVT VT) {
860860

861861
InstructionCost RISCVTTIImpl::getScalarizationOverhead(
862862
VectorType *Ty, const APInt &DemandedElts, bool Insert, bool Extract,
863-
TTI::TargetCostKind CostKind, ArrayRef<Value *> VL) const {
863+
TTI::TargetCostKind CostKind, bool ForPoisonSrc,
864+
ArrayRef<Value *> VL) const {
864865
if (isa<ScalableVectorType>(Ty))
865866
return InstructionCost::getInvalid();
866867

llvm/lib/Target/RISCV/RISCVTargetTransformInfo.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,8 @@ class RISCVTTIImpl : public BasicTTIImplBase<RISCVTTIImpl> {
168168

169169
InstructionCost getScalarizationOverhead(
170170
VectorType *Ty, const APInt &DemandedElts, bool Insert, bool Extract,
171-
TTI::TargetCostKind CostKind, ArrayRef<Value *> VL = {}) const override;
171+
TTI::TargetCostKind CostKind, bool ForPoisonSrc = true,
172+
ArrayRef<Value *> VL = {}) const override;
172173

173174
InstructionCost
174175
getIntrinsicInstrCost(const IntrinsicCostAttributes &ICA,

llvm/lib/Target/SystemZ/SystemZTargetTransformInfo.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,8 @@ static bool isFreeEltLoad(Value *Op) {
507507

508508
InstructionCost SystemZTTIImpl::getScalarizationOverhead(
509509
VectorType *Ty, const APInt &DemandedElts, bool Insert, bool Extract,
510-
TTI::TargetCostKind CostKind, ArrayRef<Value *> VL) const {
510+
TTI::TargetCostKind CostKind, bool ForPoisonSrc,
511+
ArrayRef<Value *> VL) const {
511512
unsigned NumElts = cast<FixedVectorType>(Ty)->getNumElements();
512513
InstructionCost Cost = 0;
513514

@@ -529,7 +530,7 @@ InstructionCost SystemZTTIImpl::getScalarizationOverhead(
529530
}
530531

531532
Cost += BaseT::getScalarizationOverhead(Ty, DemandedElts, Insert, Extract,
532-
CostKind, VL);
533+
CostKind, ForPoisonSrc, VL);
533534
return Cost;
534535
}
535536

0 commit comments

Comments
 (0)