From a4e8347b36617ed81accbf5c5fb3b532db941f4f Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Mon, 13 Feb 2023 07:42:47 -0400 Subject: [PATCH] AMDGPU: Refactor isConstantCostlierToNegate --- llvm/lib/Target/AMDGPU/AMDGPUISelLowering.cpp | 19 ++++++++++++------- llvm/lib/Target/AMDGPU/AMDGPUISelLowering.h | 3 +++ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/llvm/lib/Target/AMDGPU/AMDGPUISelLowering.cpp b/llvm/lib/Target/AMDGPU/AMDGPUISelLowering.cpp index 3558468..58a53f1 100644 --- a/llvm/lib/Target/AMDGPU/AMDGPUISelLowering.cpp +++ b/llvm/lib/Target/AMDGPU/AMDGPUISelLowering.cpp @@ -3844,15 +3844,20 @@ static bool isInv2Pi(const APFloat &APF) { // 0 and 1.0 / (0.5 * pi) do not have inline immmediates, so there is an // additional cost to negate them. -bool AMDGPUTargetLowering::isConstantCostlierToNegate(SDValue N) const { - if (const ConstantFPSDNode *C = isConstOrConstSplatFP(N)) { - if (C->isZero() && !C->isNegative()) - return true; +TargetLowering::NegatibleCost +AMDGPUTargetLowering::getConstantNegateCost(const ConstantFPSDNode *C) const { + if (C->isZero()) + return C->isNegative() ? NegatibleCost::Cheaper : NegatibleCost::Expensive; - if (Subtarget->hasInv2PiInlineImm() && isInv2Pi(C->getValueAPF())) - return true; - } + if (Subtarget->hasInv2PiInlineImm() && isInv2Pi(C->getValueAPF())) + return C->isNegative() ? NegatibleCost::Cheaper : NegatibleCost::Expensive; + return NegatibleCost::Neutral; +} + +bool AMDGPUTargetLowering::isConstantCostlierToNegate(SDValue N) const { + if (const ConstantFPSDNode *C = isConstOrConstSplatFP(N)) + return getConstantNegateCost(C) == NegatibleCost::Expensive; return false; } diff --git a/llvm/lib/Target/AMDGPU/AMDGPUISelLowering.h b/llvm/lib/Target/AMDGPU/AMDGPUISelLowering.h index 969e4c91..d7d2c6e 100644 --- a/llvm/lib/Target/AMDGPU/AMDGPUISelLowering.h +++ b/llvm/lib/Target/AMDGPU/AMDGPUISelLowering.h @@ -99,6 +99,9 @@ protected: SDValue RHS, DAGCombinerInfo &DCI) const; SDValue performSelectCombine(SDNode *N, DAGCombinerInfo &DCI) const; + TargetLowering::NegatibleCost + getConstantNegateCost(const ConstantFPSDNode *C) const; + bool isConstantCostlierToNegate(SDValue N) const; SDValue performFNegCombine(SDNode *N, DAGCombinerInfo &DCI) const; SDValue performFAbsCombine(SDNode *N, DAGCombinerInfo &DCI) const; -- 2.7.4