[llvm] [InstCombine] simplify `icmp pred x, ~x` (PR #73990)
via llvm-commits
llvm-commits at lists.llvm.org
Sat Mar 23 09:09:50 PDT 2024
https://github.com/ParkHanbum updated https://github.com/llvm/llvm-project/pull/73990
>From 1d3b4c7091f14998b36f870bb10a06d954cb133a Mon Sep 17 00:00:00 2001
From: Hanbum Park <kese111 at gmail.com>
Date: Fri, 1 Dec 2023 06:28:23 +0900
Subject: [PATCH 1/2] [InstCombine] Add test for simplify `X comp X^Neg_C`
This patch add testcase for comparison between X and X^Neg_X.
comparison between X and X^Neg_C is determined solely by
presence of the sign bit, so we can simplify it to checking
whether X is negative or not.
---
.../Transforms/InstCombine/icmp-of-xor-x.ll | 521 ++++++++++++++++++
1 file changed, 521 insertions(+)
diff --git a/llvm/test/Transforms/InstCombine/icmp-of-xor-x.ll b/llvm/test/Transforms/InstCombine/icmp-of-xor-x.ll
index fd61c8a301662e..b8cd60c9535b7f 100644
--- a/llvm/test/Transforms/InstCombine/icmp-of-xor-x.ll
+++ b/llvm/test/Transforms/InstCombine/icmp-of-xor-x.ll
@@ -5,6 +5,527 @@ declare void @llvm.assume(i1)
declare void @barrier()
declare void @use.i8(i8)
+; X comp X^Neg_C tests, signed.
+; X s< X^Neg_C --> X s< 0
+define i1 @src_slt(i8 %x) {
+; CHECK-LABEL: @src_slt(
+; CHECK-NEXT: [[NOT:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i8 [[NOT]], [[X]]
+; 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: [[NOT:%.*]] = xor i128 [[X:%.*]], -1
+; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i128 [[NOT]], [[X]]
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %not = xor i128 %x, -1
+ %cmp = icmp slt i128 %x, %not
+ ret i1 %cmp
+}
+; X s> X^Neg_C --> X s> -1
+define i1 @src_sgt(i8 %x) {
+; CHECK-LABEL: @src_sgt(
+; CHECK-NEXT: [[NOT:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[NOT]], [[X]]
+; 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: [[NOT:%.*]] = xor i128 [[X:%.*]], -1
+; CHECK-NEXT: [[CMP:%.*]] = icmp slt i128 [[NOT]], [[X]]
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %not = xor i128 %x, -1
+ %cmp = icmp sgt i128 %x, %not
+ ret i1 %cmp
+}
+; X s<= X^Neg_C --> X s< 0
+define i1 @src_sle(i8 %x) {
+; CHECK-LABEL: @src_sle(
+; CHECK-NEXT: [[NOT:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i8 [[NOT]], [[X]]
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %not = xor i8 %x, -1
+ %cmp = icmp sle i8 %x, %not
+ ret i1 %cmp
+}
+define i1 @src_sle_i128(i128 %x) {
+; CHECK-LABEL: @src_sle_i128(
+; CHECK-NEXT: [[NOT:%.*]] = xor i128 [[X:%.*]], -1
+; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i128 [[NOT]], [[X]]
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %not = xor i128 %x, -1
+ %cmp = icmp sle i128 %x, %not
+ ret i1 %cmp
+}
+; X s>= X^Neg_C --> X s> -1
+define i1 @src_sge(i8 %x) {
+; CHECK-LABEL: @src_sge(
+; CHECK-NEXT: [[NOT:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[NOT]], [[X]]
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %not = xor i8 %x, -1
+ %cmp = icmp sge i8 %x, %not
+ ret i1 %cmp
+}
+define i1 @src_sge_i128(i128 %x) {
+; CHECK-LABEL: @src_sge_i128(
+; CHECK-NEXT: [[NOT:%.*]] = xor i128 [[X:%.*]], -1
+; CHECK-NEXT: [[CMP:%.*]] = icmp slt i128 [[NOT]], [[X]]
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %not = xor i128 %x, -1
+ %cmp = icmp sge i128 %x, %not
+ ret i1 %cmp
+}
+; X comp X^C tests, signed. commutative
+; X^Neg_C s< X --> X s> -1
+define i1 @src_slt_comm(i8 %x) {
+; CHECK-LABEL: @src_slt_comm(
+; CHECK-NEXT: [[NOT:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[NOT]], [[X]]
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %not = xor i8 %x, -1
+ %cmp = icmp slt i8 %not, %x
+ ret i1 %cmp
+}
+define i1 @src_slt_i128_comm(i128 %x) {
+; CHECK-LABEL: @src_slt_i128_comm(
+; CHECK-NEXT: [[NOT:%.*]] = xor i128 [[X:%.*]], -1
+; CHECK-NEXT: [[CMP:%.*]] = icmp slt i128 [[NOT]], [[X]]
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %not = xor i128 %x, -1
+ %cmp = icmp slt i128 %not, %x
+ ret i1 %cmp
+}
+; X^Neg_C s> X --> X s< 0
+define i1 @src_sgt_comm(i8 %x) {
+; CHECK-LABEL: @src_sgt_comm(
+; CHECK-NEXT: [[NOT:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i8 [[NOT]], [[X]]
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %not = xor i8 %x, -1
+ %cmp = icmp sgt i8 %not, %x
+ ret i1 %cmp
+}
+define i1 @src_sgt_i128_comm(i128 %x) {
+; CHECK-LABEL: @src_sgt_i128_comm(
+; CHECK-NEXT: [[NOT:%.*]] = xor i128 [[X:%.*]], -1
+; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i128 [[NOT]], [[X]]
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %not = xor i128 %x, -1
+ %cmp = icmp sgt i128 %not, %x
+ ret i1 %cmp
+}
+; X^Neg_C s<= X --> X s> -1
+define i1 @src_sle_comm(i8 %x) {
+; CHECK-LABEL: @src_sle_comm(
+; CHECK-NEXT: [[NOT:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[NOT]], [[X]]
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %not = xor i8 %x, -1
+ %cmp = icmp sle i8 %not, %x
+ ret i1 %cmp
+}
+define i1 @src_sle_i128_comm(i128 %x) {
+; CHECK-LABEL: @src_sle_i128_comm(
+; CHECK-NEXT: [[NOT:%.*]] = xor i128 [[X:%.*]], -1
+; CHECK-NEXT: [[CMP:%.*]] = icmp slt i128 [[NOT]], [[X]]
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %not = xor i128 %x, -1
+ %cmp = icmp sle i128 %not, %x
+ ret i1 %cmp
+}
+; X^Neg_C s>= X --> X s< 0
+define i1 @src_sge_comm(i8 %x) {
+; CHECK-LABEL: @src_sge_comm(
+; CHECK-NEXT: [[NOT:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i8 [[NOT]], [[X]]
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %not = xor i8 %x, -1
+ %cmp = icmp sge i8 %not, %x
+ ret i1 %cmp
+}
+define i1 @src_sge_i128_comm(i128 %x) {
+; CHECK-LABEL: @src_sge_i128_comm(
+; CHECK-NEXT: [[NOT:%.*]] = xor i128 [[X:%.*]], -1
+; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i128 [[NOT]], [[X]]
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %not = xor i128 %x, -1
+ %cmp = icmp sge i128 %not, %x
+ ret i1 %cmp
+}
+
+; X comp X^Neg_C tests, unsigned.
+; X u< X^Neg_C --> X s> -1
+define i1 @src_ult(i8 %x) {
+; CHECK-LABEL: @src_ult(
+; CHECK-NEXT: [[NOT:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i8 [[NOT]], [[X]]
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %not = xor i8 %x, -1
+ %cmp = icmp ult i8 %x, %not
+ ret i1 %cmp
+}
+define i1 @src_ult_i128(i128 %x) {
+; CHECK-LABEL: @src_ult_i128(
+; CHECK-NEXT: [[NOT:%.*]] = xor i128 [[X:%.*]], -1
+; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i128 [[NOT]], [[X]]
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %not = xor i128 %x, -1
+ %cmp = icmp ult i128 %x, %not
+ ret i1 %cmp
+}
+; X u> X^Neg_C --> X s< 0
+define i1 @src_ugt(i8 %x) {
+; CHECK-LABEL: @src_ugt(
+; CHECK-NEXT: [[NOT:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT: [[CMP:%.*]] = icmp ult i8 [[NOT]], [[X]]
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %not = xor i8 %x, -1
+ %cmp = icmp ugt i8 %x, %not
+ ret i1 %cmp
+}
+define i1 @src_ugt_i128(i128 %x) {
+; CHECK-LABEL: @src_ugt_i128(
+; CHECK-NEXT: [[NOT:%.*]] = xor i128 [[X:%.*]], -1
+; CHECK-NEXT: [[CMP:%.*]] = icmp ult i128 [[NOT]], [[X]]
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %not = xor i128 %x, -1
+ %cmp = icmp ugt i128 %x, %not
+ ret i1 %cmp
+}
+; X u<= X^Neg_C --> X s> -1
+define i1 @src_ule(i8 %x) {
+; CHECK-LABEL: @src_ule(
+; CHECK-NEXT: [[NOT:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i8 [[NOT]], [[X]]
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %not = xor i8 %x, -1
+ %cmp = icmp ule i8 %x, %not
+ ret i1 %cmp
+}
+define i1 @src_ule_i128(i128 %x) {
+; CHECK-LABEL: @src_ule_i128(
+; CHECK-NEXT: [[NOT:%.*]] = xor i128 [[X:%.*]], -1
+; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i128 [[NOT]], [[X]]
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %not = xor i128 %x, -1
+ %cmp = icmp ule i128 %x, %not
+ ret i1 %cmp
+}
+; X u>= X^Neg_C --> X s< 0
+define i1 @src_uge(i8 %x) {
+; CHECK-LABEL: @src_uge(
+; CHECK-NEXT: [[NOT:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT: [[CMP:%.*]] = icmp ult i8 [[NOT]], [[X]]
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %not = xor i8 %x, -1
+ %cmp = icmp uge i8 %x, %not
+ ret i1 %cmp
+}
+define i1 @src_uge_i128(i128 %x) {
+; CHECK-LABEL: @src_uge_i128(
+; CHECK-NEXT: [[NOT:%.*]] = xor i128 [[X:%.*]], -1
+; CHECK-NEXT: [[CMP:%.*]] = icmp ult i128 [[NOT]], [[X]]
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %not = xor i128 %x, -1
+ %cmp = icmp uge i128 %x, %not
+ ret i1 %cmp
+}
+; X comp X^Neg_C tests, unsigned. commutative
+; X^Neg_C u< X --> X s< 0
+define i1 @src_ult_comm(i8 %x) {
+; CHECK-LABEL: @src_ult_comm(
+; CHECK-NEXT: [[NOT:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT: [[CMP:%.*]] = icmp ult i8 [[NOT]], [[X]]
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %not = xor i8 %x, -1
+ %cmp = icmp ult i8 %not, %x
+ ret i1 %cmp
+}
+define i1 @src_ult_i128_comm(i128 %x) {
+; CHECK-LABEL: @src_ult_i128_comm(
+; CHECK-NEXT: [[NOT:%.*]] = xor i128 [[X:%.*]], -1
+; CHECK-NEXT: [[CMP:%.*]] = icmp ult i128 [[NOT]], [[X]]
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %not = xor i128 %x, -1
+ %cmp = icmp ult i128 %not, %x
+ ret i1 %cmp
+}
+; X^Neg_C u> X --> X s> -1
+define i1 @src_ugt_comm(i8 %x) {
+; CHECK-LABEL: @src_ugt_comm(
+; CHECK-NEXT: [[NOT:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i8 [[NOT]], [[X]]
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %not = xor i8 %x, -1
+ %cmp = icmp ugt i8 %not, %x
+ ret i1 %cmp
+}
+define i1 @src_ugt_i128_comm(i128 %x) {
+; CHECK-LABEL: @src_ugt_i128_comm(
+; CHECK-NEXT: [[NOT:%.*]] = xor i128 [[X:%.*]], -1
+; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i128 [[NOT]], [[X]]
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %not = xor i128 %x, -1
+ %cmp = icmp ugt i128 %not, %x
+ ret i1 %cmp
+}
+; X^Neg_C u<= X --> X s< 0
+define i1 @src_ule_comm(i8 %x) {
+; CHECK-LABEL: @src_ule_comm(
+; CHECK-NEXT: [[NOT:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT: [[CMP:%.*]] = icmp ult i8 [[NOT]], [[X]]
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %not = xor i8 %x, -1
+ %cmp = icmp ule i8 %not, %x
+ ret i1 %cmp
+}
+define i1 @src_ule_i128_comm(i128 %x) {
+; CHECK-LABEL: @src_ule_i128_comm(
+; CHECK-NEXT: [[NOT:%.*]] = xor i128 [[X:%.*]], -1
+; CHECK-NEXT: [[CMP:%.*]] = icmp ult i128 [[NOT]], [[X]]
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %not = xor i128 %x, -1
+ %cmp = icmp ule i128 %not, %x
+ ret i1 %cmp
+}
+; X^Neg_C u>= X --> X s> -1
+define i1 @src_uge_comm(i8 %x) {
+; CHECK-LABEL: @src_uge_comm(
+; CHECK-NEXT: [[NOT:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i8 [[NOT]], [[X]]
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %not = xor i8 %x, -1
+ %cmp = icmp uge i8 %not, %x
+ ret i1 %cmp
+}
+define i1 @src_uge_i128_comm(i128 %x) {
+; CHECK-LABEL: @src_uge_i128_comm(
+; CHECK-NEXT: [[NOT:%.*]] = xor i128 [[X:%.*]], -1
+; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i128 [[NOT]], [[X]]
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %not = xor i128 %x, -1
+ %cmp = icmp uge i128 %not, %x
+ ret i1 %cmp
+}
+
+; X comp X^Neg_C tests. negative
+; X comp Y
+define i1 @src_sle_xny(i8 %x, i8 %y) {
+; CHECK-LABEL: @src_sle_xny(
+; CHECK-NEXT: [[Y_NOT:%.*]] = xor i8 [[Y:%.*]], -1
+; CHECK-NEXT: [[CMP:%.*]] = icmp sge i8 [[Y_NOT]], [[X:%.*]]
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %y.not = xor i8 %y, -1
+ %cmp = icmp sle i8 %x, %y.not
+ ret i1 %cmp
+}
+define i1 @src_sle_nyx(i8 %x, i8 %y) {
+; CHECK-LABEL: @src_sle_nyx(
+; CHECK-NEXT: [[Y_NOT:%.*]] = xor i8 [[Y:%.*]], -1
+; CHECK-NEXT: [[CMP:%.*]] = icmp sle i8 [[Y_NOT]], [[X:%.*]]
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %y.not = xor i8 %y, -1
+ %cmp = icmp sle i8 %y.not, %x
+ ret i1 %cmp
+}
+define i1 @src_sge_xny(i8 %x, i8 %y) {
+; CHECK-LABEL: @src_sge_xny(
+; CHECK-NEXT: [[Y_NOT:%.*]] = xor i8 [[Y:%.*]], -1
+; CHECK-NEXT: [[CMP:%.*]] = icmp sle i8 [[Y_NOT]], [[X:%.*]]
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %y.not = xor i8 %y, -1
+ %cmp = icmp sge i8 %x, %y.not
+ ret i1 %cmp
+}
+define i1 @src_sge_nyx(i8 %x, i8 %y) {
+; CHECK-LABEL: @src_sge_nyx(
+; CHECK-NEXT: [[Y_NOT:%.*]] = xor i8 [[Y:%.*]], -1
+; CHECK-NEXT: [[CMP:%.*]] = icmp sge i8 [[Y_NOT]], [[X:%.*]]
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %y.not = xor i8 %y, -1
+ %cmp = icmp sge i8 %y.not, %x
+ ret i1 %cmp
+}
+define i1 @src_ule_xny(i8 %x, i8 %y) {
+; CHECK-LABEL: @src_ule_xny(
+; CHECK-NEXT: [[Y_NOT:%.*]] = xor i8 [[Y:%.*]], -1
+; CHECK-NEXT: [[CMP:%.*]] = icmp uge i8 [[Y_NOT]], [[X:%.*]]
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %y.not = xor i8 %y, -1
+ %cmp = icmp ule i8 %x, %y.not
+ ret i1 %cmp
+}
+define i1 @src_ule_nyx(i8 %x, i8 %y) {
+; CHECK-LABEL: @src_ule_nyx(
+; CHECK-NEXT: [[Y_NOT:%.*]] = xor i8 [[Y:%.*]], -1
+; CHECK-NEXT: [[CMP:%.*]] = icmp ule i8 [[Y_NOT]], [[X:%.*]]
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %y.not = xor i8 %y, -1
+ %cmp = icmp ule i8 %y.not, %x
+ ret i1 %cmp
+}
+define i1 @src_uge_xny(i8 %x, i8 %y) {
+; CHECK-LABEL: @src_uge_xny(
+; CHECK-NEXT: [[Y_NOT:%.*]] = xor i8 [[Y:%.*]], -1
+; CHECK-NEXT: [[CMP:%.*]] = icmp ule i8 [[Y_NOT]], [[X:%.*]]
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %y.not = xor i8 %y, -1
+ %cmp = icmp uge i8 %x, %y.not
+ ret i1 %cmp
+}
+define i1 @src_uge_nyx(i8 %x, i8 %y) {
+; CHECK-LABEL: @src_uge_nyx(
+; CHECK-NEXT: [[Y_NOT:%.*]] = xor i8 [[Y:%.*]], -1
+; CHECK-NEXT: [[CMP:%.*]] = icmp uge i8 [[Y_NOT]], [[X:%.*]]
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %y.not = xor i8 %y, -1
+ %cmp = icmp uge i8 %y.not, %x
+ ret i1 %cmp
+}
+
+; X comp X^Neg_C tests. negative
+; (X+1) comp X^Neg_C
+define i1 @src_sle_incx_nx(i8 %x) {
+; CHECK-LABEL: @src_sle_incx_nx(
+; CHECK-NEXT: [[TMP1:%.*]] = sub i8 -2, [[X:%.*]]
+; CHECK-NEXT: [[CMP:%.*]] = icmp sge i8 [[TMP1]], [[X]]
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %nx = xor i8 %x, -1
+ %inc.x = add i8 %x, 1
+ %cmp = icmp sle i8 %inc.x, %nx
+ ret i1 %cmp
+}
+; (X-1) comp X^Neg_C
+define i1 @src_sle_decx_nx(i8 %x) {
+; CHECK-LABEL: @src_sle_decx_nx(
+; CHECK-NEXT: [[TMP1:%.*]] = sub i8 0, [[X:%.*]]
+; CHECK-NEXT: [[CMP:%.*]] = icmp sge i8 [[TMP1]], [[X]]
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %nx = xor i8 %x, -1
+ %dec.x = add i8 %x, -1
+ %cmp = icmp sle i8 %dec.x, %nx
+ ret i1 %cmp
+}
+; X comp (X+1)^Neg_C
+define i1 @src_sle_x_nincx(i8 %x) {
+; CHECK-LABEL: @src_sle_x_nincx(
+; CHECK-NEXT: [[NOT_INC_X:%.*]] = sub i8 -2, [[X:%.*]]
+; CHECK-NEXT: [[CMP:%.*]] = icmp sge i8 [[NOT_INC_X]], [[X]]
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %inc.x = add i8 %x, 1
+ %not.inc.x = xor i8 %inc.x, -1
+ %cmp = icmp sle i8 %x, %not.inc.x
+ ret i1 %cmp
+}
+; X comp (X-1)^Neg_C
+define i1 @src_sle_x_ndecx(i8 %x) {
+; CHECK-LABEL: @src_sle_x_ndecx(
+; CHECK-NEXT: [[NOT_DEC_X:%.*]] = sub i8 0, [[X:%.*]]
+; CHECK-NEXT: [[CMP:%.*]] = icmp sge i8 [[NOT_DEC_X]], [[X]]
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %dec.x = add i8 %x, -1
+ %not.dec.x = xor i8 %dec.x, -1
+ %cmp = icmp sle i8 %x, %not.dec.x
+ ret i1 %cmp
+}
+
+; X comp X^Neg_C vector tests
+; X s< X^Neg_C --> X s< 0
+define <2 x i1> @src_slt_xnx_to_slt_0_i8_vec(<2 x i8> %x) {
+; CHECK-LABEL: @src_slt_xnx_to_slt_0_i8_vec(
+; CHECK-NEXT: [[NOT:%.*]] = xor <2 x i8> [[X:%.*]], <i8 -1, i8 -1>
+; CHECK-NEXT: [[CMP:%.*]] = icmp sgt <2 x i8> [[NOT]], [[X]]
+; CHECK-NEXT: ret <2 x i1> [[CMP]]
+;
+ %not = xor <2 x i8> %x, <i8 -1, i8 -1>
+ %cmp = icmp slt <2 x i8> %x, %not
+ ret <2 x i1> %cmp
+}
+; X s> X^Neg_C --> X s> -1
+define <2 x i1> @src_sgt_xnx_to_sgt_n1_i8_vec(<2 x i8> %x) {
+; CHECK-LABEL: @src_sgt_xnx_to_sgt_n1_i8_vec(
+; CHECK-NEXT: [[NOT:%.*]] = xor <2 x i8> [[X:%.*]], <i8 -1, i8 -1>
+; CHECK-NEXT: [[CMP:%.*]] = icmp slt <2 x i8> [[NOT]], [[X]]
+; CHECK-NEXT: ret <2 x i1> [[CMP]]
+;
+ %not = xor <2 x i8> %x, <i8 -1, i8 -1>
+ %cmp = icmp sgt <2 x i8> %x, %not
+ ret <2 x i1> %cmp
+}
+; X s<= X^Neg_C --> X s< X^Neg_C --> X s< 0
+define <2 x i1> @src_sle_xnx_to_slt_0_i8_vec(<2 x i8> %x) {
+; CHECK-LABEL: @src_sle_xnx_to_slt_0_i8_vec(
+; CHECK-NEXT: [[NOT:%.*]] = xor <2 x i8> [[X:%.*]], <i8 -1, i8 -1>
+; CHECK-NEXT: [[CMP:%.*]] = icmp sgt <2 x i8> [[NOT]], [[X]]
+; CHECK-NEXT: ret <2 x i1> [[CMP]]
+;
+ %not = xor <2 x i8> %x, <i8 -1, i8 -1>
+ %cmp = icmp sle <2 x i8> %x, %not
+ ret <2 x i1> %cmp
+}
+; X s>= X^Neg_C --> X s> X^Neg_C --> X s> -1
+define <2 x i1> @src_sge_xnx_to_sgt_n1_i8_vec(<2 x i8> %x) {
+; CHECK-LABEL: @src_sge_xnx_to_sgt_n1_i8_vec(
+; CHECK-NEXT: [[NOT:%.*]] = xor <2 x i8> [[X:%.*]], <i8 -1, i8 -1>
+; CHECK-NEXT: [[CMP:%.*]] = icmp slt <2 x i8> [[NOT]], [[X]]
+; CHECK-NEXT: ret <2 x i1> [[CMP]]
+;
+ %not = xor <2 x i8> %x, <i8 -1, i8 -1>
+ %cmp = icmp sge <2 x i8> %x, %not
+ ret <2 x i1> %cmp
+}
+
; test for (~x ^ y) < ~z
define i1 @test_xor1(i8 %x, i8 %y, i8 %z) {
; CHECK-LABEL: @test_xor1(
>From b8478396d59fd4560e5b9941f460de947b049ced Mon Sep 17 00:00:00 2001
From: Hanbum Park <kese111 at gmail.com>
Date: Fri, 1 Dec 2023 06:32:35 +0900
Subject: [PATCH 2/2] [InstCombine] simplify `X (comp) X^Neg_C` (#57532)
This patch simplifies the comparison between X and X^Neg_X.
comparison between X and X^Neg_C is determined solely by
presence of the sign bit, so we can simplify it to checking
whether X is negative or not.
Proof: https://alive2.llvm.org/ce/z/P6zXUx
---
.../InstCombine/InstCombineCompares.cpp | 23 ++++
.../Transforms/InstCombine/icmp-of-xor-x.ll | 108 ++++++------------
2 files changed, 59 insertions(+), 72 deletions(-)
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
index 280c4d77b6dfca..8118b191478b52 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
@@ -7190,6 +7190,29 @@ Instruction *InstCombinerImpl::visitICmpInst(ICmpInst &I) {
}
}
+ // These transform works when C is negative.
+ // X s< X^C, X s<= X^C, X u> X^C, X u>= X^C --> X s< 0
+ // X s> X^C, X s>= X^C, X u< X^C, X u<= X^C --> X s>= 0
+ const APInt *C;
+ if (match(Op0, m_c_Xor(m_Specific(Op1), m_APInt(C))) && C->isNegative()) {
+ CmpInst::Predicate NewPred;
+ Pred = ICmpInst::getStrictPredicate(Pred);
+ switch (Pred) {
+ default:
+ llvm_unreachable("not a valid predicate");
+ case ICmpInst::ICMP_SLT:
+ case ICmpInst::ICMP_UGT:
+ NewPred = ICmpInst::ICMP_SLT;
+ break;
+ case ICmpInst::ICMP_SGT:
+ case ICmpInst::ICMP_ULT:
+ NewPred = ICmpInst::ICMP_SGE;
+ break;
+ }
+ Constant *Const = Constant::getNullValue(Op0->getType());
+ return new ICmpInst(NewPred, Op0, Const);
+ }
+
Instruction *AddI = nullptr;
if (match(&I, m_UAddWithOverflow(m_Value(X), m_Value(Y),
m_Instruction(AddI))) &&
diff --git a/llvm/test/Transforms/InstCombine/icmp-of-xor-x.ll b/llvm/test/Transforms/InstCombine/icmp-of-xor-x.ll
index b8cd60c9535b7f..aa2cae30ca295b 100644
--- a/llvm/test/Transforms/InstCombine/icmp-of-xor-x.ll
+++ b/llvm/test/Transforms/InstCombine/icmp-of-xor-x.ll
@@ -9,8 +9,7 @@ declare void @use.i8(i8)
; X s< X^Neg_C --> X s< 0
define i1 @src_slt(i8 %x) {
; CHECK-LABEL: @src_slt(
-; CHECK-NEXT: [[NOT:%.*]] = xor i8 [[X:%.*]], -1
-; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i8 [[NOT]], [[X]]
+; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[X:%.*]], 0
; CHECK-NEXT: ret i1 [[CMP]]
;
%not = xor i8 %x, -1
@@ -19,8 +18,7 @@ define i1 @src_slt(i8 %x) {
}
define i1 @src_slt_i128(i128 %x) {
; CHECK-LABEL: @src_slt_i128(
-; CHECK-NEXT: [[NOT:%.*]] = xor i128 [[X:%.*]], -1
-; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i128 [[NOT]], [[X]]
+; CHECK-NEXT: [[CMP:%.*]] = icmp slt i128 [[X:%.*]], 0
; CHECK-NEXT: ret i1 [[CMP]]
;
%not = xor i128 %x, -1
@@ -30,8 +28,7 @@ define i1 @src_slt_i128(i128 %x) {
; X s> X^Neg_C --> X s> -1
define i1 @src_sgt(i8 %x) {
; CHECK-LABEL: @src_sgt(
-; CHECK-NEXT: [[NOT:%.*]] = xor i8 [[X:%.*]], -1
-; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[NOT]], [[X]]
+; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i8 [[X:%.*]], -1
; CHECK-NEXT: ret i1 [[CMP]]
;
%not = xor i8 %x, -1
@@ -40,8 +37,7 @@ define i1 @src_sgt(i8 %x) {
}
define i1 @src_sgt_i128(i128 %x) {
; CHECK-LABEL: @src_sgt_i128(
-; CHECK-NEXT: [[NOT:%.*]] = xor i128 [[X:%.*]], -1
-; CHECK-NEXT: [[CMP:%.*]] = icmp slt i128 [[NOT]], [[X]]
+; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i128 [[X:%.*]], -1
; CHECK-NEXT: ret i1 [[CMP]]
;
%not = xor i128 %x, -1
@@ -51,8 +47,7 @@ define i1 @src_sgt_i128(i128 %x) {
; X s<= X^Neg_C --> X s< 0
define i1 @src_sle(i8 %x) {
; CHECK-LABEL: @src_sle(
-; CHECK-NEXT: [[NOT:%.*]] = xor i8 [[X:%.*]], -1
-; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i8 [[NOT]], [[X]]
+; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[X:%.*]], 0
; CHECK-NEXT: ret i1 [[CMP]]
;
%not = xor i8 %x, -1
@@ -61,8 +56,7 @@ define i1 @src_sle(i8 %x) {
}
define i1 @src_sle_i128(i128 %x) {
; CHECK-LABEL: @src_sle_i128(
-; CHECK-NEXT: [[NOT:%.*]] = xor i128 [[X:%.*]], -1
-; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i128 [[NOT]], [[X]]
+; CHECK-NEXT: [[CMP:%.*]] = icmp slt i128 [[X:%.*]], 0
; CHECK-NEXT: ret i1 [[CMP]]
;
%not = xor i128 %x, -1
@@ -72,8 +66,7 @@ define i1 @src_sle_i128(i128 %x) {
; X s>= X^Neg_C --> X s> -1
define i1 @src_sge(i8 %x) {
; CHECK-LABEL: @src_sge(
-; CHECK-NEXT: [[NOT:%.*]] = xor i8 [[X:%.*]], -1
-; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[NOT]], [[X]]
+; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i8 [[X:%.*]], -1
; CHECK-NEXT: ret i1 [[CMP]]
;
%not = xor i8 %x, -1
@@ -82,8 +75,7 @@ define i1 @src_sge(i8 %x) {
}
define i1 @src_sge_i128(i128 %x) {
; CHECK-LABEL: @src_sge_i128(
-; CHECK-NEXT: [[NOT:%.*]] = xor i128 [[X:%.*]], -1
-; CHECK-NEXT: [[CMP:%.*]] = icmp slt i128 [[NOT]], [[X]]
+; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i128 [[X:%.*]], -1
; CHECK-NEXT: ret i1 [[CMP]]
;
%not = xor i128 %x, -1
@@ -94,8 +86,7 @@ define i1 @src_sge_i128(i128 %x) {
; X^Neg_C s< X --> X s> -1
define i1 @src_slt_comm(i8 %x) {
; CHECK-LABEL: @src_slt_comm(
-; CHECK-NEXT: [[NOT:%.*]] = xor i8 [[X:%.*]], -1
-; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[NOT]], [[X]]
+; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i8 [[X:%.*]], -1
; CHECK-NEXT: ret i1 [[CMP]]
;
%not = xor i8 %x, -1
@@ -104,8 +95,7 @@ define i1 @src_slt_comm(i8 %x) {
}
define i1 @src_slt_i128_comm(i128 %x) {
; CHECK-LABEL: @src_slt_i128_comm(
-; CHECK-NEXT: [[NOT:%.*]] = xor i128 [[X:%.*]], -1
-; CHECK-NEXT: [[CMP:%.*]] = icmp slt i128 [[NOT]], [[X]]
+; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i128 [[X:%.*]], -1
; CHECK-NEXT: ret i1 [[CMP]]
;
%not = xor i128 %x, -1
@@ -115,8 +105,7 @@ define i1 @src_slt_i128_comm(i128 %x) {
; X^Neg_C s> X --> X s< 0
define i1 @src_sgt_comm(i8 %x) {
; CHECK-LABEL: @src_sgt_comm(
-; CHECK-NEXT: [[NOT:%.*]] = xor i8 [[X:%.*]], -1
-; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i8 [[NOT]], [[X]]
+; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[X:%.*]], 0
; CHECK-NEXT: ret i1 [[CMP]]
;
%not = xor i8 %x, -1
@@ -125,8 +114,7 @@ define i1 @src_sgt_comm(i8 %x) {
}
define i1 @src_sgt_i128_comm(i128 %x) {
; CHECK-LABEL: @src_sgt_i128_comm(
-; CHECK-NEXT: [[NOT:%.*]] = xor i128 [[X:%.*]], -1
-; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i128 [[NOT]], [[X]]
+; CHECK-NEXT: [[CMP:%.*]] = icmp slt i128 [[X:%.*]], 0
; CHECK-NEXT: ret i1 [[CMP]]
;
%not = xor i128 %x, -1
@@ -136,8 +124,7 @@ define i1 @src_sgt_i128_comm(i128 %x) {
; X^Neg_C s<= X --> X s> -1
define i1 @src_sle_comm(i8 %x) {
; CHECK-LABEL: @src_sle_comm(
-; CHECK-NEXT: [[NOT:%.*]] = xor i8 [[X:%.*]], -1
-; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[NOT]], [[X]]
+; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i8 [[X:%.*]], -1
; CHECK-NEXT: ret i1 [[CMP]]
;
%not = xor i8 %x, -1
@@ -146,8 +133,7 @@ define i1 @src_sle_comm(i8 %x) {
}
define i1 @src_sle_i128_comm(i128 %x) {
; CHECK-LABEL: @src_sle_i128_comm(
-; CHECK-NEXT: [[NOT:%.*]] = xor i128 [[X:%.*]], -1
-; CHECK-NEXT: [[CMP:%.*]] = icmp slt i128 [[NOT]], [[X]]
+; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i128 [[X:%.*]], -1
; CHECK-NEXT: ret i1 [[CMP]]
;
%not = xor i128 %x, -1
@@ -157,8 +143,7 @@ define i1 @src_sle_i128_comm(i128 %x) {
; X^Neg_C s>= X --> X s< 0
define i1 @src_sge_comm(i8 %x) {
; CHECK-LABEL: @src_sge_comm(
-; CHECK-NEXT: [[NOT:%.*]] = xor i8 [[X:%.*]], -1
-; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i8 [[NOT]], [[X]]
+; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[X:%.*]], 0
; CHECK-NEXT: ret i1 [[CMP]]
;
%not = xor i8 %x, -1
@@ -167,8 +152,7 @@ define i1 @src_sge_comm(i8 %x) {
}
define i1 @src_sge_i128_comm(i128 %x) {
; CHECK-LABEL: @src_sge_i128_comm(
-; CHECK-NEXT: [[NOT:%.*]] = xor i128 [[X:%.*]], -1
-; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i128 [[NOT]], [[X]]
+; CHECK-NEXT: [[CMP:%.*]] = icmp slt i128 [[X:%.*]], 0
; CHECK-NEXT: ret i1 [[CMP]]
;
%not = xor i128 %x, -1
@@ -180,8 +164,7 @@ define i1 @src_sge_i128_comm(i128 %x) {
; X u< X^Neg_C --> X s> -1
define i1 @src_ult(i8 %x) {
; CHECK-LABEL: @src_ult(
-; CHECK-NEXT: [[NOT:%.*]] = xor i8 [[X:%.*]], -1
-; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i8 [[NOT]], [[X]]
+; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i8 [[X:%.*]], -1
; CHECK-NEXT: ret i1 [[CMP]]
;
%not = xor i8 %x, -1
@@ -190,8 +173,7 @@ define i1 @src_ult(i8 %x) {
}
define i1 @src_ult_i128(i128 %x) {
; CHECK-LABEL: @src_ult_i128(
-; CHECK-NEXT: [[NOT:%.*]] = xor i128 [[X:%.*]], -1
-; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i128 [[NOT]], [[X]]
+; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i128 [[X:%.*]], -1
; CHECK-NEXT: ret i1 [[CMP]]
;
%not = xor i128 %x, -1
@@ -201,8 +183,7 @@ define i1 @src_ult_i128(i128 %x) {
; X u> X^Neg_C --> X s< 0
define i1 @src_ugt(i8 %x) {
; CHECK-LABEL: @src_ugt(
-; CHECK-NEXT: [[NOT:%.*]] = xor i8 [[X:%.*]], -1
-; CHECK-NEXT: [[CMP:%.*]] = icmp ult i8 [[NOT]], [[X]]
+; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[X:%.*]], 0
; CHECK-NEXT: ret i1 [[CMP]]
;
%not = xor i8 %x, -1
@@ -211,8 +192,7 @@ define i1 @src_ugt(i8 %x) {
}
define i1 @src_ugt_i128(i128 %x) {
; CHECK-LABEL: @src_ugt_i128(
-; CHECK-NEXT: [[NOT:%.*]] = xor i128 [[X:%.*]], -1
-; CHECK-NEXT: [[CMP:%.*]] = icmp ult i128 [[NOT]], [[X]]
+; CHECK-NEXT: [[CMP:%.*]] = icmp slt i128 [[X:%.*]], 0
; CHECK-NEXT: ret i1 [[CMP]]
;
%not = xor i128 %x, -1
@@ -222,8 +202,7 @@ define i1 @src_ugt_i128(i128 %x) {
; X u<= X^Neg_C --> X s> -1
define i1 @src_ule(i8 %x) {
; CHECK-LABEL: @src_ule(
-; CHECK-NEXT: [[NOT:%.*]] = xor i8 [[X:%.*]], -1
-; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i8 [[NOT]], [[X]]
+; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i8 [[X:%.*]], -1
; CHECK-NEXT: ret i1 [[CMP]]
;
%not = xor i8 %x, -1
@@ -232,8 +211,7 @@ define i1 @src_ule(i8 %x) {
}
define i1 @src_ule_i128(i128 %x) {
; CHECK-LABEL: @src_ule_i128(
-; CHECK-NEXT: [[NOT:%.*]] = xor i128 [[X:%.*]], -1
-; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i128 [[NOT]], [[X]]
+; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i128 [[X:%.*]], -1
; CHECK-NEXT: ret i1 [[CMP]]
;
%not = xor i128 %x, -1
@@ -243,8 +221,7 @@ define i1 @src_ule_i128(i128 %x) {
; X u>= X^Neg_C --> X s< 0
define i1 @src_uge(i8 %x) {
; CHECK-LABEL: @src_uge(
-; CHECK-NEXT: [[NOT:%.*]] = xor i8 [[X:%.*]], -1
-; CHECK-NEXT: [[CMP:%.*]] = icmp ult i8 [[NOT]], [[X]]
+; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[X:%.*]], 0
; CHECK-NEXT: ret i1 [[CMP]]
;
%not = xor i8 %x, -1
@@ -253,8 +230,7 @@ define i1 @src_uge(i8 %x) {
}
define i1 @src_uge_i128(i128 %x) {
; CHECK-LABEL: @src_uge_i128(
-; CHECK-NEXT: [[NOT:%.*]] = xor i128 [[X:%.*]], -1
-; CHECK-NEXT: [[CMP:%.*]] = icmp ult i128 [[NOT]], [[X]]
+; CHECK-NEXT: [[CMP:%.*]] = icmp slt i128 [[X:%.*]], 0
; CHECK-NEXT: ret i1 [[CMP]]
;
%not = xor i128 %x, -1
@@ -265,8 +241,7 @@ define i1 @src_uge_i128(i128 %x) {
; X^Neg_C u< X --> X s< 0
define i1 @src_ult_comm(i8 %x) {
; CHECK-LABEL: @src_ult_comm(
-; CHECK-NEXT: [[NOT:%.*]] = xor i8 [[X:%.*]], -1
-; CHECK-NEXT: [[CMP:%.*]] = icmp ult i8 [[NOT]], [[X]]
+; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[X:%.*]], 0
; CHECK-NEXT: ret i1 [[CMP]]
;
%not = xor i8 %x, -1
@@ -275,8 +250,7 @@ define i1 @src_ult_comm(i8 %x) {
}
define i1 @src_ult_i128_comm(i128 %x) {
; CHECK-LABEL: @src_ult_i128_comm(
-; CHECK-NEXT: [[NOT:%.*]] = xor i128 [[X:%.*]], -1
-; CHECK-NEXT: [[CMP:%.*]] = icmp ult i128 [[NOT]], [[X]]
+; CHECK-NEXT: [[CMP:%.*]] = icmp slt i128 [[X:%.*]], 0
; CHECK-NEXT: ret i1 [[CMP]]
;
%not = xor i128 %x, -1
@@ -286,8 +260,7 @@ define i1 @src_ult_i128_comm(i128 %x) {
; X^Neg_C u> X --> X s> -1
define i1 @src_ugt_comm(i8 %x) {
; CHECK-LABEL: @src_ugt_comm(
-; CHECK-NEXT: [[NOT:%.*]] = xor i8 [[X:%.*]], -1
-; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i8 [[NOT]], [[X]]
+; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i8 [[X:%.*]], -1
; CHECK-NEXT: ret i1 [[CMP]]
;
%not = xor i8 %x, -1
@@ -296,8 +269,7 @@ define i1 @src_ugt_comm(i8 %x) {
}
define i1 @src_ugt_i128_comm(i128 %x) {
; CHECK-LABEL: @src_ugt_i128_comm(
-; CHECK-NEXT: [[NOT:%.*]] = xor i128 [[X:%.*]], -1
-; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i128 [[NOT]], [[X]]
+; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i128 [[X:%.*]], -1
; CHECK-NEXT: ret i1 [[CMP]]
;
%not = xor i128 %x, -1
@@ -307,8 +279,7 @@ define i1 @src_ugt_i128_comm(i128 %x) {
; X^Neg_C u<= X --> X s< 0
define i1 @src_ule_comm(i8 %x) {
; CHECK-LABEL: @src_ule_comm(
-; CHECK-NEXT: [[NOT:%.*]] = xor i8 [[X:%.*]], -1
-; CHECK-NEXT: [[CMP:%.*]] = icmp ult i8 [[NOT]], [[X]]
+; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[X:%.*]], 0
; CHECK-NEXT: ret i1 [[CMP]]
;
%not = xor i8 %x, -1
@@ -317,8 +288,7 @@ define i1 @src_ule_comm(i8 %x) {
}
define i1 @src_ule_i128_comm(i128 %x) {
; CHECK-LABEL: @src_ule_i128_comm(
-; CHECK-NEXT: [[NOT:%.*]] = xor i128 [[X:%.*]], -1
-; CHECK-NEXT: [[CMP:%.*]] = icmp ult i128 [[NOT]], [[X]]
+; CHECK-NEXT: [[CMP:%.*]] = icmp slt i128 [[X:%.*]], 0
; CHECK-NEXT: ret i1 [[CMP]]
;
%not = xor i128 %x, -1
@@ -328,8 +298,7 @@ define i1 @src_ule_i128_comm(i128 %x) {
; X^Neg_C u>= X --> X s> -1
define i1 @src_uge_comm(i8 %x) {
; CHECK-LABEL: @src_uge_comm(
-; CHECK-NEXT: [[NOT:%.*]] = xor i8 [[X:%.*]], -1
-; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i8 [[NOT]], [[X]]
+; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i8 [[X:%.*]], -1
; CHECK-NEXT: ret i1 [[CMP]]
;
%not = xor i8 %x, -1
@@ -338,8 +307,7 @@ define i1 @src_uge_comm(i8 %x) {
}
define i1 @src_uge_i128_comm(i128 %x) {
; CHECK-LABEL: @src_uge_i128_comm(
-; CHECK-NEXT: [[NOT:%.*]] = xor i128 [[X:%.*]], -1
-; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i128 [[NOT]], [[X]]
+; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i128 [[X:%.*]], -1
; CHECK-NEXT: ret i1 [[CMP]]
;
%not = xor i128 %x, -1
@@ -484,8 +452,7 @@ define i1 @src_sle_x_ndecx(i8 %x) {
; X s< X^Neg_C --> X s< 0
define <2 x i1> @src_slt_xnx_to_slt_0_i8_vec(<2 x i8> %x) {
; CHECK-LABEL: @src_slt_xnx_to_slt_0_i8_vec(
-; CHECK-NEXT: [[NOT:%.*]] = xor <2 x i8> [[X:%.*]], <i8 -1, i8 -1>
-; CHECK-NEXT: [[CMP:%.*]] = icmp sgt <2 x i8> [[NOT]], [[X]]
+; CHECK-NEXT: [[CMP:%.*]] = icmp slt <2 x i8> [[X:%.*]], zeroinitializer
; CHECK-NEXT: ret <2 x i1> [[CMP]]
;
%not = xor <2 x i8> %x, <i8 -1, i8 -1>
@@ -495,8 +462,7 @@ define <2 x i1> @src_slt_xnx_to_slt_0_i8_vec(<2 x i8> %x) {
; X s> X^Neg_C --> X s> -1
define <2 x i1> @src_sgt_xnx_to_sgt_n1_i8_vec(<2 x i8> %x) {
; CHECK-LABEL: @src_sgt_xnx_to_sgt_n1_i8_vec(
-; CHECK-NEXT: [[NOT:%.*]] = xor <2 x i8> [[X:%.*]], <i8 -1, i8 -1>
-; CHECK-NEXT: [[CMP:%.*]] = icmp slt <2 x i8> [[NOT]], [[X]]
+; CHECK-NEXT: [[CMP:%.*]] = icmp sgt <2 x i8> [[X:%.*]], <i8 -1, i8 -1>
; CHECK-NEXT: ret <2 x i1> [[CMP]]
;
%not = xor <2 x i8> %x, <i8 -1, i8 -1>
@@ -506,8 +472,7 @@ define <2 x i1> @src_sgt_xnx_to_sgt_n1_i8_vec(<2 x i8> %x) {
; X s<= X^Neg_C --> X s< X^Neg_C --> X s< 0
define <2 x i1> @src_sle_xnx_to_slt_0_i8_vec(<2 x i8> %x) {
; CHECK-LABEL: @src_sle_xnx_to_slt_0_i8_vec(
-; CHECK-NEXT: [[NOT:%.*]] = xor <2 x i8> [[X:%.*]], <i8 -1, i8 -1>
-; CHECK-NEXT: [[CMP:%.*]] = icmp sgt <2 x i8> [[NOT]], [[X]]
+; CHECK-NEXT: [[CMP:%.*]] = icmp slt <2 x i8> [[X:%.*]], zeroinitializer
; CHECK-NEXT: ret <2 x i1> [[CMP]]
;
%not = xor <2 x i8> %x, <i8 -1, i8 -1>
@@ -517,8 +482,7 @@ define <2 x i1> @src_sle_xnx_to_slt_0_i8_vec(<2 x i8> %x) {
; X s>= X^Neg_C --> X s> X^Neg_C --> X s> -1
define <2 x i1> @src_sge_xnx_to_sgt_n1_i8_vec(<2 x i8> %x) {
; CHECK-LABEL: @src_sge_xnx_to_sgt_n1_i8_vec(
-; CHECK-NEXT: [[NOT:%.*]] = xor <2 x i8> [[X:%.*]], <i8 -1, i8 -1>
-; CHECK-NEXT: [[CMP:%.*]] = icmp slt <2 x i8> [[NOT]], [[X]]
+; CHECK-NEXT: [[CMP:%.*]] = icmp sgt <2 x i8> [[X:%.*]], <i8 -1, i8 -1>
; CHECK-NEXT: ret <2 x i1> [[CMP]]
;
%not = xor <2 x i8> %x, <i8 -1, i8 -1>
More information about the llvm-commits
mailing list