diff options
author | Sanjay Patel <spatel@rotateright.com> | 2019-02-17 15:09:41 +0000 |
---|---|---|
committer | Sanjay Patel <spatel@rotateright.com> | 2019-02-17 15:09:41 +0000 |
commit | 3e1193743c433e2fcc0b47912b425844deeaebe1 (patch) | |
tree | e14d14ddc22c58beef684b16bd5bbf2c150a3dc1 | |
parent | 0f943269a01f0796c59a849f3b38e44154811e51 (diff) | |
download | bcm5719-llvm-3e1193743c433e2fcc0b47912b425844deeaebe1.tar.gz bcm5719-llvm-3e1193743c433e2fcc0b47912b425844deeaebe1.zip |
[InstCombine] add tests for unsigned saturated add; NFC
We're missing IR canonicalizations for this op as shown in D51929.
llvm-svn: 354219
-rw-r--r-- | llvm/test/Transforms/InstCombine/saturating-add-sub.ll | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/llvm/test/Transforms/InstCombine/saturating-add-sub.ll b/llvm/test/Transforms/InstCombine/saturating-add-sub.ll index f8eb7917618..451f60ad8af 100644 --- a/llvm/test/Transforms/InstCombine/saturating-add-sub.ll +++ b/llvm/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 |