[llvm] [InstCombine] simplify `icmp pred x, ~x` (PR #73990)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 9 18:35:44 PST 2024
================
@@ -5,6 +5,521 @@ declare void @llvm.assume(i1)
declare void @barrier()
declare void @use.i8(i8)
+; X op ~X tests. op signed
+; X s< ~X --> X s< 0
+define i1 @src_slt(i8 %x) {
+; CHECK-LABEL: @src_slt(
+; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[X:%.*]], 0
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %not = xor i8 %x, -1
+ %cmp = icmp slt i8 %x, %not
+ ret i1 %cmp
+}
+define i1 @src_slt_i128(i128 %x) {
+; CHECK-LABEL: @src_slt_i128(
+; CHECK-NEXT: [[CMP:%.*]] = icmp slt i128 [[X:%.*]], 0
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %not = xor i128 %x, -1
+ %cmp = icmp slt i128 %x, %not
+ ret i1 %cmp
+}
+; X s> ~X --> X s> -1
+define i1 @src_sgt(i8 %x) {
+; CHECK-LABEL: @src_sgt(
+; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i8 [[X:%.*]], -1
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %not = xor i8 %x, -1
+ %cmp = icmp sgt i8 %x, %not
+ ret i1 %cmp
+}
+define i1 @src_sgt_i128(i128 %x) {
+; CHECK-LABEL: @src_sgt_i128(
+; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i128 [[X:%.*]], -1
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %not = xor i128 %x, -1
+ %cmp = icmp sgt i128 %x, %not
+ ret i1 %cmp
+}
+; X s<= ~X --> X s< 0
+define i1 @src_sle(i8 %x) {
----------------
ParkHanbum wrote:
@nikic maybe this problem solved after implemented code moved to `foidIcmpXorXX`. how do you think?
https://github.com/llvm/llvm-project/pull/73990
More information about the llvm-commits
mailing list