From 7017a68c8bd669aecdf907fe442bf7a5422fc7e8 Mon Sep 17 00:00:00 2001 From: Sanjay Patel Date: Sat, 13 Jul 2019 12:54:48 +0000 Subject: [PATCH] [InstCombine] add tests for umin/umax via usub.sat; NFC git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@365999 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../InstCombine/saturating-add-sub.ll | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/test/Transforms/InstCombine/saturating-add-sub.ll b/test/Transforms/InstCombine/saturating-add-sub.ll index 364c80d205f..56e10626104 100644 --- a/test/Transforms/InstCombine/saturating-add-sub.ll +++ b/test/Transforms/InstCombine/saturating-add-sub.ll @@ -1614,3 +1614,75 @@ define i32 @unsigned_sat_constant_using_min_wrong_constant(i32 %x) { %r = add i32 %s, -42 ret i32 %r } + +define i8 @umax(i8 %a, i8 %b) { +; CHECK-LABEL: @umax( +; CHECK-NEXT: [[USUB:%.*]] = tail call i8 @llvm.usub.sat.i8(i8 [[A:%.*]], i8 [[B:%.*]]) +; CHECK-NEXT: [[R:%.*]] = add i8 [[USUB]], [[B]] +; CHECK-NEXT: ret i8 [[R]] +; + %usub = tail call i8 @llvm.usub.sat.i8(i8 %a, i8 %b) + %r = add i8 %usub, %b + ret i8 %r +} + +define <2 x i8> @umax_vec(<2 x i8> %a, <2 x i8> %b) { +; CHECK-LABEL: @umax_vec( +; CHECK-NEXT: [[USUB:%.*]] = tail call <2 x i8> @llvm.usub.sat.v2i8(<2 x i8> [[A:%.*]], <2 x i8> [[B:%.*]]) +; CHECK-NEXT: [[R:%.*]] = add <2 x i8> [[USUB]], [[B]] +; CHECK-NEXT: ret <2 x i8> [[R]] +; + %usub = tail call <2 x i8> @llvm.usub.sat.v2i8(<2 x i8> %a, <2 x i8> %b) + %r = add <2 x i8> %usub, %b + ret <2 x i8> %r +} + +define i8 @umax_extra_use(i8 %a, i8 %b) { +; CHECK-LABEL: @umax_extra_use( +; CHECK-NEXT: [[USUB:%.*]] = tail call i8 @llvm.usub.sat.i8(i8 [[A:%.*]], i8 [[B:%.*]]) +; CHECK-NEXT: call void @use(i8 [[USUB]]) +; CHECK-NEXT: [[R:%.*]] = add i8 [[USUB]], [[B]] +; CHECK-NEXT: ret i8 [[R]] +; + %usub = tail call i8 @llvm.usub.sat.i8(i8 %a, i8 %b) + call void @use(i8 %usub) + %r = add i8 %usub, %b + ret i8 %r +} + +define i8 @umin(i8 %a, i8 %b) { +; CHECK-LABEL: @umin( +; CHECK-NEXT: [[USUB:%.*]] = tail call i8 @llvm.usub.sat.i8(i8 [[A:%.*]], i8 [[B:%.*]]) +; CHECK-NEXT: [[R:%.*]] = sub i8 [[A]], [[USUB]] +; CHECK-NEXT: ret i8 [[R]] +; + %usub = tail call i8 @llvm.usub.sat.i8(i8 %a, i8 %b) + %r = sub i8 %a, %usub + ret i8 %r +} + +define <2 x i8> @umin_vec(<2 x i8> %a, <2 x i8> %b) { +; CHECK-LABEL: @umin_vec( +; CHECK-NEXT: [[USUB:%.*]] = tail call <2 x i8> @llvm.usub.sat.v2i8(<2 x i8> [[A:%.*]], <2 x i8> [[B:%.*]]) +; CHECK-NEXT: [[R:%.*]] = sub <2 x i8> [[A]], [[USUB]] +; CHECK-NEXT: ret <2 x i8> [[R]] +; + %usub = tail call <2 x i8> @llvm.usub.sat.v2i8(<2 x i8> %a, <2 x i8> %b) + %r = sub <2 x i8> %a, %usub + ret <2 x i8> %r +} + +define i8 @umin_extra_use(i8 %a, i8 %b) { +; CHECK-LABEL: @umin_extra_use( +; CHECK-NEXT: [[USUB:%.*]] = tail call i8 @llvm.usub.sat.i8(i8 [[A:%.*]], i8 [[B:%.*]]) +; CHECK-NEXT: call void @use(i8 [[USUB]]) +; CHECK-NEXT: [[R:%.*]] = sub i8 [[A]], [[USUB]] +; CHECK-NEXT: ret i8 [[R]] +; + %usub = tail call i8 @llvm.usub.sat.i8(i8 %a, i8 %b) + call void @use(i8 %usub) + %r = sub i8 %a, %usub + ret i8 %r +} + +declare void @use(i8) -- 2.40.0