[llvm] baa6a85 - [InstCombine] allow commute in sub-of-umax fold

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 9 08:05:08 PST 2021


Author: Sanjay Patel
Date: 2021-11-09T10:50:11-05:00
New Revision: baa6a851308dceca141a191847bc6e1a526eea17

URL: https://github.com/llvm/llvm-project/commit/baa6a851308dceca141a191847bc6e1a526eea17
DIFF: https://github.com/llvm/llvm-project/commit/baa6a851308dceca141a191847bc6e1a526eea17.diff

LOG: [InstCombine] allow commute in sub-of-umax fold

This fold was added with:
83c2fb9f66be
...but missed the commuted pattern:
https://alive2.llvm.org/ce/z/_tYEGy

Added: 
    

Modified: 
    llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
    llvm/test/Transforms/InstCombine/sub-minmax.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
index 2c43158890f9..3e0cc549b2b5 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
@@ -2171,7 +2171,7 @@ Instruction *InstCombinerImpl::visitSub(BinaryOperator &I) {
   // umax(X, Op1) - Op1 --> usub.sat(X, Op1)
   // TODO: The one-use restriction is not strictly necessary, but it may
   //       require improving other pattern matching and/or codegen.
-  if (match(Op0, m_OneUse(m_UMax(m_Value(X), m_Specific(Op1)))))
+  if (match(Op0, m_OneUse(m_c_UMax(m_Value(X), m_Specific(Op1)))))
     return replaceInstUsesWith(
         I, Builder.CreateIntrinsic(Intrinsic::usub_sat, {Ty}, {X, Op1}));
 

diff  --git a/llvm/test/Transforms/InstCombine/sub-minmax.ll b/llvm/test/Transforms/InstCombine/sub-minmax.ll
index b039c93d5c19..5fc5738a43e6 100644
--- a/llvm/test/Transforms/InstCombine/sub-minmax.ll
+++ b/llvm/test/Transforms/InstCombine/sub-minmax.ll
@@ -501,9 +501,8 @@ define i8 @umin_not_sub_intrinsic_uses(i8 %x, i8 %y) {
 
 define i8 @umax_sub_op0(i8 %x, i8 %y) {
 ; CHECK-LABEL: @umax_sub_op0(
-; CHECK-NEXT:    [[U:%.*]] = call i8 @llvm.umax.i8(i8 [[Y:%.*]], i8 [[X:%.*]])
-; CHECK-NEXT:    [[R:%.*]] = sub i8 [[U]], [[Y]]
-; CHECK-NEXT:    ret i8 [[R]]
+; CHECK-NEXT:    [[TMP1:%.*]] = call i8 @llvm.usub.sat.i8(i8 [[X:%.*]], i8 [[Y:%.*]])
+; CHECK-NEXT:    ret i8 [[TMP1]]
 ;
   %u = call i8 @llvm.umax.i8(i8 %y, i8 %x)
   %r = sub i8 %u, %y


        


More information about the llvm-commits mailing list