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

This fold was added with:
83c2fb9f66
...but missed the commuted pattern:
https://alive2.llvm.org/ce/z/_tYEGy
This commit is contained in:
Sanjay Patel
2021-11-09 10:48:47 -05:00
parent ad48fc35e2
commit baa6a85130
2 changed files with 3 additions and 4 deletions

View File

@@ -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}));

View File

@@ -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