Revision: 127543 Author: bwendlin Date: 2007-05-23 01:01:23 -0700 (Wed, 23 May 2007)
Log Message: ----------- >From TOT: prevent exponential recursion in isNegatibleForFree Modified Paths: -------------- apple-local/branches/llvm-leopard/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp Modified: apple-local/branches/llvm-leopard/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp =================================================================== --- apple-local/branches/llvm-leopard/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp 2007-05-23 07:02:15 UTC (rev 127542) +++ apple-local/branches/llvm-leopard/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp 2007-05-23 08:01:23 UTC (rev 127543) @@ -351,7 +351,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; @@ -367,10 +370,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; @@ -383,15 +386,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); } } _______________________________________________ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits