[llvm] eb2a405 - [NFC] [DAGCombiner] Remove unnecessary negation in visitFNEG

Qiu Chaofan via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 31 09:37:29 PDT 2020


Author: Qiu Chaofan
Date: 2020-09-01T00:35:01+08:00
New Revision: eb2a405c181c9833eb8676d147619b8c893dc6fa

URL: https://github.com/llvm/llvm-project/commit/eb2a405c181c9833eb8676d147619b8c893dc6fa
DIFF: https://github.com/llvm/llvm-project/commit/eb2a405c181c9833eb8676d147619b8c893dc6fa.diff

LOG: [NFC] [DAGCombiner] Remove unnecessary negation in visitFNEG

In visitFNEG of DAGCombiner, the folding of (fneg (fsub c, x)) is
redundant since getNegatedExpression already handles it.

Added: 
    

Modified: 
    llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
    llvm/test/CodeGen/PowerPC/fneg.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
index a570581e89bb..42f4aea4741f 100644
--- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -14022,22 +14022,6 @@ SDValue DAGCombiner::visitFNEG(SDNode *N) {
     }
   }
 
-  // (fneg (fmul c, x)) -> (fmul -c, x)
-  if (N0.getOpcode() == ISD::FMUL &&
-      (N0.getNode()->hasOneUse() || !TLI.isFNegFree(VT))) {
-    ConstantFPSDNode *CFP1 = dyn_cast<ConstantFPSDNode>(N0.getOperand(1));
-    if (CFP1) {
-      APFloat CVal = CFP1->getValueAPF();
-      CVal.changeSign();
-      if (LegalDAG && (TLI.isFPImmLegal(CVal, VT, ForCodeSize) ||
-                       TLI.isOperationLegal(ISD::ConstantFP, VT)))
-        return DAG.getNode(
-            ISD::FMUL, SDLoc(N), VT, N0.getOperand(0),
-            DAG.getNode(ISD::FNEG, SDLoc(N), VT, N0.getOperand(1)),
-            N0->getFlags());
-    }
-  }
-
   return SDValue();
 }
 

diff  --git a/llvm/test/CodeGen/PowerPC/fneg.ll b/llvm/test/CodeGen/PowerPC/fneg.ll
index aea34e216d64..26cfa1e82c69 100644
--- a/llvm/test/CodeGen/PowerPC/fneg.ll
+++ b/llvm/test/CodeGen/PowerPC/fneg.ll
@@ -56,3 +56,16 @@ define double @fneg_no_ice(float %x) {
   %e3 = fmul double %e, %e2
   ret double %e3
 }
+
+define double @fneg_fmul_const(double %x) {
+; CHECK-LABEL: fneg_fmul_const:
+; CHECK:       # %bb.0: # %entry
+; CHECK-NEXT:    lis r3, .LCPI4_0 at ha
+; CHECK-NEXT:    lfd f0, .LCPI4_0 at l(r3)
+; CHECK-NEXT:    fmul f1, f1, f0
+; CHECK-NEXT:    blr
+entry:
+  %f = fmul double %x, 1.2345
+  %s = fneg double %f
+  ret double %s
+}


        


More information about the llvm-commits mailing list