-
Notifications
You must be signed in to change notification settings - Fork 14.9k
[LV] Add scalar load/stores to VPReplicateRecipe::computeCost #153218
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
@llvm/pr-subscribers-vectorizers @llvm/pr-subscribers-llvm-transforms Author: David Sherwood (david-arm) ChangesAvoid calling getLegacyCost for single scalar loads and stores where the cost is trivial to calculate. Full diff: https://github.com/llvm/llvm-project/pull/153218.diff 1 Files Affected:
diff --git a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
index e34cab117f321..b301aee6dad23 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
@@ -2975,6 +2975,22 @@ InstructionCost VPReplicateRecipe::computeCost(ElementCount VF,
Op2Info, Operands, UI, &Ctx.TLI) *
(isSingleScalar() ? 1 : VF.getFixedValue());
}
+ case Instruction::Load:
+ case Instruction::Store: {
+ if (isSingleScalar()) {
+ Type *ValTy = getLoadStoreType(UI);
+ Type *ScalarPtrTy = getLoadStorePointerOperand(UI)->getType();
+ const Align Alignment = getLoadStoreAlignment(UI);
+ unsigned AS = getLoadStoreAddressSpace(UI);
+ TTI::OperandValueInfo OpInfo = TTI::getOperandInfo(UI->getOperand(0));
+ InstructionCost ScalarMemOpCost = Ctx.TTI.getMemoryOpCost(
+ UI->getOpcode(), ValTy, Alignment, AS, CostKind, OpInfo, UI);
+ return ScalarMemOpCost + Ctx.TTI.getAddressComputationCost(ScalarPtrTy);
+ }
+ // TODO: See getMemInstScalarizationCost for how to handle vector and
+ // predicated cases.
+ break;
+ }
}
return Ctx.getLegacyCost(UI, VF);
|
Gentle ping. :) |
UI->getOpcode(), ValTy, Alignment, AS, CostKind, OpInfo, UI); | ||
return ScalarMemOpCost + Ctx.TTI.getAddressComputationCost(ScalarPtrTy); | ||
} | ||
// TODO: See getMemInstScalarizationCost for how to handle vector and |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// TODO: See getMemInstScalarizationCost for how to handle vector and | |
// TODO: See getMemInstScalarizationCost for how to handle replicating and |
This code here won't handle vector cases?
Type *ValTy = getLoadStoreType(UI); | ||
Type *ScalarPtrTy = getLoadStorePointerOperand(UI)->getType(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we get this from the VPlan type analysis?
Avoid calling getLegacyCost for single scalar loads and stores where the cost is trivial to calculate.
a4e0e92
to
fd7bf4b
Compare
// TODO: Is this right? Operand 0 has a different meaning for loads and | ||
// stores. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is indeed confusing and the argument isn't documented, but it looks like in RISCV TTI and X86 TTI (https://github.com/llvm/llvm-project/blob/main/llvm/lib/Target/X86/X86TargetTransformInfo.cpp#L5241) the argument is used as it is passed here: stored value for stores, address for loads. AArch64 and ARM TTIs don't use it.
So it seems it is used as expected, even though the documentation of the interface could be improved
Avoid calling getLegacyCost for single scalar loads and stores where the cost is trivial to calculate.