Skip to content

Commit ba4ce60

Browse files
authored
[LV] Add scalar load/stores to VPReplicateRecipe::computeCost (#153218)
Avoid calling getLegacyCost for single scalar loads and stores where the cost is trivial to calculate.
1 parent c0562ff commit ba4ce60

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3158,6 +3158,24 @@ InstructionCost VPReplicateRecipe::computeCost(ElementCount VF,
31583158
return *getCostForRecipeWithOpcode(getOpcode(), ElementCount::getFixed(1),
31593159
Ctx) *
31603160
(isSingleScalar() ? 1 : VF.getFixedValue());
3161+
case Instruction::Load:
3162+
case Instruction::Store: {
3163+
if (isSingleScalar()) {
3164+
bool IsLoad = UI->getOpcode() == Instruction::Load;
3165+
Type *ValTy = Ctx.Types.inferScalarType(IsLoad ? this : getOperand(0));
3166+
Type *ScalarPtrTy = Ctx.Types.inferScalarType(getOperand(IsLoad ? 0 : 1));
3167+
const Align Alignment = getLoadStoreAlignment(UI);
3168+
unsigned AS = getLoadStoreAddressSpace(UI);
3169+
TTI::OperandValueInfo OpInfo = TTI::getOperandInfo(UI->getOperand(0));
3170+
InstructionCost ScalarMemOpCost = Ctx.TTI.getMemoryOpCost(
3171+
UI->getOpcode(), ValTy, Alignment, AS, Ctx.CostKind, OpInfo, UI);
3172+
return ScalarMemOpCost + Ctx.TTI.getAddressComputationCost(
3173+
ScalarPtrTy, nullptr, nullptr, Ctx.CostKind);
3174+
}
3175+
// TODO: See getMemInstScalarizationCost for how to handle replicating and
3176+
// predicated cases.
3177+
break;
3178+
}
31613179
}
31623180

31633181
return Ctx.getLegacyCost(UI, VF);

0 commit comments

Comments
 (0)