summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Berg <michael_c_berg@apple.com>2018-06-05 18:49:47 +0000
committerMichael Berg <michael_c_berg@apple.com>2018-06-05 18:49:47 +0000
commit96925fe0df7a628839eabb5886a0e59910713ab6 (patch)
tree400aafdcd23c4192db8cca373fe9e5189186b1e2
parentb89704fa6f6fc80c58bdacdadeb6d0dd4fa6e5d9 (diff)
downloadbcm5719-llvm-96925fe0df7a628839eabb5886a0e59910713ab6.tar.gz
bcm5719-llvm-96925fe0df7a628839eabb5886a0e59910713ab6.zip
guard fneg with fmf sub flags
Summary: This change uses fmf subflags to guard optimizations as well as unsafe. These changes originated from D46483. Reviewers: spatel, hfinkel Reviewed By: spatel Subscribers: nemanjai Differential Revision: https://reviews.llvm.org/D47389 llvm-svn: 334037
-rw-r--r--llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp6
-rw-r--r--llvm/test/CodeGen/PowerPC/fmf-propagation.ll15
2 files changed, 9 insertions, 12 deletions
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
index 9dac51f33cd..bdecb8b37c4 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -4049,10 +4049,10 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
break;
case ISD::FNEG:
// -(X-Y) -> (Y-X) is unsafe because when X==Y, -0.0 != +0.0
- if (getTarget().Options.UnsafeFPMath && OpOpcode == ISD::FSUB)
- // FIXME: FNEG has no fast-math-flags to propagate; use the FSUB's flags?
+ if ((getTarget().Options.UnsafeFPMath || Flags.hasNoSignedZeros()) &&
+ OpOpcode == ISD::FSUB)
return getNode(ISD::FSUB, DL, VT, Operand.getOperand(1),
- Operand.getOperand(0), Operand.getNode()->getFlags());
+ Operand.getOperand(0), Flags);
if (OpOpcode == ISD::FNEG) // --X -> X
return Operand.getOperand(0);
break;
diff --git a/llvm/test/CodeGen/PowerPC/fmf-propagation.ll b/llvm/test/CodeGen/PowerPC/fmf-propagation.ll
index 3a9c844c238..4c87c3dfbbd 100644
--- a/llvm/test/CodeGen/PowerPC/fmf-propagation.ll
+++ b/llvm/test/CodeGen/PowerPC/fmf-propagation.ll
@@ -460,28 +460,25 @@ define double @log2_approx(double %x) nounwind {
; -(X - Y) --> (Y - X)
; FMFDEBUG-LABEL: Optimized lowered selection DAG: %bb.0 'fneg_fsub_nozeros_1:'
-; FMFDEBUG: fsub {{t[0-9]+}}, {{t[0-9]+}}
+; FMFDEBUG: fsub nsz {{t[0-9]+}}, {{t[0-9]+}}
; FMFDEBUG: Type-legalized selection DAG: %bb.0 'fneg_fsub_nozeros_1:'
; GLOBALDEBUG-LABEL: Optimized lowered selection DAG: %bb.0 'fneg_fsub_nozeros_1:'
-; GLOBALDEBUG: fsub {{t[0-9]+}}, {{t[0-9]+}}
+; GLOBALDEBUG: fsub nsz {{t[0-9]+}}, {{t[0-9]+}}
; GLOBALDEBUG: Type-legalized selection DAG: %bb.0 'fneg_fsub_nozeros_1:'
define float @fneg_fsub_nozeros_1(float %x, float %y, float %z) {
; FMF-LABEL: fneg_fsub_nozeros_1:
; FMF: # %bb.0:
-; FMF-NEXT: xssubsp 0, 1, 2
-; FMF-NEXT: xxlxor 13, 13, 13
-; FMF-NEXT: xssubsp 1, 13, 0
+; FMF-NEXT: xssubsp 1, 2, 1
; FMF-NEXT: blr
;
; GLOBAL-LABEL: fneg_fsub_nozeros_1:
; GLOBAL: # %bb.0:
-; GLOBAL-NEXT: xssubsp 0, 1, 2
-; GLOBAL-NEXT: xxlxor 13, 13, 13
-; GLOBAL-NEXT: xssubsp 1, 13, 0
+; GLOBAL-NEXT: xssubsp 1, 2, 1
; GLOBAL-NEXT: blr
%neg = fsub float %x, %y
- %add = fsub float 0.0, %neg
+ %add = fsub nsz float 0.0, %neg
ret float %add
}
+
OpenPOWER on IntegriCloud