diff options
author | Sanjay Patel <spatel@rotateright.com> | 2018-09-11 22:40:20 +0000 |
---|---|---|
committer | Sanjay Patel <spatel@rotateright.com> | 2018-09-11 22:40:20 +0000 |
commit | 1cf0734b2f6b346993c41c18f4d6a9f2d1e11189 (patch) | |
tree | e282f5e9a4dbcde551704a7e42e3358bad860cbe /llvm/test | |
parent | 42e7cc1b0fdf3428ebd0dfd70a6e4efe162e1cd3 (diff) | |
download | bcm5719-llvm-1cf0734b2f6b346993c41c18f4d6a9f2d1e11189.tar.gz bcm5719-llvm-1cf0734b2f6b346993c41c18f4d6a9f2d1e11189.zip |
[InstCombine] add folds for unsigned-overflow compares
Name: op_ugt_sum
%a = add i8 %x, %y
%r = icmp ugt i8 %x, %a
=>
%notx = xor i8 %x, -1
%r = icmp ugt i8 %y, %notx
Name: sum_ult_op
%a = add i8 %x, %y
%r = icmp ult i8 %a, %x
=>
%notx = xor i8 %x, -1
%r = icmp ugt i8 %y, %notx
https://rise4fun.com/Alive/ZRxI
AFAICT, this doesn't interfere with any add-saturation patterns
because those have >1 use for the 'add'. But this should be
better for IR analysis and codegen in the basic cases.
This is another fold inspired by PR14613:
https://bugs.llvm.org/show_bug.cgi?id=14613
llvm-svn: 342004
Diffstat (limited to 'llvm/test')
-rw-r--r-- | llvm/test/Transforms/InstCombine/icmp-add.ll | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/llvm/test/Transforms/InstCombine/icmp-add.ll b/llvm/test/Transforms/InstCombine/icmp-add.ll index 4fe31e78a2a..24593640af2 100644 --- a/llvm/test/Transforms/InstCombine/icmp-add.ll +++ b/llvm/test/Transforms/InstCombine/icmp-add.ll @@ -377,8 +377,8 @@ define i1 @op_ugt_sum_commute1(i8 %p1, i8 %p2) { ; CHECK-LABEL: @op_ugt_sum_commute1( ; CHECK-NEXT: [[X:%.*]] = sdiv i8 42, [[P1:%.*]] ; CHECK-NEXT: [[Y:%.*]] = sdiv i8 42, [[P2:%.*]] -; CHECK-NEXT: [[A:%.*]] = add i8 [[X]], [[Y]] -; CHECK-NEXT: [[C:%.*]] = icmp ugt i8 [[X]], [[A]] +; CHECK-NEXT: [[TMP1:%.*]] = xor i8 [[X]], -1 +; CHECK-NEXT: [[C:%.*]] = icmp ugt i8 [[Y]], [[TMP1]] ; CHECK-NEXT: ret i1 [[C]] ; %x = sdiv i8 42, %p1 @@ -392,8 +392,8 @@ define <2 x i1> @op_ugt_sum_vec_commute2(<2 x i8> %p1, <2 x i8> %p2) { ; CHECK-LABEL: @op_ugt_sum_vec_commute2( ; CHECK-NEXT: [[X:%.*]] = sdiv <2 x i8> <i8 42, i8 -42>, [[P1:%.*]] ; CHECK-NEXT: [[Y:%.*]] = sdiv <2 x i8> <i8 42, i8 -42>, [[P2:%.*]] -; CHECK-NEXT: [[A:%.*]] = add <2 x i8> [[Y]], [[X]] -; CHECK-NEXT: [[C:%.*]] = icmp ugt <2 x i8> [[X]], [[A]] +; CHECK-NEXT: [[TMP1:%.*]] = xor <2 x i8> [[X]], <i8 -1, i8 -1> +; CHECK-NEXT: [[C:%.*]] = icmp ugt <2 x i8> [[Y]], [[TMP1]] ; CHECK-NEXT: ret <2 x i1> [[C]] ; %x = sdiv <2 x i8> <i8 42, i8 -42>, %p1 @@ -424,8 +424,8 @@ define <2 x i1> @sum_ult_op_vec_commute1(<2 x i8> %p1, <2 x i8> %p2) { ; CHECK-LABEL: @sum_ult_op_vec_commute1( ; CHECK-NEXT: [[X:%.*]] = sdiv <2 x i8> <i8 42, i8 -42>, [[P1:%.*]] ; CHECK-NEXT: [[Y:%.*]] = sdiv <2 x i8> <i8 -42, i8 42>, [[P2:%.*]] -; CHECK-NEXT: [[A:%.*]] = add <2 x i8> [[X]], [[Y]] -; CHECK-NEXT: [[C:%.*]] = icmp ult <2 x i8> [[A]], [[X]] +; CHECK-NEXT: [[TMP1:%.*]] = xor <2 x i8> [[X]], <i8 -1, i8 -1> +; CHECK-NEXT: [[C:%.*]] = icmp ugt <2 x i8> [[Y]], [[TMP1]] ; CHECK-NEXT: ret <2 x i1> [[C]] ; %x = sdiv <2 x i8> <i8 42, i8 -42>, %p1 @@ -439,8 +439,8 @@ define i1 @sum_ult_op_commute2(i8 %p1, i8 %p2) { ; CHECK-LABEL: @sum_ult_op_commute2( ; CHECK-NEXT: [[X:%.*]] = sdiv i8 42, [[P1:%.*]] ; CHECK-NEXT: [[Y:%.*]] = sdiv i8 42, [[P2:%.*]] -; CHECK-NEXT: [[A:%.*]] = add i8 [[Y]], [[X]] -; CHECK-NEXT: [[C:%.*]] = icmp ult i8 [[A]], [[X]] +; CHECK-NEXT: [[TMP1:%.*]] = xor i8 [[X]], -1 +; CHECK-NEXT: [[C:%.*]] = icmp ugt i8 [[Y]], [[TMP1]] ; CHECK-NEXT: ret i1 [[C]] ; %x = sdiv i8 42, %p1 |