diff options
| author | Chris Lattner <sabre@nondot.org> | 2007-05-23 07:35:22 +0000 |
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2007-05-23 07:35:22 +0000 |
| commit | 6509c0673f5852c81d08c6ae3c56b3b8c02b1425 (patch) | |
| tree | 5587855f818ea5efa87414d47c77a274b5eb2fcb /llvm/lib/CodeGen | |
| parent | d0e669199b7de1aa3006418603ccda0bed4a5f10 (diff) | |
| download | bcm5719-llvm-6509c0673f5852c81d08c6ae3c56b3b8c02b1425.tar.gz bcm5719-llvm-6509c0673f5852c81d08c6ae3c56b3b8c02b1425.zip | |
prevent exponential recursion in isNegatibleForFree
llvm-svn: 37310
Diffstat (limited to 'llvm/lib/CodeGen')
| -rw-r--r-- | llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp index 58023105f10..05000115417 100644 --- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp @@ -352,7 +352,10 @@ CombineTo(SDNode *N, SDOperand Res0, SDOperand Res1) { /// 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 @@ static char isNegatibleForFree(SDOperand Op) { 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 @@ static char isNegatibleForFree(SDOperand Op) { 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); } } |

