From: Sanjay Patel Date: Tue, 21 May 2019 14:47:38 +0000 (+0000) Subject: [DAGCombiner] prevent unsafe reassociation of FP ops X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c32b944575fe5f284b432d1748542c0f89405650;p=llvm [DAGCombiner] prevent unsafe reassociation of FP ops There are no FP callers of DAGCombiner::reassociateOps() currently, but we can add a fast-math check to make sure this API is not being misused. This was noted as a potential risk (and that risk might increase) with: D62191 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@361268 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/lib/CodeGen/SelectionDAG/DAGCombiner.cpp index 799f95274b2..0aa481ff2e2 100644 --- a/lib/CodeGen/SelectionDAG/DAGCombiner.cpp +++ b/lib/CodeGen/SelectionDAG/DAGCombiner.cpp @@ -1042,6 +1042,13 @@ SDValue DAGCombiner::reassociateOps(unsigned Opc, const SDLoc &DL, SDValue N0, // Don't reassociate reductions. if (Flags.hasVectorReduction()) return SDValue(); + + // Floating-point reassociation is not allowed without loose FP math. + if (N0.getValueType().isFloatingPoint() || + N1.getValueType().isFloatingPoint()) + if (!Flags.hasAllowReassociation() || !Flags.hasNoSignedZeros()) + return SDValue(); + if (SDValue Combined = reassociateOpsCommutative(Opc, DL, N0, N1)) return Combined; if (SDValue Combined = reassociateOpsCommutative(Opc, DL, N1, N0)) @@ -1728,7 +1735,7 @@ SDValue DAGCombiner::combine(SDNode *N) { } } - // If N is a commutative binary node, try eliminate it if the commuted + // If N is a commutative binary node, try to eliminate it if the commuted // version is already present in the DAG. if (!RV.getNode() && TLI.isCommutativeBinOp(N->getOpcode()) && N->getNumValues() == 1) {