From 9b5b508e71a02cc89abbf485850ff66c0efecdd4 Mon Sep 17 00:00:00 2001 From: Qiu Chaofan Date: Tue, 1 Sep 2020 00:35:01 +0800 Subject: [PATCH] [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. --- lib/CodeGen/SelectionDAG/DAGCombiner.cpp | 16 ---------------- test/CodeGen/PowerPC/fneg.ll | 13 +++++++++++++ 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/lib/CodeGen/SelectionDAG/DAGCombiner.cpp index a570581e89b..42f4aea4741 100644 --- a/lib/CodeGen/SelectionDAG/DAGCombiner.cpp +++ b/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(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/test/CodeGen/PowerPC/fneg.ll b/test/CodeGen/PowerPC/fneg.ll index aea34e216d6..26cfa1e82c6 100644 --- a/test/CodeGen/PowerPC/fneg.ll +++ b/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@ha +; CHECK-NEXT: lfd f0, .LCPI4_0@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 +}