@@ -3535,24 +3535,37 @@ class TargetLowering : public TargetLoweringBase {
3535
3535
llvm_unreachable (" Not Implemented" );
3536
3536
}
3537
3537
3538
+ // / Returns whether computing the negated form of the specified expression is
3539
+ // / more expensive, the same cost or cheaper.
3540
+ virtual NegatibleCost getNegatibleCost (SDValue Op, SelectionDAG &DAG,
3541
+ bool LegalOperations, bool ForCodeSize,
3542
+ unsigned Depth = 0 ) const ;
3543
+
3544
+ // / If getNegatibleCost returns Neutral/Cheaper, return the newly negated
3545
+ // / expression.
3546
+ virtual SDValue negateExpression (SDValue Op, SelectionDAG &DAG, bool LegalOps,
3547
+ bool OptForSize, unsigned Depth = 0 ) const ;
3548
+
3538
3549
// / Return the newly negated expression if the cost is not expensive and
3539
3550
// / set the cost in \p Cost to indicate that if it is cheaper or neutral to
3540
3551
// / do the negation.
3541
- virtual SDValue getNegatedExpression (SDValue Op, SelectionDAG &DAG,
3542
- bool LegalOps, bool OptForSize,
3543
- NegatibleCost &Cost,
3544
- unsigned Depth = 0 ) const ;
3552
+ SDValue getNegatedExpression (SDValue Op, SelectionDAG &DAG, bool LegalOps,
3553
+ bool OptForSize, NegatibleCost &Cost,
3554
+ unsigned Depth = 0 ) const {
3555
+ Cost = getNegatibleCost (Op, DAG, LegalOps, OptForSize, Depth);
3556
+ if (Cost != NegatibleCost::Expensive)
3557
+ return negateExpression (Op, DAG, LegalOps, OptForSize, Depth);
3558
+ return SDValue ();
3559
+ }
3545
3560
3546
3561
// / This is the helper function to return the newly negated expression only
3547
3562
// / when the cost is cheaper.
3548
3563
SDValue getCheaperNegatedExpression (SDValue Op, SelectionDAG &DAG,
3549
3564
bool LegalOps, bool OptForSize,
3550
3565
unsigned Depth = 0 ) const {
3551
- NegatibleCost Cost = NegatibleCost::Expensive;
3552
- SDValue Neg =
3553
- getNegatedExpression (Op, DAG, LegalOps, OptForSize, Cost, Depth);
3554
- if (Neg && Cost == NegatibleCost::Cheaper)
3555
- return Neg;
3566
+ if (getNegatibleCost (Op, DAG, LegalOps, OptForSize, Depth) ==
3567
+ NegatibleCost::Cheaper)
3568
+ return negateExpression (Op, DAG, LegalOps, OptForSize, Depth);
3556
3569
return SDValue ();
3557
3570
}
3558
3571
0 commit comments