Skip to content

Commit 04ff13c

Browse files
committed
[VPlan] Get Addr computation cost with scalar type if it is uniform for gather/scatter.
This patch query `getAddressComputationCost()` with scalar type if the address is uniform. This can help the cost for gather/scatter more accurate. In current LV, non consecutive VPWidenMemoryRecipe (gather/scatter) will account the cost of address computation. But there are some cases that the addr is uniform accross lanes, that makes the address can be calculated with scalar type and broadcast. I have a follow optimization that try to converts gather/scatter with uniform memory acces to scalar load/store + broadcast. With this optimization, we can remove this temporary change.
1 parent af0f85c commit 04ff13c

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3182,10 +3182,17 @@ InstructionCost VPWidenMemoryRecipe::computeCost(ElementCount VF,
31823182
// TODO: Using the original IR may not be accurate.
31833183
// Currently, ARM will use the underlying IR to calculate gather/scatter
31843184
// instruction cost.
3185-
const Value *Ptr = getLoadStorePointerOperand(&Ingredient);
3186-
Type *PtrTy = toVectorTy(Ptr->getType(), VF);
31873185
assert(!Reverse &&
31883186
"Inconsecutive memory access should not have the order.");
3187+
3188+
const Value *Ptr = getLoadStorePointerOperand(&Ingredient);
3189+
Type *PtrTy = Ptr->getType();
3190+
3191+
// If the address value is uniform across all lanes, then the address can be
3192+
// calculated with scalar type and broadcast.
3193+
if (!vputils::isSingleScalar(getAddr()))
3194+
PtrTy = toVectorTy(PtrTy, VF);
3195+
31893196
return Ctx.TTI.getAddressComputationCost(PtrTy, nullptr, nullptr,
31903197
Ctx.CostKind) +
31913198
Ctx.TTI.getGatherScatterOpCost(Opcode, Ty, Ptr, IsMasked, Alignment,

0 commit comments

Comments
 (0)