[llvm] 7d6017f - [TTI] Change new getVectorInstrCost overload to use const reference after D131114
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 4 15:16:56 PDT 2022
Author: Fangrui Song
Date: 2022-08-04T15:16:51-07:00
New Revision: 7d6017fd311280937726e565655fdd5a5c4d0e4d
URL: https://github.com/llvm/llvm-project/commit/7d6017fd311280937726e565655fdd5a5c4d0e4d
DIFF: https://github.com/llvm/llvm-project/commit/7d6017fd311280937726e565655fdd5a5c4d0e4d.diff
LOG: [TTI] Change new getVectorInstrCost overload to use const reference after D131114
A const reference is preferred over a non-null const pointer.
`Type *` is kept as is to match the other overload.
Reviewed By: davidxl
Differential Revision: https://reviews.llvm.org/D131197
Added:
Modified:
llvm/include/llvm/Analysis/TargetTransformInfo.h
llvm/include/llvm/Analysis/TargetTransformInfoImpl.h
llvm/include/llvm/CodeGen/BasicTTIImpl.h
llvm/lib/Analysis/TargetTransformInfo.cpp
llvm/lib/CodeGen/CodeGenPrepare.cpp
llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
llvm/lib/Transforms/Vectorize/VectorCombine.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/Analysis/TargetTransformInfo.h b/llvm/include/llvm/Analysis/TargetTransformInfo.h
index 13c9a2eaeefaf..43c2fce688452 100644
--- a/llvm/include/llvm/Analysis/TargetTransformInfo.h
+++ b/llvm/include/llvm/Analysis/TargetTransformInfo.h
@@ -1178,7 +1178,7 @@ class TargetTransformInfo {
///
/// A typical suitable use case is cost estimation when vector instruction
/// exists (e.g., from basic blocks during transformation).
- InstructionCost getVectorInstrCost(const Instruction *I, Type *Val,
+ InstructionCost getVectorInstrCost(const Instruction &I, Type *Val,
unsigned Index = -1) const;
/// \return The cost of replication shuffle of \p VF elements typed \p EltTy
@@ -1759,7 +1759,7 @@ class TargetTransformInfo::Concept {
const Instruction *I) = 0;
virtual InstructionCost getVectorInstrCost(unsigned Opcode, Type *Val,
unsigned Index) = 0;
- virtual InstructionCost getVectorInstrCost(const Instruction *I, Type *Val,
+ virtual InstructionCost getVectorInstrCost(const Instruction &I, Type *Val,
unsigned Index) = 0;
virtual InstructionCost
@@ -2319,7 +2319,7 @@ class TargetTransformInfo::Model final : public TargetTransformInfo::Concept {
unsigned Index) override {
return Impl.getVectorInstrCost(Opcode, Val, Index);
}
- InstructionCost getVectorInstrCost(const Instruction *I, Type *Val,
+ InstructionCost getVectorInstrCost(const Instruction &I, Type *Val,
unsigned Index) override {
return Impl.getVectorInstrCost(I, Val, Index);
}
diff --git a/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h b/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h
index 514a970c59997..55b3b53a19a88 100644
--- a/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h
+++ b/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h
@@ -575,7 +575,7 @@ class TargetTransformInfoImplBase {
return 1;
}
- InstructionCost getVectorInstrCost(const Instruction *I, Type *Val,
+ InstructionCost getVectorInstrCost(const Instruction &I, Type *Val,
unsigned Index) const {
return 1;
}
@@ -1153,7 +1153,7 @@ class TargetTransformInfoImplCRTPBase : public TargetTransformInfoImplBase {
if (auto *CI = dyn_cast<ConstantInt>(IE->getOperand(2)))
if (CI->getValue().getActiveBits() <= 32)
Idx = CI->getZExtValue();
- return TargetTTI->getVectorInstrCost(IE, Ty, Idx);
+ return TargetTTI->getVectorInstrCost(*IE, Ty, Idx);
}
case Instruction::ShuffleVector: {
auto *Shuffle = dyn_cast<ShuffleVectorInst>(U);
@@ -1243,7 +1243,7 @@ class TargetTransformInfoImplCRTPBase : public TargetTransformInfoImplBase {
if (CI->getValue().getActiveBits() <= 32)
Idx = CI->getZExtValue();
Type *DstTy = U->getOperand(0)->getType();
- return TargetTTI->getVectorInstrCost(EEI, DstTy, Idx);
+ return TargetTTI->getVectorInstrCost(*EEI, DstTy, Idx);
}
}
// By default, just classify everything as 'basic'.
diff --git a/llvm/include/llvm/CodeGen/BasicTTIImpl.h b/llvm/include/llvm/CodeGen/BasicTTIImpl.h
index 2b092d48121e3..22ad98151dc9b 100644
--- a/llvm/include/llvm/CodeGen/BasicTTIImpl.h
+++ b/llvm/include/llvm/CodeGen/BasicTTIImpl.h
@@ -1159,9 +1159,9 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
return LT.first;
}
- InstructionCost getVectorInstrCost(const Instruction *I, Type *Val,
+ InstructionCost getVectorInstrCost(const Instruction &I, Type *Val,
unsigned Index) {
- return thisT()->getVectorInstrCost(I->getOpcode(), Val, Index);
+ return thisT()->getVectorInstrCost(I.getOpcode(), Val, Index);
}
InstructionCost getReplicationShuffleCost(Type *EltTy, int ReplicationFactor,
diff --git a/llvm/lib/Analysis/TargetTransformInfo.cpp b/llvm/lib/Analysis/TargetTransformInfo.cpp
index c86279eae9a52..74b1083397bef 100644
--- a/llvm/lib/Analysis/TargetTransformInfo.cpp
+++ b/llvm/lib/Analysis/TargetTransformInfo.cpp
@@ -877,10 +877,9 @@ InstructionCost TargetTransformInfo::getVectorInstrCost(unsigned Opcode,
return Cost;
}
-InstructionCost TargetTransformInfo::getVectorInstrCost(const Instruction *I,
+InstructionCost TargetTransformInfo::getVectorInstrCost(const Instruction &I,
Type *Val,
unsigned Index) const {
- assert((I != nullptr) && "Expect not-null instruction pointer");
// FIXME: Assert that Opcode is either InsertElement or ExtractElement.
// This is mentioned in the interface description and respected by all
// callers, but never asserted upon.
diff --git a/llvm/lib/CodeGen/CodeGenPrepare.cpp b/llvm/lib/CodeGen/CodeGenPrepare.cpp
index 57423ffbae138..0d899918604b2 100644
--- a/llvm/lib/CodeGen/CodeGenPrepare.cpp
+++ b/llvm/lib/CodeGen/CodeGenPrepare.cpp
@@ -7261,7 +7261,7 @@ class VectorPromoteHelper {
// scalar to vector.
// The vector chain has to account for the combining cost.
InstructionCost ScalarCost =
- TTI.getVectorInstrCost(Transition, PromotedType, Index);
+ TTI.getVectorInstrCost(*Transition, PromotedType, Index);
InstructionCost VectorCost = StoreExtractCombineCost;
enum TargetTransformInfo::TargetCostKind CostKind =
TargetTransformInfo::TCK_RecipThroughput;
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index 737fcb386764e..232d1517ce489 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -5882,7 +5882,7 @@ InstructionCost BoUpSLP::getEntryCost(const TreeEntry *E,
continue;
}
}
- Cost -= TTIRef.getVectorInstrCost(EE, EE->getVectorOperandType(), Idx);
+ Cost -= TTIRef.getVectorInstrCost(*EE, EE->getVectorOperandType(), Idx);
}
// Add a cost for subvector extracts/inserts if required.
for (const auto &Data : ExtractVectorsTys) {
@@ -6116,7 +6116,7 @@ InstructionCost BoUpSLP::getEntryCost(const TreeEntry *E,
if (ShuffleOrOp == Instruction::ExtractElement) {
auto *EE = cast<ExtractElementInst>(VL[I]);
CommonCost -= TTI->getVectorInstrCost(
- EE, EE->getVectorOperandType(), *getExtractIndex(EE));
+ *EE, EE->getVectorOperandType(), *getExtractIndex(EE));
} else {
CommonCost -= TTI->getVectorInstrCost(Instruction::ExtractElement,
VecTy, Idx);
@@ -6128,7 +6128,7 @@ InstructionCost BoUpSLP::getEntryCost(const TreeEntry *E,
if (ShuffleOrOp == Instruction::ExtractElement) {
auto *EE = cast<ExtractElementInst>(V);
CommonCost += TTI->getVectorInstrCost(
- EE, EE->getVectorOperandType(), *getExtractIndex(EE));
+ *EE, EE->getVectorOperandType(), *getExtractIndex(EE));
} else {
--Idx;
CommonCost += TTI->getVectorInstrCost(Instruction::ExtractElement,
diff --git a/llvm/lib/Transforms/Vectorize/VectorCombine.cpp b/llvm/lib/Transforms/Vectorize/VectorCombine.cpp
index 37901d8bce4d2..0107a55b07f25 100644
--- a/llvm/lib/Transforms/Vectorize/VectorCombine.cpp
+++ b/llvm/lib/Transforms/Vectorize/VectorCombine.cpp
@@ -270,8 +270,8 @@ ExtractElementInst *VectorCombine::getShuffleExtract(
Type *VecTy = Ext0->getVectorOperand()->getType();
assert(VecTy == Ext1->getVectorOperand()->getType() && "Need matching types");
- InstructionCost Cost0 = TTI.getVectorInstrCost(Ext0, VecTy, Index0);
- InstructionCost Cost1 = TTI.getVectorInstrCost(Ext1, VecTy, Index1);
+ InstructionCost Cost0 = TTI.getVectorInstrCost(*Ext0, VecTy, Index0);
+ InstructionCost Cost1 = TTI.getVectorInstrCost(*Ext1, VecTy, Index1);
// If both costs are invalid no shuffle is needed
if (!Cost0.isValid() && !Cost1.isValid())
@@ -335,8 +335,10 @@ bool VectorCombine::isExtractExtractCheap(ExtractElementInst *Ext0,
unsigned Ext0Index = Ext0IndexC->getZExtValue();
unsigned Ext1Index = Ext1IndexC->getZExtValue();
- InstructionCost Extract0Cost = TTI.getVectorInstrCost(Ext0, VecTy, Ext0Index);
- InstructionCost Extract1Cost = TTI.getVectorInstrCost(Ext1, VecTy, Ext1Index);
+ InstructionCost Extract0Cost =
+ TTI.getVectorInstrCost(*Ext0, VecTy, Ext0Index);
+ InstructionCost Extract1Cost =
+ TTI.getVectorInstrCost(*Ext1, VecTy, Ext1Index);
// A more expensive extract will always be replaced by a splat shuffle.
// For example, if Ext0 is more expensive:
@@ -750,8 +752,8 @@ bool VectorCombine::foldExtractedCmps(Instruction &I) {
if (!VecTy)
return false;
- InstructionCost OldCost = TTI.getVectorInstrCost(Ext0, VecTy, Index0);
- OldCost += TTI.getVectorInstrCost(Ext1, VecTy, Index1);
+ InstructionCost OldCost = TTI.getVectorInstrCost(*Ext0, VecTy, Index0);
+ OldCost += TTI.getVectorInstrCost(*Ext1, VecTy, Index1);
OldCost +=
TTI.getCmpSelInstrCost(CmpOpcode, I0->getType(),
CmpInst::makeCmpResultType(I0->getType()), Pred) *
@@ -771,7 +773,7 @@ bool VectorCombine::foldExtractedCmps(Instruction &I) {
NewCost += TTI.getShuffleCost(TargetTransformInfo::SK_PermuteSingleSrc, CmpTy,
ShufMask);
NewCost += TTI.getArithmeticInstrCost(I.getOpcode(), CmpTy);
- NewCost += TTI.getVectorInstrCost(Ext0, CmpTy, CheapIndex);
+ NewCost += TTI.getVectorInstrCost(*Ext0, CmpTy, CheapIndex);
// Aggressively form vector ops if the cost is equal because the transform
// may enable further optimization.
More information about the llvm-commits
mailing list