[llvm] r339266 - [InstCombine] fold fsub+fsub with common operand

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 8 09:04:48 PDT 2018


Author: spatel
Date: Wed Aug  8 09:04:48 2018
New Revision: 339266

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

This is a sibling to the simplify from:
rL339171

Modified:
    llvm/trunk/lib/Transforms/InstCombine/InstCombineAddSub.cpp
    llvm/trunk/test/Transforms/InstCombine/fast-math.ll

Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineAddSub.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineAddSub.cpp?rev=339266&r1=339265&r2=339266&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineAddSub.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineAddSub.cpp Wed Aug  8 09:04:48 2018
@@ -1907,6 +1907,14 @@ Instruction *InstCombiner::visitFSub(Bin
     return replaceInstUsesWith(I, V);
 
   if (I.hasAllowReassoc() && I.hasNoSignedZeros()) {
+    // (Y - X) - Y --> -X
+    if (match(Op0, m_FSub(m_Specific(Op1), m_Value(X))))
+      return BinaryOperator::CreateFNegFMF(X, &I);
+
+    // TODO: This performs reassociative folds for FP ops. Some fraction of the
+    // functionality has been subsumed by simple pattern matching here and in
+    // InstSimplify. We should let a dedicated reassociation pass handle more
+    // complex pattern matching and remove this from InstCombine.
     if (Value *V = FAddCombine(Builder).simplify(&I))
       return replaceInstUsesWith(I, V);
   }

Modified: llvm/trunk/test/Transforms/InstCombine/fast-math.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/fast-math.ll?rev=339266&r1=339265&r2=339266&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/fast-math.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/fast-math.ll Wed Aug  8 09:04:48 2018
@@ -335,8 +335,8 @@ define <2 x float> @fsub_fadd_common_op_
 
 define float @fsub_fsub_common_op_fneg(float %x, float %y) {
 ; CHECK-LABEL: @fsub_fsub_common_op_fneg(
-; CHECK-NEXT:    [[TMP1:%.*]] = fsub reassoc nsz float -0.000000e+00, [[X:%.*]]
-; CHECK-NEXT:    ret float [[TMP1]]
+; CHECK-NEXT:    [[R:%.*]] = fsub reassoc nsz float -0.000000e+00, [[X:%.*]]
+; CHECK-NEXT:    ret float [[R]]
 ;
   %s = fsub float %y, %x
   %r = fsub reassoc nsz float %s, %y
@@ -347,8 +347,7 @@ define float @fsub_fsub_common_op_fneg(f
 
 define <2 x float> @fsub_fsub_common_op_fneg_vec(<2 x float> %x, <2 x float> %y) {
 ; CHECK-LABEL: @fsub_fsub_common_op_fneg_vec(
-; CHECK-NEXT:    [[S:%.*]] = fsub <2 x float> [[Y:%.*]], [[X:%.*]]
-; CHECK-NEXT:    [[R:%.*]] = fsub reassoc nsz <2 x float> [[S]], [[Y]]
+; CHECK-NEXT:    [[R:%.*]] = fsub reassoc nsz <2 x float> <float -0.000000e+00, float -0.000000e+00>, [[X:%.*]]
 ; CHECK-NEXT:    ret <2 x float> [[R]]
 ;
   %s = fsub <2 x float> %y, %x




More information about the llvm-commits mailing list