summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp7
-rw-r--r--llvm/test/CodeGen/X86/fp-fold.ll11
2 files changed, 14 insertions, 4 deletions
diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
index ac324fe4c3d..33821c33bb7 100644
--- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -704,8 +704,8 @@ static char isNegatibleForFree(SDValue Op, bool LegalOperations,
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(SDValue Op, SelectionDAG &DAG,
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,
diff --git a/llvm/test/CodeGen/X86/fp-fold.ll b/llvm/test/CodeGen/X86/fp-fold.ll
index fa4404bb1c0..34354436c6e 100644
--- a/llvm/test/CodeGen/X86/fp-fold.ll
+++ b/llvm/test/CodeGen/X86/fp-fold.ll
@@ -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:
OpenPOWER on IntegriCloud