[llvm] r334753 - updating isNegatibleForFree and GetNegatedExpression with fmf for fadd
Michael Berg via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 14 11:48:31 PDT 2018
Author: mcberg2017
Date: Thu Jun 14 11:48:31 2018
New Revision: 334753
URL: http://llvm.org/viewvc/llvm-project?rev=334753&view=rev
Log:
updating isNegatibleForFree and GetNegatedExpression with fmf for fadd
Summary: A FMF constraint is added to FADD with unsafe still available as the fallback
Reviewers: spatel, wristow, arsenm, hfinkel
Reviewed By: spatel
Subscribers: wdng
Differential Revision: https://reviews.llvm.org/D48180
Modified:
llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
llvm/trunk/test/CodeGen/X86/fp-fold.ll
Modified: llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp?rev=334753&r1=334752&r2=334753&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp Thu Jun 14 11:48:31 2018
@@ -704,8 +704,8 @@ static char isNegatibleForFree(SDValue O
TLI.isFPImmLegal(neg(cast<ConstantFPSDNode>(Op)->getValueAPF()), VT);
}
case ISD::FADD:
- // FIXME: determine better conditions for this xform.
- if (!Options->UnsafeFPMath) return 0;
+ if (!Options->UnsafeFPMath && !Flags.hasNoSignedZeros())
+ return 0;
// After operation legalization, it might not be legal to create new FSUBs.
if (LegalOperations && !TLI.isOperationLegalOrCustom(ISD::FSUB, VT))
@@ -766,8 +766,7 @@ static SDValue GetNegatedExpression(SDVa
return DAG.getConstantFP(V, SDLoc(Op), Op.getValueType());
}
case ISD::FADD:
- // FIXME: determine better conditions for this xform.
- assert(Options.UnsafeFPMath);
+ assert(Options.UnsafeFPMath || Flags.hasNoSignedZeros());
// fold (fneg (fadd A, B)) -> (fsub (fneg A), B)
if (isNegatibleForFree(Op.getOperand(0), LegalOperations,
Modified: llvm/trunk/test/CodeGen/X86/fp-fold.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/fp-fold.ll?rev=334753&r1=334752&r2=334753&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/fp-fold.ll (original)
+++ llvm/trunk/test/CodeGen/X86/fp-fold.ll Thu Jun 14 11:48:31 2018
@@ -62,6 +62,17 @@ define float @fsub_self(float %x) {
ret float %r
}
+define float @fsub_neg_x_y(float %x, float %y) {
+; ANY-LABEL: fsub_neg_x_y:
+; ANY: # %bb.0:
+; ANY-NEXT: subss %xmm0, %xmm1
+; ANY-NEXT: movaps %xmm1, %xmm0
+; ANY-NEXT: retq
+ %neg = fsub nsz float 0.0, %x
+ %r = fadd nsz float %neg, %y
+ ret float %r
+}
+
define float @fsub_negzero(float %x) {
; STRICT-LABEL: fsub_negzero:
; STRICT: # %bb.0:
More information about the llvm-commits
mailing list