[llvm] r361047 - [InstSimplify] Add unary fneg to `fsub 0.0, (fneg X) ==> X` transform

Cameron McInally via llvm-commits llvm-commits at lists.llvm.org
Fri May 17 09:47:00 PDT 2019


Author: mcinally
Date: Fri May 17 09:47:00 2019
New Revision: 361047

URL: http://llvm.org/viewvc/llvm-project?rev=361047&view=rev
Log:
[InstSimplify] Add unary fneg to `fsub 0.0, (fneg X) ==> X` transform

Differential Revision: https://reviews.llvm.org/D62013

Modified:
    llvm/trunk/lib/Analysis/InstructionSimplify.cpp
    llvm/trunk/test/Transforms/InstSimplify/fast-math.ll

Modified: llvm/trunk/lib/Analysis/InstructionSimplify.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/InstructionSimplify.cpp?rev=361047&r1=361046&r2=361047&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/InstructionSimplify.cpp (original)
+++ llvm/trunk/lib/Analysis/InstructionSimplify.cpp Fri May 17 09:47:00 2019
@@ -4400,8 +4400,10 @@ static Value *SimplifyFSubInst(Value *Op
     return X;
 
   // fsub 0.0, (fsub 0.0, X) ==> X if signed zeros are ignored.
+  // fsub 0.0, (fneg X) ==> X if signed zeros are ignored.
   if (FMF.noSignedZeros() && match(Op0, m_AnyZeroFP()) &&
-      match(Op1, m_FSub(m_AnyZeroFP(), m_Value(X))))
+      (match(Op1, m_FSub(m_AnyZeroFP(), m_Value(X))) ||
+       match(Op1, m_FNeg(m_Value(X)))))
     return X;
 
   // fsub nnan x, x ==> 0.0

Modified: llvm/trunk/test/Transforms/InstSimplify/fast-math.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstSimplify/fast-math.ll?rev=361047&r1=361046&r2=361047&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstSimplify/fast-math.ll (original)
+++ llvm/trunk/test/Transforms/InstSimplify/fast-math.ll Fri May 17 09:47:00 2019
@@ -219,9 +219,7 @@ define float @fsub_0_0_x(float %a) {
 ; fsub nsz 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 nsz float 0.000000e+00, [[T1]]
-; CHECK-NEXT:    ret float [[RET]]
+; CHECK-NEXT:    ret float [[A:%.*]]
 ;
   %t1 = fneg float %a
   %ret = fsub nsz float 0.0, %t1
@@ -239,9 +237,7 @@ define <2 x float> @fsub_0_0_x_vec_undef
 
 define <2 x float> @fneg_x_vec_undef1(<2 x float> %a) {
 ; CHECK-LABEL: @fneg_x_vec_undef1(
-; CHECK-NEXT:    [[T1:%.*]] = fneg <2 x float> [[A:%.*]]
-; CHECK-NEXT:    [[RET:%.*]] = fsub nsz <2 x float> <float 0.000000e+00, float undef>, [[T1]]
-; CHECK-NEXT:    ret <2 x float> [[RET]]
+; CHECK-NEXT:    ret <2 x float> [[A:%.*]]
 ;
   %t1 = fneg <2 x float> %a
   %ret = fsub nsz <2 x float> <float 0.0, float undef>, %t1




More information about the llvm-commits mailing list