diff options
author | Nikita Popov <nikita.ppv@gmail.com> | 2019-03-20 18:00:27 +0000 |
---|---|---|
committer | Nikita Popov <nikita.ppv@gmail.com> | 2019-03-20 18:00:27 +0000 |
commit | 37cf25c3c6819d3ed55915903b5cea91f9d367b0 (patch) | |
tree | bba326a807c179178ef4cd887585d2e561e6042b /llvm/test/Transforms/InstCombine/uadd-with-overflow.ll | |
parent | becd797a97847270df668b646da9d1d9e9853409 (diff) | |
download | bcm5719-llvm-37cf25c3c6819d3ed55915903b5cea91f9d367b0.tar.gz bcm5719-llvm-37cf25c3c6819d3ed55915903b5cea91f9d367b0.zip |
[InstCombine] Fold add nuw + uadd.with.overflow
Fold add nuw and uadd.with.overflow with constants if the
addition does not overflow.
Part of https://bugs.llvm.org/show_bug.cgi?id=38146.
Patch by Dan Robertson.
Differential Revision: https://reviews.llvm.org/D59471
llvm-svn: 356584
Diffstat (limited to 'llvm/test/Transforms/InstCombine/uadd-with-overflow.ll')
-rw-r--r-- | llvm/test/Transforms/InstCombine/uadd-with-overflow.ll | 20 |
1 files changed, 8 insertions, 12 deletions
diff --git a/llvm/test/Transforms/InstCombine/uadd-with-overflow.ll b/llvm/test/Transforms/InstCombine/uadd-with-overflow.ll index c9776f43528..b306cb619f8 100644 --- a/llvm/test/Transforms/InstCombine/uadd-with-overflow.ll +++ b/llvm/test/Transforms/InstCombine/uadd-with-overflow.ll @@ -11,9 +11,8 @@ declare { i8, i1 } @llvm.uadd.with.overflow.i8(i8, i8) define { i32, i1 } @simple_fold(i32 %x) { ; CHECK-LABEL: @simple_fold( -; CHECK-NEXT: [[A:%.*]] = add nuw i32 [[X:%.*]], 7 -; CHECK-NEXT: [[B:%.*]] = tail call { i32, i1 } @llvm.uadd.with.overflow.i32(i32 [[A]], i32 13) -; CHECK-NEXT: ret { i32, i1 } [[B]] +; CHECK-NEXT: [[TMP1:%.*]] = call { i32, i1 } @llvm.uadd.with.overflow.i32(i32 [[X:%.*]], i32 20) +; CHECK-NEXT: ret { i32, i1 } [[TMP1]] ; %a = add nuw i32 %x, 7 %b = tail call { i32, i1 } @llvm.uadd.with.overflow.i32(i32 %a, i32 13) @@ -22,9 +21,8 @@ define { i32, i1 } @simple_fold(i32 %x) { define { i8, i1 } @fold_on_constant_add_no_overflow(i8 %x) { ; CHECK-LABEL: @fold_on_constant_add_no_overflow( -; CHECK-NEXT: [[A:%.*]] = add nuw i8 [[X:%.*]], -56 -; CHECK-NEXT: [[B:%.*]] = tail call { i8, i1 } @llvm.uadd.with.overflow.i8(i8 [[A]], i8 55) -; CHECK-NEXT: ret { i8, i1 } [[B]] +; CHECK-NEXT: [[TMP1:%.*]] = call { i8, i1 } @llvm.uadd.with.overflow.i8(i8 [[X:%.*]], i8 -1) +; CHECK-NEXT: ret { i8, i1 } [[TMP1]] ; %a = add nuw i8 %x, 200 %b = tail call { i8, i1 } @llvm.uadd.with.overflow.i8(i8 %a, i8 55) @@ -65,9 +63,8 @@ define { <2 x i8>, <2 x i1> } @no_fold_vector_overflow(<2 x i8> %x) { define { <2 x i32>, <2 x i1> } @fold_simple_splat_constant(<2 x i32> %x) { ; CHECK-LABEL: @fold_simple_splat_constant( -; CHECK-NEXT: [[A:%.*]] = add nuw <2 x i32> [[X:%.*]], <i32 12, i32 12> -; CHECK-NEXT: [[B:%.*]] = tail call { <2 x i32>, <2 x i1> } @llvm.uadd.with.overflow.v2i32(<2 x i32> [[A]], <2 x i32> <i32 30, i32 30>) -; CHECK-NEXT: ret { <2 x i32>, <2 x i1> } [[B]] +; CHECK-NEXT: [[TMP1:%.*]] = call { <2 x i32>, <2 x i1> } @llvm.uadd.with.overflow.v2i32(<2 x i32> [[X:%.*]], <2 x i32> <i32 42, i32 42>) +; CHECK-NEXT: ret { <2 x i32>, <2 x i1> } [[TMP1]] ; %a = add nuw <2 x i32> %x, <i32 12, i32 12> %b = tail call { <2 x i32>, <2 x i1> } @llvm.uadd.with.overflow.v2i32(<2 x i32> %a, <2 x i32> <i32 30, i32 30>) @@ -98,9 +95,8 @@ define { <2 x i32>, <2 x i1> } @no_fold_splat_not_constant(<2 x i32> %x, <2 x i3 define { i32, i1 } @fold_nuwnsw(i32 %x) { ; CHECK-LABEL: @fold_nuwnsw( -; CHECK-NEXT: [[A:%.*]] = add nuw nsw i32 [[X:%.*]], 12 -; CHECK-NEXT: [[B:%.*]] = tail call { i32, i1 } @llvm.uadd.with.overflow.i32(i32 [[A]], i32 30) -; CHECK-NEXT: ret { i32, i1 } [[B]] +; CHECK-NEXT: [[TMP1:%.*]] = call { i32, i1 } @llvm.uadd.with.overflow.i32(i32 [[X:%.*]], i32 42) +; CHECK-NEXT: ret { i32, i1 } [[TMP1]] ; %a = add nuw nsw i32 %x, 12 %b = tail call { i32, i1 } @llvm.uadd.with.overflow.i32(i32 %a, i32 30) |