Skip to content

Commit acb86fb

Browse files
authored
[TTI] Consistently pass the pointer type to getAddressComputationCost. NFCI (llvm#152657)
In some places we were passing the type of value being accessed, in other cases we were passing the type of the pointer for the access. The most "involved" user is LoopVectorizationCostModel::getMemInstScalarizationCost, which is the only call site that passes in the SCEV, and it passes along the pointer type. This changes call sites to consistently pass the pointer type, and renames the arguments to clarify this. No target actually checks the contents of the type passed, only to see if it's a vector or not, so this shouldn't have an effect.
1 parent d1e6923 commit acb86fb

14 files changed

+36
-30
lines changed

llvm/include/llvm/Analysis/TargetTransformInfo.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1675,13 +1675,14 @@ class TargetTransformInfo {
16751675

16761676
/// \returns The cost of the address computation. For most targets this can be
16771677
/// merged into the instruction indexing mode. Some targets might want to
1678-
/// distinguish between address computation for memory operations on vector
1679-
/// types and scalar types. Such targets should override this function.
1680-
/// The 'SE' parameter holds pointer for the scalar evolution object which
1681-
/// is used in order to get the Ptr step value in case of constant stride.
1682-
/// The 'Ptr' parameter holds SCEV of the access pointer.
1683-
LLVM_ABI InstructionCost getAddressComputationCost(
1684-
Type *Ty, ScalarEvolution *SE = nullptr, const SCEV *Ptr = nullptr) const;
1678+
/// distinguish between address computation for memory operations with vector
1679+
/// pointer types and scalar pointer types. Such targets should override this
1680+
/// function. \p SE holds the pointer for the scalar evolution object which
1681+
/// was used in order to get the Ptr step value. \p Ptr holds the SCEV of the
1682+
/// access pointer.
1683+
LLVM_ABI InstructionCost
1684+
getAddressComputationCost(Type *PtrTy, ScalarEvolution *SE = nullptr,
1685+
const SCEV *Ptr = nullptr) const;
16851686

16861687
/// \returns The cost, if any, of keeping values of the given types alive
16871688
/// over a callsite.

llvm/include/llvm/Analysis/TargetTransformInfoImpl.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -937,7 +937,8 @@ class TargetTransformInfoImplBase {
937937
// Assume that we have a register of the right size for the type.
938938
virtual unsigned getNumberOfParts(Type *Tp) const { return 1; }
939939

940-
virtual InstructionCost getAddressComputationCost(Type *Tp, ScalarEvolution *,
940+
virtual InstructionCost getAddressComputationCost(Type *PtrTy,
941+
ScalarEvolution *,
941942
const SCEV *) const {
942943
return 0;
943944
}

llvm/include/llvm/CodeGen/BasicTTIImpl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3026,7 +3026,7 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
30263026
return LT.first.getValue();
30273027
}
30283028

3029-
InstructionCost getAddressComputationCost(Type *Ty, ScalarEvolution *,
3029+
InstructionCost getAddressComputationCost(Type *PtrTy, ScalarEvolution *,
30303030
const SCEV *) const override {
30313031
return 0;
30323032
}

llvm/lib/Analysis/TargetTransformInfo.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1231,9 +1231,9 @@ unsigned TargetTransformInfo::getNumberOfParts(Type *Tp) const {
12311231
}
12321232

12331233
InstructionCost
1234-
TargetTransformInfo::getAddressComputationCost(Type *Tp, ScalarEvolution *SE,
1234+
TargetTransformInfo::getAddressComputationCost(Type *PtrTy, ScalarEvolution *SE,
12351235
const SCEV *Ptr) const {
1236-
InstructionCost Cost = TTIImpl->getAddressComputationCost(Tp, SE, Ptr);
1236+
InstructionCost Cost = TTIImpl->getAddressComputationCost(PtrTy, SE, Ptr);
12371237
assert(Cost >= 0 && "TTI should not produce negative costs!");
12381238
return Cost;
12391239
}

llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4336,7 +4336,7 @@ InstructionCost AArch64TTIImpl::getArithmeticInstrCost(
43364336
}
43374337

43384338
InstructionCost
4339-
AArch64TTIImpl::getAddressComputationCost(Type *Ty, ScalarEvolution *SE,
4339+
AArch64TTIImpl::getAddressComputationCost(Type *PtrTy, ScalarEvolution *SE,
43404340
const SCEV *Ptr) const {
43414341
// Address computations in vectorized code with non-consecutive addresses will
43424342
// likely result in more instructions compared to scalar code where the
@@ -4345,7 +4345,7 @@ AArch64TTIImpl::getAddressComputationCost(Type *Ty, ScalarEvolution *SE,
43454345
unsigned NumVectorInstToHideOverhead = NeonNonConstStrideOverhead;
43464346
int MaxMergeDistance = 64;
43474347

4348-
if (Ty->isVectorTy() && SE &&
4348+
if (PtrTy->isVectorTy() && SE &&
43494349
!BaseT::isConstantStridedAccessLessThan(SE, Ptr, MaxMergeDistance + 1))
43504350
return NumVectorInstToHideOverhead;
43514351

llvm/lib/Target/AArch64/AArch64TargetTransformInfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ class AArch64TTIImpl final : public BasicTTIImplBase<AArch64TTIImpl> {
238238
ArrayRef<const Value *> Args = {},
239239
const Instruction *CxtI = nullptr) const override;
240240

241-
InstructionCost getAddressComputationCost(Type *Ty, ScalarEvolution *SE,
241+
InstructionCost getAddressComputationCost(Type *PtrTy, ScalarEvolution *SE,
242242
const SCEV *Ptr) const override;
243243

244244
InstructionCost getCmpSelInstrCost(

llvm/lib/Target/ARM/ARMTargetTransformInfo.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,7 +1084,7 @@ InstructionCost ARMTTIImpl::getCmpSelInstrCost(
10841084
CostKind, Op1Info, Op2Info, I);
10851085
}
10861086

1087-
InstructionCost ARMTTIImpl::getAddressComputationCost(Type *Ty,
1087+
InstructionCost ARMTTIImpl::getAddressComputationCost(Type *PtrTy,
10881088
ScalarEvolution *SE,
10891089
const SCEV *Ptr) const {
10901090
// Address computations in vectorized code with non-consecutive addresses will
@@ -1095,15 +1095,15 @@ InstructionCost ARMTTIImpl::getAddressComputationCost(Type *Ty,
10951095
int MaxMergeDistance = 64;
10961096

10971097
if (ST->hasNEON()) {
1098-
if (Ty->isVectorTy() && SE &&
1098+
if (PtrTy->isVectorTy() && SE &&
10991099
!BaseT::isConstantStridedAccessLessThan(SE, Ptr, MaxMergeDistance + 1))
11001100
return NumVectorInstToHideOverhead;
11011101

11021102
// In many cases the address computation is not merged into the instruction
11031103
// addressing mode.
11041104
return 1;
11051105
}
1106-
return BaseT::getAddressComputationCost(Ty, SE, Ptr);
1106+
return BaseT::getAddressComputationCost(PtrTy, SE, Ptr);
11071107
}
11081108

11091109
bool ARMTTIImpl::isProfitableLSRChainElement(Instruction *I) const {

llvm/lib/Target/Hexagon/HexagonTargetTransformInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ HexagonTTIImpl::getIntrinsicInstrCost(const IntrinsicCostAttributes &ICA,
156156
return BaseT::getIntrinsicInstrCost(ICA, CostKind);
157157
}
158158

159-
InstructionCost HexagonTTIImpl::getAddressComputationCost(Type *Tp,
159+
InstructionCost HexagonTTIImpl::getAddressComputationCost(Type *PtrTy,
160160
ScalarEvolution *SE,
161161
const SCEV *S) const {
162162
return 0;

llvm/lib/Target/Hexagon/HexagonTargetTransformInfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ class HexagonTTIImpl final : public BasicTTIImplBase<HexagonTTIImpl> {
111111
InstructionCost
112112
getIntrinsicInstrCost(const IntrinsicCostAttributes &ICA,
113113
TTI::TargetCostKind CostKind) const override;
114-
InstructionCost getAddressComputationCost(Type *Tp, ScalarEvolution *SE,
114+
InstructionCost getAddressComputationCost(Type *PtrTy, ScalarEvolution *SE,
115115
const SCEV *S) const override;
116116
InstructionCost getMemoryOpCost(
117117
unsigned Opcode, Type *Src, Align Alignment, unsigned AddressSpace,

llvm/lib/Target/X86/X86TargetTransformInfo.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5488,7 +5488,7 @@ InstructionCost X86TTIImpl::getPointersChainCost(
54885488
return BaseT::getPointersChainCost(Ptrs, Base, Info, AccessTy, CostKind);
54895489
}
54905490

5491-
InstructionCost X86TTIImpl::getAddressComputationCost(Type *Ty,
5491+
InstructionCost X86TTIImpl::getAddressComputationCost(Type *PtrTy,
54925492
ScalarEvolution *SE,
54935493
const SCEV *Ptr) const {
54945494
// Address computations in vectorized code with non-consecutive addresses will
@@ -5504,7 +5504,7 @@ InstructionCost X86TTIImpl::getAddressComputationCost(Type *Ty,
55045504
// Even in the case of (loop invariant) stride whose value is not known at
55055505
// compile time, the address computation will not incur more than one extra
55065506
// ADD instruction.
5507-
if (Ty->isVectorTy() && SE && !ST->hasAVX2()) {
5507+
if (PtrTy->isVectorTy() && SE && !ST->hasAVX2()) {
55085508
// TODO: AVX2 is the current cut-off because we don't have correct
55095509
// interleaving costs for prior ISA's.
55105510
if (!BaseT::isStridedAccess(Ptr))
@@ -5513,7 +5513,7 @@ InstructionCost X86TTIImpl::getAddressComputationCost(Type *Ty,
55135513
return 1;
55145514
}
55155515

5516-
return BaseT::getAddressComputationCost(Ty, SE, Ptr);
5516+
return BaseT::getAddressComputationCost(PtrTy, SE, Ptr);
55175517
}
55185518

55195519
InstructionCost

0 commit comments

Comments
 (0)