Skip to content

Commit ee2b590

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 ef50227 commit ee2b590

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
@@ -3106,10 +3106,17 @@ InstructionCost VPWidenMemoryRecipe::computeCost(ElementCount VF,
31063106
// TODO: Using the original IR may not be accurate.
31073107
// Currently, ARM will use the underlying IR to calculate gather/scatter
31083108
// instruction cost.
3109-
const Value *Ptr = getLoadStorePointerOperand(&Ingredient);
3110-
Type *PtrTy = toVectorTy(Ptr->getType(), VF);
31113109
assert(!Reverse &&
31123110
"Inconsecutive memory access should not have the order.");
3111+
3112+
const Value *Ptr = getLoadStorePointerOperand(&Ingredient);
3113+
Type *PtrTy = Ptr->getType();
3114+
3115+
// If the address value is uniform across all lane, then the address can be
3116+
// calculated with scalar type and broacast.
3117+
if (!vputils::isSingleScalar(getAddr()))
3118+
PtrTy = toVectorTy(PtrTy, VF);
3119+
31133120
return Ctx.TTI.getAddressComputationCost(PtrTy) +
31143121
Ctx.TTI.getGatherScatterOpCost(Opcode, Ty, Ptr, IsMasked, Alignment,
31153122
Ctx.CostKind, &Ingredient);

0 commit comments

Comments
 (0)