Skip to content

Commit 78c3f58

Browse files
committed
[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 llvm-svn: 361268
1 parent a7b9e98 commit 78c3f58

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1042,6 +1042,13 @@ SDValue DAGCombiner::reassociateOps(unsigned Opc, const SDLoc &DL, SDValue N0,
10421042
// Don't reassociate reductions.
10431043
if (Flags.hasVectorReduction())
10441044
return SDValue();
1045+
1046+
// Floating-point reassociation is not allowed without loose FP math.
1047+
if (N0.getValueType().isFloatingPoint() ||
1048+
N1.getValueType().isFloatingPoint())
1049+
if (!Flags.hasAllowReassociation() || !Flags.hasNoSignedZeros())
1050+
return SDValue();
1051+
10451052
if (SDValue Combined = reassociateOpsCommutative(Opc, DL, N0, N1))
10461053
return Combined;
10471054
if (SDValue Combined = reassociateOpsCommutative(Opc, DL, N1, N0))
@@ -1728,7 +1735,7 @@ SDValue DAGCombiner::combine(SDNode *N) {
17281735
}
17291736
}
17301737

1731-
// If N is a commutative binary node, try eliminate it if the commuted
1738+
// If N is a commutative binary node, try to eliminate it if the commuted
17321739
// version is already present in the DAG.
17331740
if (!RV.getNode() && TLI.isCommutativeBinOp(N->getOpcode()) &&
17341741
N->getNumValues() == 1) {

0 commit comments

Comments
 (0)