[llvm] r207850 - DAGCombine: prevent formation of illegal ConstantFP nodes.

Tim Northover tnorthover at apple.com
Fri May 2 10:25:03 PDT 2014


Author: tnorthover
Date: Fri May  2 12:25:02 2014
New Revision: 207850

URL: http://llvm.org/viewvc/llvm-project?rev=207850&view=rev
Log:
DAGCombine: prevent formation of illegal ConstantFP nodes.

Added:
    llvm/trunk/test/CodeGen/ARM64/fp-contract-zero.ll
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=207850&r1=207849&r2=207850&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp Fri May  2 12:25:02 2014
@@ -7181,11 +7181,16 @@ SDValue DAGCombiner::visitFNEG(SDNode *N
   // (fneg (fmul c, x)) -> (fmul -c, x)
   if (N0.getOpcode() == ISD::FMUL) {
     ConstantFPSDNode *CFP1 = dyn_cast<ConstantFPSDNode>(N0.getOperand(1));
-    if (CFP1)
-      return DAG.getNode(ISD::FMUL, SDLoc(N), VT,
-                         N0.getOperand(0),
-                         DAG.getNode(ISD::FNEG, SDLoc(N), VT,
-                                     N0.getOperand(1)));
+    if (CFP1) {
+      APFloat CVal = CFP1->getValueAPF();
+      CVal.changeSign();
+      if (Level >= AfterLegalizeDAG &&
+          (TLI.isFPImmLegal(CVal, N->getValueType(0)) ||
+           TLI.isOperationLegal(ISD::ConstantFP, N->getValueType(0))))
+        return DAG.getNode(
+            ISD::FMUL, SDLoc(N), VT, N0.getOperand(0),
+            DAG.getNode(ISD::FNEG, SDLoc(N), VT, N0.getOperand(1)));
+    }
   }
 
   return SDValue();

Added: llvm/trunk/test/CodeGen/ARM64/fp-contract-zero.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/ARM64/fp-contract-zero.ll?rev=207850&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/ARM64/fp-contract-zero.ll (added)
+++ llvm/trunk/test/CodeGen/ARM64/fp-contract-zero.ll Fri May  2 12:25:02 2014
@@ -0,0 +1,14 @@
+; RUN: llc -mtriple=arm64 -fp-contract=fast -o - %s | FileCheck %s
+
+
+; Make sure we don't try to fold an fneg into +0.0, creating an illegal constant
+; -0.0. It's also good, though not essential, that we don't resort to a litpool.
+define double @test_fms_fold(double %a, double %b) {
+; CHECK-LABEL: test_fms_fold:
+; CHECK: fmov {{d[0-9]+}}, xzr
+; CHECK: ret
+  %mul = fmul double %a, 0.000000e+00
+  %mul1 = fmul double %b, 0.000000e+00
+  %sub = fsub double %mul, %mul1
+  ret double %sub
+}
\ No newline at end of file





More information about the llvm-commits mailing list