]> granicus.if.org Git - llvm/commitdiff
[DAGCombiner] prevent unsafe reassociation of FP ops
authorSanjay Patel <spatel@rotateright.com>
Tue, 21 May 2019 14:47:38 +0000 (14:47 +0000)
committerSanjay Patel <spatel@rotateright.com>
Tue, 21 May 2019 14:47:38 +0000 (14:47 +0000)
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

lib/CodeGen/SelectionDAG/DAGCombiner.cpp

index 799f95274b26eed102925721688c5abcd15f0d33..0aa481ff2e2986f3aae47b30e98e31aa3c33699c 100644 (file)
@@ -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) {