From: Sanjay Patel Date: Sun, 17 Feb 2019 15:09:41 +0000 (+0000) Subject: [InstCombine] add tests for unsigned saturated add; NFC X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=58ac5f316a1d414e98a83fa2e631d897e268381b;p=llvm [InstCombine] add tests for unsigned saturated add; NFC We're missing IR canonicalizations for this op as shown in D51929. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@354219 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/test/Transforms/InstCombine/saturating-add-sub.ll b/test/Transforms/InstCombine/saturating-add-sub.ll index f8eb7917618..451f60ad8af 100644 --- a/test/Transforms/InstCombine/saturating-add-sub.ll +++ b/test/Transforms/InstCombine/saturating-add-sub.ll @@ -639,6 +639,38 @@ define <2 x i8> @test_vector_ssub_neg_nneg(<2 x i8> %a) { ; Raw IR tests +define i32 @uadd_sat(i32 %x, i32 %y) { +; CHECK-LABEL: @uadd_sat( +; CHECK-NEXT: [[NOTX:%.*]] = xor i32 [[X:%.*]], -1 +; CHECK-NEXT: [[A:%.*]] = add i32 [[Y:%.*]], [[X]] +; CHECK-NEXT: [[C:%.*]] = icmp ult i32 [[NOTX]], [[Y]] +; CHECK-NEXT: [[R:%.*]] = select i1 [[C]], i32 -1, i32 [[A]] +; CHECK-NEXT: ret i32 [[R]] +; + %notx = xor i32 %x, -1 + %a = add i32 %y, %x + %c = icmp ult i32 %notx, %y + %r = select i1 %c, i32 -1, i32 %a + ret i32 %r +} + +define i32 @uadd_sat_commute1(i32 %xp, i32 %y) { +; CHECK-LABEL: @uadd_sat_commute1( +; CHECK-NEXT: [[X:%.*]] = urem i32 42, [[XP:%.*]] +; CHECK-NEXT: [[NOTX:%.*]] = xor i32 [[X]], -1 +; CHECK-NEXT: [[A:%.*]] = add i32 [[X]], [[Y:%.*]] +; CHECK-NEXT: [[C:%.*]] = icmp ult i32 [[NOTX]], [[Y]] +; CHECK-NEXT: [[R:%.*]] = select i1 [[C]], i32 -1, i32 [[A]] +; CHECK-NEXT: ret i32 [[R]] +; + %x = urem i32 42, %xp ; thwart complexity-based-canonicalization + %notx = xor i32 %x, -1 + %a = add i32 %x, %y + %c = icmp ult i32 %notx, %y + %r = select i1 %c, i32 -1, i32 %a + ret i32 %r +} + define i32 @uadd_sat_constant(i32 %x) { ; CHECK-LABEL: @uadd_sat_constant( ; CHECK-NEXT: [[A:%.*]] = add i32 [[X:%.*]], 42