Skip to content

Commit 39c454a

Browse files
authored
[TTI] getScalingFactorCost should return InstructionCost::getInvalid() instead of -1. (#129802)
Historically this function return an int with negative values meaning invalid. It was migrated to InstructionCost in 43ace8b, but the code was not updated to return invalid cost instead of -1. In that commit, the caller in LSR was updated to assert that the cost is valid instead of positive. We should return invalid instead of a negative value so LSR will assert if the cost isn't valid.
1 parent b53e757 commit 39c454a

File tree

8 files changed

+8
-8
lines changed

8 files changed

+8
-8
lines changed

llvm/include/llvm/Analysis/TargetTransformInfoImpl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ class TargetTransformInfoImplBase {
364364
Scale, AddrSpace, /*I=*/nullptr,
365365
BaseOffset.getScalable()))
366366
return 0;
367-
return -1;
367+
return InstructionCost::getInvalid();
368368
}
369369

370370
bool LSRWithInstrQueries() const { return false; }

llvm/include/llvm/CodeGen/BasicTTIImpl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
511511
AM.ScalableOffset = BaseOffset.getScalable();
512512
if (getTLI()->isLegalAddressingMode(DL, AM, Ty, AddrSpace))
513513
return 0;
514-
return -1;
514+
return InstructionCost::getInvalid();
515515
}
516516

517517
bool isTruncateFree(Type *Ty1, Type *Ty2) {

llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5271,7 +5271,7 @@ AArch64TTIImpl::getScalingFactorCost(Type *Ty, GlobalValue *BaseGV,
52715271
// Scale represents reg2 * scale, thus account for 1 if
52725272
// it is not equal to 0 or 1.
52735273
return AM.Scale != 0 && AM.Scale != 1;
5274-
return -1;
5274+
return InstructionCost::getInvalid();
52755275
}
52765276

52775277
bool AArch64TTIImpl::shouldTreatInstructionLikeSelect(const Instruction *I) {

llvm/lib/Target/AArch64/AArch64TargetTransformInfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ class AArch64TTIImpl : public BasicTTIImplBase<AArch64TTIImpl> {
450450
/// mode represented by AM for this target, for a load/store
451451
/// of the specified type.
452452
/// If the AM is supported, the return value must be >= 0.
453-
/// If the AM is not supported, it returns a negative value.
453+
/// If the AM is not supported, it returns an invalid cost.
454454
InstructionCost getScalingFactorCost(Type *Ty, GlobalValue *BaseGV,
455455
StackOffset BaseOffset, bool HasBaseReg,
456456
int64_t Scale, unsigned AddrSpace) const;

llvm/lib/Target/ARM/ARMTargetTransformInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2668,7 +2668,7 @@ InstructionCost ARMTTIImpl::getScalingFactorCost(Type *Ty, GlobalValue *BaseGV,
26682668
return AM.Scale < 0 ? 1 : 0; // positive offsets execute faster
26692669
return 0;
26702670
}
2671-
return -1;
2671+
return InstructionCost::getInvalid();
26722672
}
26732673

26742674
bool ARMTTIImpl::hasArmWideBranch(bool Thumb) const {

llvm/lib/Target/ARM/ARMTargetTransformInfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ class ARMTTIImpl : public BasicTTIImplBase<ARMTTIImpl> {
300300
/// getScalingFactorCost - Return the cost of the scaling used in
301301
/// addressing mode represented by AM.
302302
/// If the AM is supported, the return value must be >= 0.
303-
/// If the AM is not supported, the return value must be negative.
303+
/// If the AM is not supported, the return value is an invalid cost.
304304
InstructionCost getScalingFactorCost(Type *Ty, GlobalValue *BaseGV,
305305
StackOffset BaseOffset, bool HasBaseReg,
306306
int64_t Scale, unsigned AddrSpace) const;

llvm/lib/Target/X86/X86TargetTransformInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7057,7 +7057,7 @@ InstructionCost X86TTIImpl::getScalingFactorCost(Type *Ty, GlobalValue *BaseGV,
70577057
// Scale represents reg2 * scale, thus account for 1
70587058
// as soon as we use a second register.
70597059
return AM.Scale != 0;
7060-
return -1;
7060+
return InstructionCost::getInvalid();
70617061
}
70627062

70637063
InstructionCost X86TTIImpl::getBranchMispredictPenalty() const {

llvm/lib/Target/X86/X86TargetTransformInfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ class X86TTIImpl : public BasicTTIImplBase<X86TTIImpl> {
254254
/// mode represented by AM for this target, for a load/store
255255
/// of the specified type.
256256
/// If the AM is supported, the return value must be >= 0.
257-
/// If the AM is not supported, it returns a negative value.
257+
/// If the AM is not supported, it returns an invalid cost.
258258
InstructionCost getScalingFactorCost(Type *Ty, GlobalValue *BaseGV,
259259
StackOffset BaseOffset, bool HasBaseReg,
260260
int64_t Scale, unsigned AddrSpace) const;

0 commit comments

Comments
 (0)