[llvm] r214622 - Fix issues with ISD::FNEG and ISD::FMA SDNodes where they would not be constant-folded

Owen Anderson resistor at mac.com
Sat Aug 2 01:45:33 PDT 2014


Author: resistor
Date: Sat Aug  2 03:45:33 2014
New Revision: 214622

URL: http://llvm.org/viewvc/llvm-project?rev=214622&view=rev
Log:
Fix issues with ISD::FNEG and ISD::FMA SDNodes where they would not be constant-folded
during DAGCombine in certain circumstances.  Unfortunately, the circumstances required
to trigger the issue seem to require a pretty specific interaction of DAGCombines,
and I haven't been able to find a testcase that reproduces on X86, ARM, or AArch64.
The functionality added here is replicated in essentially every other DAG combine,
so it seems pretty obviously correct.


Modified:
    llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Modified: llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp?rev=214622&r1=214621&r2=214622&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp Sat Aug  2 03:45:33 2014
@@ -6893,6 +6893,14 @@ SDValue DAGCombiner::visitFMA(SDNode *N)
   EVT VT = N->getValueType(0);
   SDLoc dl(N);
 
+
+  // Constant fold FMA.
+  if (isa<ConstantFPSDNode>(N0) &&
+      isa<ConstantFPSDNode>(N1) &&
+      isa<ConstantFPSDNode>(N2)) {
+    return DAG.getNode(ISD::FMA, dl, VT, N0, N1, N2);
+  }
+
   if (DAG.getTarget().Options.UnsafeFPMath) {
     if (N0CFP && N0CFP->isZero())
       return N2;
@@ -7293,6 +7301,10 @@ SDValue DAGCombiner::visitFNEG(SDNode *N
   SDValue N0 = N->getOperand(0);
   EVT VT = N->getValueType(0);
 
+  // Constant fold FNEG.
+  if (isa<ConstantFPSDNode>(N0))
+    return DAG.getNode(ISD::FNEG, SDLoc(N), VT, N->getOperand(0));
+
   if (VT.isVector()) {
     SDValue FoldedVOp = SimplifyVUnaryOp(N);
     if (FoldedVOp.getNode()) return FoldedVOp;





More information about the llvm-commits mailing list