Skip to content

Commit 026e9d3

Browse files
committed
Fixups
1 parent dcfbaee commit 026e9d3

File tree

5 files changed

+50
-4
lines changed

5 files changed

+50
-4
lines changed

llvm/include/llvm/Analysis/TargetTransformInfo.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1468,6 +1468,15 @@ class TargetTransformInfo {
14681468
TTI::TargetCostKind CostKind,
14691469
unsigned Index = -1) const;
14701470

1471+
/// \return The expected of aggregate inserts and extracts. Use an empty
1472+
/// ArrayRef to indicate that there is no information on the indices. This is
1473+
/// used when the instruction is not available; a typical use case is to
1474+
/// provision the cost of vectorization/scalarization in vectorizer passes.
1475+
InstructionCost getInsertExtractValueCost(unsigned Opcode, Type *AggType,
1476+
TTI::TargetCostKind CostKind,
1477+
ArrayRef<unsigned> Indices,
1478+
Value *AggDef = nullptr) const;
1479+
14711480
/// \return The cost of replication shuffle of \p VF elements typed \p EltTy
14721481
/// \p ReplicationFactor times.
14731482
///
@@ -2200,6 +2209,11 @@ class TargetTransformInfo::Concept {
22002209
const APInt &DemandedDstElts,
22012210
TTI::TargetCostKind CostKind) = 0;
22022211

2212+
virtual InstructionCost
2213+
getInsertExtractValueCost(unsigned Opcode, Type *AggType,
2214+
TTI::TargetCostKind CostKind,
2215+
ArrayRef<unsigned> Indices, Value *AggDef) = 0;
2216+
22032217
virtual InstructionCost
22042218
getMemoryOpCost(unsigned Opcode, Type *Src, Align Alignment,
22052219
unsigned AddressSpace, TTI::TargetCostKind CostKind,
@@ -2921,6 +2935,13 @@ class TargetTransformInfo::Model final : public TargetTransformInfo::Concept {
29212935
return Impl.getReplicationShuffleCost(EltTy, ReplicationFactor, VF,
29222936
DemandedDstElts, CostKind);
29232937
}
2938+
InstructionCost getInsertExtractValueCost(unsigned Opcode, Type *AggType,
2939+
TTI::TargetCostKind CostKind,
2940+
ArrayRef<unsigned> Indices,
2941+
Value *AggDef) override {
2942+
return Impl.getInsertExtractValueCost(Opcode, AggType, CostKind, Indices,
2943+
AggDef);
2944+
}
29242945
InstructionCost getMemoryOpCost(unsigned Opcode, Type *Src, Align Alignment,
29252946
unsigned AddressSpace,
29262947
TTI::TargetCostKind CostKind,

llvm/include/llvm/Analysis/TargetTransformInfoImpl.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,13 @@ class TargetTransformInfoImplBase {
745745
return 1;
746746
}
747747

748+
InstructionCost getInsertExtractValueCost(unsigned Opcode, Type *AggType,
749+
TTI::TargetCostKind CostKind,
750+
ArrayRef<unsigned> Indices,
751+
Value *AggDef) const {
752+
return 0;
753+
}
754+
748755
InstructionCost getMemoryOpCost(unsigned Opcode, Type *Src, Align Alignment,
749756
unsigned AddressSpace,
750757
TTI::TargetCostKind CostKind,

llvm/lib/Analysis/TargetTransformInfo.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1113,6 +1113,18 @@ TargetTransformInfo::getVectorInstrCost(const Instruction &I, Type *Val,
11131113
return Cost;
11141114
}
11151115

1116+
InstructionCost TargetTransformInfo::getInsertExtractValueCost(
1117+
unsigned Opcode, Type *AggType, TTI::TargetCostKind CostKind,
1118+
ArrayRef<unsigned> Indices, Value *AggDef) const {
1119+
assert((Opcode == Instruction::InsertValue ||
1120+
Opcode == Instruction::ExtractValue) &&
1121+
"Expecting Opcode to be insertvalue/extractvalue.");
1122+
InstructionCost Cost = TTIImpl->getInsertExtractValueCost(
1123+
Opcode, AggType, CostKind, Indices, AggDef);
1124+
assert(Cost >= 0 && "TTI should not produce negative costs!");
1125+
return Cost;
1126+
}
1127+
11161128
InstructionCost TargetTransformInfo::getReplicationShuffleCost(
11171129
Type *EltTy, int ReplicationFactor, int VF, const APInt &DemandedDstElts,
11181130
TTI::TargetCostKind CostKind) const {

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3605,13 +3605,13 @@ void LoopVectorizationCostModel::collectLoopUniforms(ElementCount VF) {
36053605
}
36063606
}
36073607

3608-
// ExtractValue instructions must be uniform, because the operands are
3609-
// known to be loop-invariant.
36103608
if (auto *EVI = dyn_cast<ExtractValueInst>(&I)) {
36113609
if (IsOutOfScope(EVI->getAggregateOperand())) {
36123610
AddToWorklistIfAllowed(EVI);
36133611
continue;
36143612
}
3613+
// Only ExtractValue instructions where the aggregate value comes from a
3614+
// call are allowed to be non-uniform.
36153615
assert(isa<CallInst>(EVI->getAggregateOperand()) &&
36163616
"Expected aggregate value to be call return value");
36173617
}

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1514,8 +1514,14 @@ InstructionCost VPWidenRecipe::computeCost(ElementCount VF,
15141514
return Ctx.TTI.getArithmeticInstrCost(Instruction::Mul, VectorTy,
15151515
Ctx.CostKind);
15161516
}
1517-
case Instruction::ExtractValue:
1518-
return 0;
1517+
case Instruction::ExtractValue: {
1518+
assert(getNumOperands() == 2 && "expected single level extractvalue");
1519+
Type *VectorizedTy = toVectorizedTy(Ctx.Types.inferScalarType(this), VF);
1520+
auto *CI = cast<ConstantInt>(getOperand(1)->getLiveInIRValue());
1521+
return Ctx.TTI.getInsertExtractValueCost(
1522+
Instruction::ExtractValue, VectorizedTy, Ctx.CostKind,
1523+
static_cast<unsigned>(CI->getZExtValue()));
1524+
}
15191525
case Instruction::ICmp:
15201526
case Instruction::FCmp: {
15211527
Instruction *CtxI = dyn_cast_or_null<Instruction>(getUnderlyingValue());

0 commit comments

Comments
 (0)