[llvm-commits] CVS: llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
Chris Lattner
sabre at nondot.org
Wed May 23 00:35:42 PDT 2007
Changes in directory llvm/lib/CodeGen/SelectionDAG:
DAGCombiner.cpp updated: 1.308 -> 1.309
---
Log message:
prevent exponential recursion in isNegatibleForFree
---
Diffs of the changes: (+9 -6)
DAGCombiner.cpp | 15 +++++++++------
1 files changed, 9 insertions(+), 6 deletions(-)
Index: llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
diff -u llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp:1.308 llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp:1.309
--- llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp:1.308 Fri May 18 13:41:29 2007
+++ llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp Wed May 23 02:35:22 2007
@@ -352,7 +352,10 @@
/// isNegatibleForFree - Return 1 if we can compute the negated form of the
/// specified expression for the same cost as the expression itself, or 2 if we
/// can compute the negated form more cheaply than the expression itself.
-static char isNegatibleForFree(SDOperand Op) {
+static char isNegatibleForFree(SDOperand Op, unsigned Depth = 0) {
+ // Don't recurse exponentially.
+ if (Depth > 6) return false;
+
// fneg is removable even if it has multiple uses.
if (Op.getOpcode() == ISD::FNEG) return 2;
@@ -368,10 +371,10 @@
if (!UnsafeFPMath) return 0;
// -(A+B) -> -A - B
- if (char V = isNegatibleForFree(Op.getOperand(0)))
+ if (char V = isNegatibleForFree(Op.getOperand(0), Depth+1))
return V;
// -(A+B) -> -B - A
- return isNegatibleForFree(Op.getOperand(1));
+ return isNegatibleForFree(Op.getOperand(1), Depth+1);
case ISD::FSUB:
// We can't turn -(A-B) into B-A when we honor signed zeros.
if (!UnsafeFPMath) return 0;
@@ -384,15 +387,15 @@
if (HonorSignDependentRoundingFPMath()) return 0;
// -(X*Y) -> (-X * Y) or (X*-Y)
- if (char V = isNegatibleForFree(Op.getOperand(0)))
+ if (char V = isNegatibleForFree(Op.getOperand(0), Depth+1))
return V;
- return isNegatibleForFree(Op.getOperand(1));
+ return isNegatibleForFree(Op.getOperand(1), Depth+1);
case ISD::FP_EXTEND:
case ISD::FP_ROUND:
case ISD::FSIN:
- return isNegatibleForFree(Op.getOperand(0));
+ return isNegatibleForFree(Op.getOperand(0), Depth+1);
}
}
More information about the llvm-commits
mailing list