Teach DAG combine to fold x-x to 0.0 when unsafe FP math is enabled.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@156324 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Owen Anderson 2012-05-07 20:51:25 +00:00
parent 423f19f2da
commit 713e953118
2 changed files with 22 additions and 0 deletions

View File

@ -5670,9 +5670,13 @@ SDValue DAGCombiner::visitFSUB(SDNode *N) {
GetNegatedExpression(N1, DAG, LegalOperations));
// If 'unsafe math' is enabled, fold
// (fsub x, x) -> 0.0 &
// (fsub x, (fadd x, y)) -> (fneg y) &
// (fsub x, (fadd y, x)) -> (fneg y)
if (DAG.getTarget().Options.UnsafeFPMath) {
if (N0 == N1)
return DAG.getConstantFP(0.0f, VT);
if (N1.getOpcode() == ISD::FADD) {
SDValue N10 = N1->getOperand(0);
SDValue N11 = N1->getOperand(1);

View File

@ -0,0 +1,18 @@
; RUN: llc -march=arm -mcpu=cortex-a9 < %s | FileCheck -check-prefix=SAFE %s
; RUN: llc -march=arm -mcpu=cortex-a9 -enable-unsafe-fp-math < %s | FileCheck -check-prefix=FAST %s
target triple = "armv7-apple-ios"
; SAFE: test
; FAST: test
define float @test(float %x, float %y) {
entry:
; SAFE: vmul.f32
; SAFE: vsub.f32
; FAST: mov r0, #0
%0 = fmul float %x, %y
%1 = fsub float %0, %0
ret float %1
}