[llvm] a4e8347 - AMDGPU: Refactor isConstantCostlierToNegate
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 15 01:21:08 PST 2023
Author: Matt Arsenault
Date: 2023-02-15T05:21:00-04:00
New Revision: a4e8347b36617ed81accbf5c5fb3b532db941f4f
URL: https://github.com/llvm/llvm-project/commit/a4e8347b36617ed81accbf5c5fb3b532db941f4f
DIFF: https://github.com/llvm/llvm-project/commit/a4e8347b36617ed81accbf5c5fb3b532db941f4f.diff
LOG: AMDGPU: Refactor isConstantCostlierToNegate
Added:
Modified:
llvm/lib/Target/AMDGPU/AMDGPUISelLowering.cpp
llvm/lib/Target/AMDGPU/AMDGPUISelLowering.h
Removed:
################################################################################
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUISelLowering.cpp b/llvm/lib/Target/AMDGPU/AMDGPUISelLowering.cpp
index 35584681a6ba..58a53f1f939d 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 969e4c913853..d7d2c6e65f65 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUISelLowering.h
+++ b/llvm/lib/Target/AMDGPU/AMDGPUISelLowering.h
@@ -99,6 +99,9 @@ class AMDGPUTargetLowering : public TargetLowering {
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;
More information about the llvm-commits
mailing list