Skip to content

Commit baa6a85

Browse files
committed
[InstCombine] allow commute in sub-of-umax fold
This fold was added with: 83c2fb9 ...but missed the commuted pattern: https://alive2.llvm.org/ce/z/_tYEGy
1 parent ad48fc3 commit baa6a85

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2171,7 +2171,7 @@ Instruction *InstCombinerImpl::visitSub(BinaryOperator &I) {
21712171
// umax(X, Op1) - Op1 --> usub.sat(X, Op1)
21722172
// TODO: The one-use restriction is not strictly necessary, but it may
21732173
// require improving other pattern matching and/or codegen.
2174-
if (match(Op0, m_OneUse(m_UMax(m_Value(X), m_Specific(Op1)))))
2174+
if (match(Op0, m_OneUse(m_c_UMax(m_Value(X), m_Specific(Op1)))))
21752175
return replaceInstUsesWith(
21762176
I, Builder.CreateIntrinsic(Intrinsic::usub_sat, {Ty}, {X, Op1}));
21772177

llvm/test/Transforms/InstCombine/sub-minmax.ll

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -501,9 +501,8 @@ define i8 @umin_not_sub_intrinsic_uses(i8 %x, i8 %y) {
501501

502502
define i8 @umax_sub_op0(i8 %x, i8 %y) {
503503
; CHECK-LABEL: @umax_sub_op0(
504-
; CHECK-NEXT: [[U:%.*]] = call i8 @llvm.umax.i8(i8 [[Y:%.*]], i8 [[X:%.*]])
505-
; CHECK-NEXT: [[R:%.*]] = sub i8 [[U]], [[Y]]
506-
; CHECK-NEXT: ret i8 [[R]]
504+
; CHECK-NEXT: [[TMP1:%.*]] = call i8 @llvm.usub.sat.i8(i8 [[X:%.*]], i8 [[Y:%.*]])
505+
; CHECK-NEXT: ret i8 [[TMP1]]
507506
;
508507
%u = call i8 @llvm.umax.i8(i8 %y, i8 %x)
509508
%r = sub i8 %u, %y

0 commit comments

Comments
 (0)