From: QingShan Zhang Date: Wed, 15 Apr 2020 02:17:36 +0000 (+0000) Subject: [NFC][DAGCombine] Change the value of NegatibleCost to make it align with the semantics X-Git-Tag: llvmorg-12-init~9023 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c9f9c79c5a4868f8bb7526c104aa18fd1dc42002;p=platform%2Fupstream%2Fllvm.git [NFC][DAGCombine] Change the value of NegatibleCost to make it align with the semantics This is a minor NFC change to make the code more clear. We have the NegatibleCost that has cheaper, neutral, and expensive. Typically, the smaller one means the less cost. It is inverse for current implementation, which makes following code not easy to read. If (CostX > CostY) negate(X) Reviewed By: RKSimon Differential Revision: https://reviews.llvm.org/D77993 --- diff --git a/llvm/include/llvm/CodeGen/TargetLowering.h b/llvm/include/llvm/CodeGen/TargetLowering.h index 4b0592d..98df521 100644 --- a/llvm/include/llvm/CodeGen/TargetLowering.h +++ b/llvm/include/llvm/CodeGen/TargetLowering.h @@ -257,9 +257,9 @@ public: /// Enum that specifies when a float negation is beneficial. enum class NegatibleCost { - Expensive = 0, // Negated expression is more expensive. + Cheaper = 0, // Negated expression is cheaper. Neutral = 1, // Negated expression has the same cost. - Cheaper = 2 // Negated expression is cheaper. + Expensive = 2 // Negated expression is more expensive. }; class ArgListEntry { diff --git a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp index 6c3e952..5110dd5 100644 --- a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp @@ -5671,10 +5671,10 @@ TargetLowering::getNegatibleCost(SDValue Op, SelectionDAG &DAG, ForCodeSize, Depth + 1); NegatibleCost V1 = getNegatibleCost(Op.getOperand(1), DAG, LegalOperations, ForCodeSize, Depth + 1); - NegatibleCost V01 = std::max(V0, V1); + NegatibleCost V01 = std::min(V0, V1); if (V01 == NegatibleCost::Expensive) return NegatibleCost::Expensive; - return std::max(V01, V2); + return std::min(V01, V2); } case ISD::FP_EXTEND: @@ -5776,7 +5776,7 @@ SDValue TargetLowering::getNegatedExpression(SDValue Op, SelectionDAG &DAG, SDValue NegZ = getNegatedExpression(Z, DAG, LegalOps, OptForSize, Depth); NegatibleCost CostX = getNegatibleCost(X, DAG, LegalOps, OptForSize, Depth); NegatibleCost CostY = getNegatibleCost(Y, DAG, LegalOps, OptForSize, Depth); - if (CostX > CostY) { + if (CostX <= CostY) { // fold (fneg (fma X, Y, Z)) -> (fma (fneg X), Y, (fneg Z)) SDValue NegX = getNegatedExpression(X, DAG, LegalOps, OptForSize, Depth); return DAG.getNode(Opcode, DL, VT, NegX, Y, NegZ, Flags);