From: Benjamin Kramer Date: Mon, 29 Feb 2016 11:12:23 +0000 (+0000) Subject: [InstSimplify] fsub 0.0, (fsub -0.0, X) ==> X is only safe if signed zeros are ignored. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f5b2a47ac69a91be61a99f16d5b6bbab02e92b77;p=platform%2Fupstream%2Fllvm.git [InstSimplify] fsub 0.0, (fsub -0.0, X) ==> X is only safe if signed zeros are ignored. Only allow fsub -0.0, (fsub -0.0, X) ==> X without nsz. PR26746. llvm-svn: 262212 --- diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp index 61e7296..aca19de 100644 --- a/llvm/lib/Analysis/InstructionSimplify.cpp +++ b/llvm/lib/Analysis/InstructionSimplify.cpp @@ -833,14 +833,15 @@ static Value *SimplifyFSubInst(Value *Op0, Value *Op1, FastMathFlags FMF, (FMF.noSignedZeros() || CannotBeNegativeZero(Op0))) return Op0; - // fsub 0, (fsub -0.0, X) ==> X + // fsub -0.0, (fsub -0.0, X) ==> X Value *X; - if (match(Op0, m_AnyZero())) { - if (match(Op1, m_FSub(m_NegZero(), m_Value(X)))) - return X; - if (FMF.noSignedZeros() && match(Op1, m_FSub(m_AnyZero(), m_Value(X)))) - return X; - } + if (match(Op0, m_NegZero()) && match(Op1, m_FSub(m_NegZero(), m_Value(X)))) + return X; + + // fsub 0.0, (fsub 0.0, X) ==> X if signed zeros are ignored. + if (FMF.noSignedZeros() && match(Op0, m_NegZero()) && + match(Op1, m_FSub(m_AnyZero(), m_Value(X)))) + return X; // fsub nnan x, x ==> 0.0 if (FMF.noNaNs() && Op0 == Op1) diff --git a/llvm/test/Transforms/InstSimplify/floating-point-arithmetic.ll b/llvm/test/Transforms/InstSimplify/floating-point-arithmetic.ll index b0957a8..1c29884 100644 --- a/llvm/test/Transforms/InstSimplify/floating-point-arithmetic.ll +++ b/llvm/test/Transforms/InstSimplify/floating-point-arithmetic.ll @@ -1,8 +1,8 @@ ; RUN: opt < %s -instsimplify -S | FileCheck %s -; fsub 0, (fsub 0, X) ==> X -; CHECK-LABEL: @fsub_0_0_x( -define float @fsub_0_0_x(float %a) { +; fsub -0.0, (fsub -0.0, X) ==> X +; CHECK-LABEL: @fsub_-0_-0_x( +define float @fsub_-0_-0_x(float %a) { %t1 = fsub float -0.0, %a %ret = fsub float -0.0, %t1 @@ -10,6 +10,26 @@ define float @fsub_0_0_x(float %a) { ret float %ret } +; fsub 0.0, (fsub -0.0, X) != X +; CHECK-LABEL: @fsub_0_-0_x( +define float @fsub_0_-0_x(float %a) { + %t1 = fsub float 0.0, %a + %ret = fsub float -0.0, %t1 + +; CHECK-NOT: ret float %a + ret float %ret +} + +; fsub -0.0, (fsub 0.0, X) != X +; CHECK-LABEL: @fsub_-0_0_x( +define float @fsub_-0_0_x(float %a) { + %t1 = fsub float -0.0, %a + %ret = fsub float 0.0, %t1 + +; CHECK-NOT: ret float %a + ret float %ret +} + ; fsub X, 0 ==> X ; CHECK-LABEL: @fsub_x_0( define float @fsub_x_0(float %a) {