From 27148536f0503cc565d2a2f083a4bffb814a5fe3 Mon Sep 17 00:00:00 2001 From: Cameron McInally Date: Mon, 20 May 2019 13:13:35 +0000 Subject: [PATCH] [InstSimplify] Teach fsub -0.0, (fneg X) ==> X about unary fneg Differential Revision: https://reviews.llvm.org/D62077 llvm-svn: 361151 --- lib/Analysis/InstructionSimplify.cpp | 3 ++- .../InstSimplify/floating-point-arithmetic.ll | 12 +++--------- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/lib/Analysis/InstructionSimplify.cpp b/lib/Analysis/InstructionSimplify.cpp index f97daec9556..e7f96b11b0a 100644 --- a/lib/Analysis/InstructionSimplify.cpp +++ b/lib/Analysis/InstructionSimplify.cpp @@ -4404,9 +4404,10 @@ static Value *SimplifyFSubInst(Value *Op0, Value *Op1, FastMathFlags FMF, return Op0; // fsub -0.0, (fsub -0.0, X) ==> X + // fsub -0.0, (fneg X) ==> X Value *X; if (match(Op0, m_NegZeroFP()) && - match(Op1, m_FSub(m_NegZeroFP(), m_Value(X)))) + match(Op1, m_FNeg(m_Value(X)))) return X; // fsub 0.0, (fsub 0.0, X) ==> X if signed zeros are ignored. diff --git a/test/Transforms/InstSimplify/floating-point-arithmetic.ll b/test/Transforms/InstSimplify/floating-point-arithmetic.ll index ee8a6451fe7..ee097ffab09 100644 --- a/test/Transforms/InstSimplify/floating-point-arithmetic.ll +++ b/test/Transforms/InstSimplify/floating-point-arithmetic.ll @@ -60,9 +60,7 @@ define float @fsub_-0_-0_x(float %a) { ; fsub -0.0, (fneg X) ==> X define float @fneg_x(float %a) { ; CHECK-LABEL: @fneg_x( -; CHECK-NEXT: %t1 = fneg float %a -; CHECK-NEXT: %ret = fsub float -0.000000e+00, %t1 -; CHECK-NEXT: ret float %ret +; CHECK-NEXT: ret float [[A:%.*]] ; %t1 = fneg float %a %ret = fsub float -0.0, %t1 @@ -80,9 +78,7 @@ define <2 x float> @fsub_-0_-0_x_vec(<2 x float> %a) { define <2 x float> @fneg_x_vec(<2 x float> %a) { ; CHECK-LABEL: @fneg_x_vec( -; CHECK-NEXT: %t1 = fneg <2 x float> %a -; CHECK-NEXT: %ret = fsub <2 x float> , %t1 -; CHECK-NEXT: ret <2 x float> %ret +; CHECK-NEXT: ret <2 x float> [[A:%.*]] ; %t1 = fneg <2 x float> %a %ret = fsub <2 x float> , %t1 @@ -100,9 +96,7 @@ define <2 x float> @fsub_-0_-0_x_vec_undef_elts(<2 x float> %a) { define <2 x float> @fneg_x_vec_undef_elts(<2 x float> %a) { ; CHECK-LABEL: @fneg_x_vec_undef_elts( -; CHECK-NEXT: %t1 = fneg <2 x float> %a -; CHECK-NEXT: %ret = fsub <2 x float> , %t1 -; CHECK-NEXT: ret <2 x float> %ret +; CHECK-NEXT: ret <2 x float> [[A:%.*]] ; %t1 = fneg <2 x float> %a %ret = fsub <2 x float> , %t1