Skip to content

Commit 728cf6d

Browse files
committed
Revert "[DAGCombine] Remove the getNegatibleCost to avoid the out of sync with getNegatedExpression"
This reverts commit 3c44c44. Causes infloops on some inputs, see https://reviews.llvm.org/D77319 for repro
1 parent b75795c commit 728cf6d

File tree

7 files changed

+279
-217
lines changed

7 files changed

+279
-217
lines changed

llvm/include/llvm/CodeGen/TargetLowering.h

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3535,24 +3535,37 @@ class TargetLowering : public TargetLoweringBase {
35353535
llvm_unreachable("Not Implemented");
35363536
}
35373537

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+
35383549
/// Return the newly negated expression if the cost is not expensive and
35393550
/// set the cost in \p Cost to indicate that if it is cheaper or neutral to
35403551
/// 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+
}
35453560

35463561
/// This is the helper function to return the newly negated expression only
35473562
/// when the cost is cheaper.
35483563
SDValue getCheaperNegatedExpression(SDValue Op, SelectionDAG &DAG,
35493564
bool LegalOps, bool OptForSize,
35503565
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);
35563569
return SDValue();
35573570
}
35583571

0 commit comments

Comments
 (0)