From 220bc1077d7fc0c0f1e5e6103e056d6583ac3c27 Mon Sep 17 00:00:00 2001 From: Craig Topper Date: Tue, 4 Mar 2025 15:44:40 -0800 Subject: [PATCH] [TTI] getScalingFactorCost should return InstructionCost::getInvalid() instead of -1. Historically this function return an int, with negative values meaning invalid. It was migrated to InstructionCost in 43ace8b5ce07a, but the code was not updated to use invalid cost. In that commit, the caller in LSR was updated to assert that the cost is valid instead of positive. --- llvm/include/llvm/Analysis/TargetTransformInfoImpl.h | 2 +- llvm/include/llvm/CodeGen/BasicTTIImpl.h | 2 +- llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp | 2 +- llvm/lib/Target/AArch64/AArch64TargetTransformInfo.h | 2 +- llvm/lib/Target/ARM/ARMTargetTransformInfo.cpp | 2 +- llvm/lib/Target/ARM/ARMTargetTransformInfo.h | 2 +- llvm/lib/Target/X86/X86TargetTransformInfo.cpp | 2 +- llvm/lib/Target/X86/X86TargetTransformInfo.h | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h b/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h index a8d6dd18266bb..99bd587b03b79 100644 --- a/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h +++ b/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h @@ -364,7 +364,7 @@ class TargetTransformInfoImplBase { Scale, AddrSpace, /*I=*/nullptr, BaseOffset.getScalable())) return 0; - return -1; + return InstructionCost::getInvalid(); } bool LSRWithInstrQueries() const { return false; } diff --git a/llvm/include/llvm/CodeGen/BasicTTIImpl.h b/llvm/include/llvm/CodeGen/BasicTTIImpl.h index 563953516a354..3f03c3acddfd1 100644 --- a/llvm/include/llvm/CodeGen/BasicTTIImpl.h +++ b/llvm/include/llvm/CodeGen/BasicTTIImpl.h @@ -511,7 +511,7 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase { AM.ScalableOffset = BaseOffset.getScalable(); if (getTLI()->isLegalAddressingMode(DL, AM, Ty, AddrSpace)) return 0; - return -1; + return InstructionCost::getInvalid(); } bool isTruncateFree(Type *Ty1, Type *Ty2) { diff --git a/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp b/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp index 09a0e7ec172bf..ba019e1a4ecd5 100644 --- a/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp +++ b/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp @@ -5271,7 +5271,7 @@ AArch64TTIImpl::getScalingFactorCost(Type *Ty, GlobalValue *BaseGV, // Scale represents reg2 * scale, thus account for 1 if // it is not equal to 0 or 1. return AM.Scale != 0 && AM.Scale != 1; - return -1; + return InstructionCost::getInvalid(); } bool AArch64TTIImpl::shouldTreatInstructionLikeSelect(const Instruction *I) { diff --git a/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.h b/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.h index c7f8450213ae5..46765e7b22175 100644 --- a/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.h +++ b/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.h @@ -451,7 +451,7 @@ class AArch64TTIImpl : public BasicTTIImplBase { /// mode represented by AM for this target, for a load/store /// of the specified type. /// If the AM is supported, the return value must be >= 0. - /// If the AM is not supported, it returns a negative value. + /// If the AM is not supported, it returns an invalid cost. InstructionCost getScalingFactorCost(Type *Ty, GlobalValue *BaseGV, StackOffset BaseOffset, bool HasBaseReg, int64_t Scale, unsigned AddrSpace) const; diff --git a/llvm/lib/Target/ARM/ARMTargetTransformInfo.cpp b/llvm/lib/Target/ARM/ARMTargetTransformInfo.cpp index 6b3fa04798061..93a1316382fcc 100644 --- a/llvm/lib/Target/ARM/ARMTargetTransformInfo.cpp +++ b/llvm/lib/Target/ARM/ARMTargetTransformInfo.cpp @@ -2669,7 +2669,7 @@ InstructionCost ARMTTIImpl::getScalingFactorCost(Type *Ty, GlobalValue *BaseGV, return AM.Scale < 0 ? 1 : 0; // positive offsets execute faster return 0; } - return -1; + return InstructionCost::getInvalid(); } bool ARMTTIImpl::hasArmWideBranch(bool Thumb) const { diff --git a/llvm/lib/Target/ARM/ARMTargetTransformInfo.h b/llvm/lib/Target/ARM/ARMTargetTransformInfo.h index 3a4f940088b2e..72bd98f548187 100644 --- a/llvm/lib/Target/ARM/ARMTargetTransformInfo.h +++ b/llvm/lib/Target/ARM/ARMTargetTransformInfo.h @@ -302,7 +302,7 @@ class ARMTTIImpl : public BasicTTIImplBase { /// getScalingFactorCost - Return the cost of the scaling used in /// addressing mode represented by AM. /// If the AM is supported, the return value must be >= 0. - /// If the AM is not supported, the return value must be negative. + /// If the AM is not supported, the return value is an invalid cost. InstructionCost getScalingFactorCost(Type *Ty, GlobalValue *BaseGV, StackOffset BaseOffset, bool HasBaseReg, int64_t Scale, unsigned AddrSpace) const; diff --git a/llvm/lib/Target/X86/X86TargetTransformInfo.cpp b/llvm/lib/Target/X86/X86TargetTransformInfo.cpp index f6552c500d7cf..fb0d6d1ffa414 100644 --- a/llvm/lib/Target/X86/X86TargetTransformInfo.cpp +++ b/llvm/lib/Target/X86/X86TargetTransformInfo.cpp @@ -7057,7 +7057,7 @@ InstructionCost X86TTIImpl::getScalingFactorCost(Type *Ty, GlobalValue *BaseGV, // Scale represents reg2 * scale, thus account for 1 // as soon as we use a second register. return AM.Scale != 0; - return -1; + return InstructionCost::getInvalid(); } InstructionCost X86TTIImpl::getBranchMispredictPenalty() const { diff --git a/llvm/lib/Target/X86/X86TargetTransformInfo.h b/llvm/lib/Target/X86/X86TargetTransformInfo.h index 7786616f89aa6..8fcaee0c7017f 100644 --- a/llvm/lib/Target/X86/X86TargetTransformInfo.h +++ b/llvm/lib/Target/X86/X86TargetTransformInfo.h @@ -254,7 +254,7 @@ class X86TTIImpl : public BasicTTIImplBase { /// mode represented by AM for this target, for a load/store /// of the specified type. /// If the AM is supported, the return value must be >= 0. - /// If the AM is not supported, it returns a negative value. + /// If the AM is not supported, it returns an invalid cost. InstructionCost getScalingFactorCost(Type *Ty, GlobalValue *BaseGV, StackOffset BaseOffset, bool HasBaseReg, int64_t Scale, unsigned AddrSpace) const;