[llvm] r339174 - [InstSimplify] fold fadd+fsub with common operand

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 7 13:23:49 PDT 2018


Author: spatel
Date: Tue Aug  7 13:23:49 2018
New Revision: 339174

URL: http://llvm.org/viewvc/llvm-project?rev=339174&view=rev
Log:
[InstSimplify] fold fadd+fsub with common operand

Modified:
    llvm/trunk/lib/Analysis/InstructionSimplify.cpp
    llvm/trunk/test/Transforms/InstSimplify/floating-point-arithmetic.ll

Modified: llvm/trunk/lib/Analysis/InstructionSimplify.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/InstructionSimplify.cpp?rev=339174&r1=339173&r2=339174&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/InstructionSimplify.cpp (original)
+++ llvm/trunk/lib/Analysis/InstructionSimplify.cpp Tue Aug  7 13:23:49 2018
@@ -4397,8 +4397,10 @@ static Value *SimplifyFSubInst(Value *Op
     return Constant::getNullValue(Op0->getType());
 
   // Y - (Y - X) --> X
+  // (X + Y) - Y --> X
   if (FMF.noSignedZeros() && FMF.allowReassoc() &&
-      match(Op1, m_FSub(m_Specific(Op0), m_Value(X))))
+      (match(Op1, m_FSub(m_Specific(Op0), m_Value(X))) ||
+       match(Op0, m_c_FAdd(m_Specific(Op1), m_Value(X)))))
     return X;
 
   return nullptr;

Modified: llvm/trunk/test/Transforms/InstSimplify/floating-point-arithmetic.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstSimplify/floating-point-arithmetic.ll?rev=339174&r1=339173&r2=339174&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstSimplify/floating-point-arithmetic.ll (original)
+++ llvm/trunk/test/Transforms/InstSimplify/floating-point-arithmetic.ll Tue Aug  7 13:23:49 2018
@@ -799,9 +799,7 @@ define float @fsub_fsub_wrong_common_op_
 
 define float @fadd_fsub_common_op(float %x, float %y) {
 ; CHECK-LABEL: @fadd_fsub_common_op(
-; CHECK-NEXT:    [[A:%.*]] = fadd float [[Y:%.*]], [[X:%.*]]
-; CHECK-NEXT:    [[R:%.*]] = fsub reassoc nsz float [[A]], [[Y]]
-; CHECK-NEXT:    ret float [[R]]
+; CHECK-NEXT:    ret float [[X:%.*]]
 ;
   %a = fadd float %y, %x
   %r = fsub reassoc nsz float %a, %y
@@ -812,9 +810,7 @@ define float @fadd_fsub_common_op(float
 
 define <2 x float> @fadd_fsub_common_op_commute_vec(<2 x float> %x, <2 x float> %y) {
 ; CHECK-LABEL: @fadd_fsub_common_op_commute_vec(
-; CHECK-NEXT:    [[A:%.*]] = fadd <2 x float> [[X:%.*]], [[Y:%.*]]
-; CHECK-NEXT:    [[R:%.*]] = fsub reassoc nsz <2 x float> [[A]], [[Y]]
-; CHECK-NEXT:    ret <2 x float> [[R]]
+; CHECK-NEXT:    ret <2 x float> [[X:%.*]]
 ;
   %a = fadd <2 x float> %x, %y
   %r = fsub reassoc nsz <2 x float> %a, %y




More information about the llvm-commits mailing list