[llvm] Simplify `(a % b) lt/ge (b-1)` into `(a % b) eq/ne (b-1)` (PR #72504)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 29 06:47:10 PST 2023
https://github.com/elhewaty updated https://github.com/llvm/llvm-project/pull/72504
>From 22c513b7e8d2a57ed23a69c64d3e5d674ab04b09 Mon Sep 17 00:00:00 2001
From: Mohamed Atef <mohamedatef1698 at gmail.com>
Date: Fri, 17 Nov 2023 16:20:59 +0200
Subject: [PATCH 1/2] [InstCombine] Add test coverage for (a % b) lt/le/ge/gt
(b(-/+)1)
---
llvm/test/Transforms/InstCombine/icmp.ll | 309 +++++++++++++++++++++++
1 file changed, 309 insertions(+)
diff --git a/llvm/test/Transforms/InstCombine/icmp.ll b/llvm/test/Transforms/InstCombine/icmp.ll
index 78ac730cf026ed..a164ab455dc77d 100644
--- a/llvm/test/Transforms/InstCombine/icmp.ll
+++ b/llvm/test/Transforms/InstCombine/icmp.ll
@@ -10,6 +10,315 @@ declare void @use_i8(i8)
declare void @use_i32(i32)
declare void @use_i64(i64)
+; tests for (x % c) >=/ < (c - 1), where c >= 0
+define i1 @srem_sge_test1(i64 %x) {
+; CHECK-LABEL: @srem_sge_test1(
+; CHECK-NEXT: [[Y:%.*]] = srem i64 [[X:%.*]], 34360750831
+; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i64 [[Y]], 34360750829
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %Cminus1 = add i64 34360750831, -1
+ %y = srem i64 %x, 34360750831
+ %cmp = icmp sge i64 %y, %Cminus1
+ ret i1 %cmp
+}
+
+define i1 @srem_slt_test1(i64 %x) {
+; CHECK-LABEL: @srem_slt_test1(
+; CHECK-NEXT: [[Y:%.*]] = srem i64 [[X:%.*]], 34360750831
+; CHECK-NEXT: [[CMP:%.*]] = icmp slt i64 [[Y]], 34360750830
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %Cminus1 = add i64 34360750831, -1
+ %y = srem i64 %x, 34360750831
+ %cmp = icmp slt i64 %y, %Cminus1
+ ret i1 %cmp
+}
+
+define i1 @srem_sge_test2(i32 %x) {
+; CHECK-LABEL: @srem_sge_test2(
+; CHECK-NEXT: [[Y:%.*]] = srem i32 [[X:%.*]], 1074977277
+; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[Y]], 1074977275
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %Cminus1 = add i32 1074977277, -1
+ %y = srem i32 %x, 1074977277
+ %cmp = icmp sge i32 %y, %Cminus1
+ ret i1 %cmp
+}
+
+define i1 @srem_slt_test2(i32 %x) {
+; CHECK-LABEL: @srem_slt_test2(
+; CHECK-NEXT: [[Y:%.*]] = srem i32 [[X:%.*]], 1074977277
+; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[Y]], 1074977276
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %Cminus1 = add i32 1074977277, -1
+ %y = srem i32 %x, 1074977277
+ %cmp = icmp slt i32 %y, %Cminus1
+ ret i1 %cmp
+}
+
+define i1 @srem_sge_test3(i16 %x) {
+; CHECK-LABEL: @srem_sge_test3(
+; CHECK-NEXT: [[Y:%.*]] = srem i16 [[X:%.*]], 2259
+; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i16 [[Y]], 2257
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %Cminus1 = add i16 2259, -1
+ %y = srem i16 %x, 2259
+ %cmp = icmp sge i16 %y, %Cminus1
+ ret i1 %cmp
+}
+
+define i1 @srem_slt_test3(i16 %x) {
+; CHECK-LABEL: @srem_slt_test3(
+; CHECK-NEXT: [[Y:%.*]] = srem i16 [[X:%.*]], 2259
+; CHECK-NEXT: [[CMP:%.*]] = icmp slt i16 [[Y]], 2258
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %Cminus1 = add i16 2259, -1
+ %y = srem i16 %x, 2259
+ %cmp = icmp slt i16 %y, %Cminus1
+ ret i1 %cmp
+}
+
+define i1 @srem_sge_test4(i8 %x) {
+; CHECK-LABEL: @srem_sge_test4(
+; CHECK-NEXT: [[Y:%.*]] = srem i8 [[X:%.*]], 63
+; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i8 [[Y]], 61
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %Cminus1 = add i8 575, -1
+ %y = srem i8 %x, 575
+ %cmp = icmp sge i8 %y, %Cminus1
+ ret i1 %cmp
+}
+
+define i1 @srem_slt_test4(i8 %x) {
+; CHECK-LABEL: @srem_slt_test4(
+; CHECK-NEXT: [[Y:%.*]] = srem i8 [[X:%.*]], 63
+; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[Y]], 62
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+
+ %Cminus1 = add i8 575, -1
+ %y = srem i8 %x, 575
+ %cmp = icmp slt i8 %y, %Cminus1
+ ret i1 %cmp
+}
+
+define i1 @test_srem_slt_constant(i32 %a) {
+; CHECK-LABEL: @test_srem_slt_constant(
+; CHECK-NEXT: [[Y:%.*]] = srem i32 [[A:%.*]], 512
+; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[Y]], 511
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %y = srem i32 %a, 512
+ %cmp = icmp slt i32 %y, 511
+ ret i1 %cmp
+}
+
+define i1 @test_srem_sge_constant(i32 %a) {
+; CHECK-LABEL: @test_srem_sge_constant(
+; CHECK-NEXT: [[Y:%.*]] = srem i32 [[A:%.*]], 512
+; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[Y]], 510
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %y = srem i32 %a, 512
+ %cmp = icmp sge i32 %y, 511
+ ret i1 %cmp
+}
+
+define <2 x i1> @test_srem_slt_constant_splat(<2 x i32> %a) {
+; CHECK-LABEL: @test_srem_slt_constant_splat(
+; CHECK-NEXT: [[Y:%.*]] = srem <2 x i32> [[A:%.*]], <i32 512, i32 512>
+; CHECK-NEXT: [[CMP:%.*]] = icmp slt <2 x i32> [[Y]], <i32 511, i32 511>
+; CHECK-NEXT: ret <2 x i1> [[CMP]]
+;
+ %y = srem <2 x i32> %a, <i32 512, i32 512>
+ %cmp = icmp slt <2 x i32> %y, <i32 511, i32 511>
+ ret <2 x i1> %cmp
+}
+
+define <2 x i1> @test_srem_sge_constant_splat(<2 x i32> %a) {
+; CHECK-LABEL: @test_srem_sge_constant_splat(
+; CHECK-NEXT: [[Y:%.*]] = srem <2 x i32> [[A:%.*]], <i32 512, i32 512>
+; CHECK-NEXT: [[CMP:%.*]] = icmp sgt <2 x i32> [[Y]], <i32 510, i32 510>
+; CHECK-NEXT: ret <2 x i1> [[CMP]]
+;
+ %y = srem <2 x i32> %a, <i32 512, i32 512>
+ %cmp = icmp sge <2 x i32> %y, <i32 511, i32 511>
+ ret <2 x i1> %cmp
+}
+
+; tests for (x % c) <=/> (c + 1), where y < 0
+define i1 @srem_sgt_test(i16 %x) {
+; CHECK-LABEL: @srem_sgt_test(
+; CHECK-NEXT: [[Y:%.*]] = srem i16 [[X:%.*]], 2259
+; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i16 [[Y]], -2258
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %Cplus1 = add i16 -2259, 1
+ %y = srem i16 %x, -2259
+ %cmp = icmp sgt i16 %y, %Cplus1
+ ret i1 %cmp
+}
+
+define i1 @srem_sle_test(i16 %x) {
+; CHECK-LABEL: @srem_sle_test(
+; CHECK-NEXT: [[Y:%.*]] = srem i16 [[X:%.*]], 2259
+; CHECK-NEXT: [[CMP:%.*]] = icmp slt i16 [[Y]], -2257
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %Cplus1 = add i16 -2259, 1
+ %y = srem i16 %x, -2259
+ %cmp = icmp sle i16 %y, %Cplus1
+ ret i1 %cmp
+}
+
+define <2 x i1> @test_srem_sgt_constant_splat(<2 x i32> %a) {
+; CHECK-LABEL: @test_srem_sgt_constant_splat(
+; CHECK-NEXT: [[Y:%.*]] = srem <2 x i32> [[A:%.*]], <i32 512, i32 512>
+; CHECK-NEXT: [[CMP:%.*]] = icmp sgt <2 x i32> [[Y]], <i32 -511, i32 -511>
+; CHECK-NEXT: ret <2 x i1> [[CMP]]
+;
+ %y = srem <2 x i32> %a, <i32 -512, i32 -512>
+ %cmp = icmp sgt <2 x i32> %y, <i32 -511, i32 -511>
+ ret <2 x i1> %cmp
+}
+
+define <2 x i1> @test_srem_sle_constant_splat(<2 x i32> %a) {
+; CHECK-LABEL: @test_srem_sle_constant_splat(
+; CHECK-NEXT: [[Y:%.*]] = srem <2 x i32> [[A:%.*]], <i32 512, i32 512>
+; CHECK-NEXT: [[CMP:%.*]] = icmp slt <2 x i32> [[Y]], <i32 -510, i32 -510>
+; CHECK-NEXT: ret <2 x i1> [[CMP]]
+;
+ %y = srem <2 x i32> %a, <i32 -512, i32 -512>
+ %cmp = icmp sle <2 x i32> %y, <i32 -511, i32 -511>
+ ret <2 x i1> %cmp
+}
+
+; tests for handling urem w/ slt/sge/uge/ult
+define i1 @test_urem_slt(i32 %x) {
+; CHECK-LABEL: @test_urem_slt(
+; CHECK-NEXT: [[Y:%.*]] = urem i32 [[X:%.*]], 12235
+; CHECK-NEXT: [[CMP:%.*]] = icmp ult i32 [[Y]], 12234
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %Cminus1 = add i32 12235, -1
+ %y = urem i32 %x, 12235
+ %cmp = icmp slt i32 %y, %Cminus1
+ ret i1 %cmp
+}
+
+define i1 @test_urem_sge(i32 %x) {
+; CHECK-LABEL: @test_urem_sge(
+; CHECK-NEXT: [[Y:%.*]] = urem i32 [[X:%.*]], 13546
+; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i32 [[Y]], 13544
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %Cminus1 = add i32 13546, -1
+ %y = urem i32 %x, 13546
+ %cmp = icmp sge i32 %y, %Cminus1
+ ret i1 %cmp
+}
+
+define i1 @test_urem_uge(i32 %x) {
+; CHECK-LABEL: @test_urem_uge(
+; CHECK-NEXT: [[Y:%.*]] = urem i32 [[X:%.*]], 18642
+; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i32 [[Y]], 18640
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %Cminus1 = add i32 18642, -1
+ %y = urem i32 %x, 18642
+ %cmp = icmp uge i32 %y, %Cminus1
+ ret i1 %cmp
+}
+
+define i1 @test_urem_ult(i32 %x) {
+; CHECK-LABEL: @test_urem_ult(
+; CHECK-NEXT: [[Y:%.*]] = urem i32 [[X:%.*]], 15344
+; CHECK-NEXT: [[CMP:%.*]] = icmp ult i32 [[Y]], 15343
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %Cminus1 = add i32 15344, -1
+ %y = urem i32 %x, 15344
+ %cmp = icmp ult i32 %y, %Cminus1
+ ret i1 %cmp
+}
+
+define <2 x i1> @test_urem_slt_constant_splat(<2 x i32> %a) {
+; CHECK-LABEL: @test_urem_slt_constant_splat(
+; CHECK-NEXT: [[Y:%.*]] = srem <2 x i32> [[A:%.*]], <i32 512, i32 512>
+; CHECK-NEXT: [[CMP:%.*]] = icmp slt <2 x i32> [[Y]], <i32 511, i32 511>
+; CHECK-NEXT: ret <2 x i1> [[CMP]]
+;
+ %y = srem <2 x i32> %a, <i32 512, i32 512>
+ %cmp = icmp slt <2 x i32> %y, <i32 511, i32 511>
+ ret <2 x i1> %cmp
+}
+
+define <2 x i1> @test_urem_sge_constant_splat(<2 x i32> %a) {
+; CHECK-LABEL: @test_urem_sge_constant_splat(
+; CHECK-NEXT: [[Y:%.*]] = srem <2 x i32> [[A:%.*]], <i32 512, i32 512>
+; CHECK-NEXT: [[CMP:%.*]] = icmp sgt <2 x i32> [[Y]], <i32 510, i32 510>
+; CHECK-NEXT: ret <2 x i1> [[CMP]]
+;
+ %y = srem <2 x i32> %a, <i32 512, i32 512>
+ %cmp = icmp sge <2 x i32> %y, <i32 511, i32 511>
+ ret <2 x i1> %cmp
+}
+
+define <2 x i1> @test_urem_uge_constant_splat(<2 x i32> %a) {
+; CHECK-LABEL: @test_urem_uge_constant_splat(
+; CHECK-NEXT: [[Y:%.*]] = srem <2 x i32> [[A:%.*]], <i32 512, i32 512>
+; CHECK-NEXT: [[CMP:%.*]] = icmp ugt <2 x i32> [[Y]], <i32 510, i32 510>
+; CHECK-NEXT: ret <2 x i1> [[CMP]]
+;
+ %y = srem <2 x i32> %a, <i32 512, i32 512>
+ %cmp = icmp uge <2 x i32> %y, <i32 511, i32 511>
+ ret <2 x i1> %cmp
+}
+
+define <2 x i1> @test_urem_ult_constant_splat(<2 x i32> %a) {
+; CHECK-LABEL: @test_urem_ult_constant_splat(
+; CHECK-NEXT: [[Y:%.*]] = srem <2 x i32> [[A:%.*]], <i32 512, i32 512>
+; CHECK-NEXT: [[CMP:%.*]] = icmp ult <2 x i32> [[Y]], <i32 511, i32 511>
+; CHECK-NEXT: ret <2 x i1> [[CMP]]
+;
+ %y = srem <2 x i32> %a, <i32 512, i32 512>
+ %cmp = icmp ult <2 x i32> %y, <i32 511, i32 511>
+ ret <2 x i1> %cmp
+}
+
+; negative tests
+define i1 @srem_slt_neg_test(i8 %x, i8 %C) {
+; CHECK-LABEL: @srem_slt_neg_test(
+; CHECK-NEXT: [[CMINUS1:%.*]] = add i8 [[C:%.*]], -1
+; CHECK-NEXT: [[Y:%.*]] = srem i8 [[X:%.*]], [[C]]
+; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[Y]], [[CMINUS1]]
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %Cminus1 = add i8 %C, -1
+ %y = srem i8 %x, %C
+ %cmp = icmp slt i8 %y, %Cminus1
+ ret i1 %cmp
+}
+
+define i1 @srem_sge_neg_test(i8 %x, i8 %C) {
+; CHECK-LABEL: @srem_sge_neg_test(
+; CHECK-NEXT: [[CMINUS1:%.*]] = add i8 [[C:%.*]], -1
+; CHECK-NEXT: [[Y:%.*]] = srem i8 [[X:%.*]], [[C]]
+; CHECK-NEXT: [[CMP:%.*]] = icmp sge i8 [[Y]], [[CMINUS1]]
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %Cminus1 = add i8 %C, -1
+ %y = srem i8 %x, %C
+ %cmp = icmp sge i8 %y, %Cminus1
+ ret i1 %cmp
+}
+
define i32 @test1(i32 %X) {
; CHECK-LABEL: @test1(
; CHECK-NEXT: [[X_LOBIT:%.*]] = lshr i32 [[X:%.*]], 31
>From be5ae4b0787645cd2a5ffd0c949fff91355cb945 Mon Sep 17 00:00:00 2001
From: Mohamed Atef <mohamedatef1698 at gmail.com>
Date: Fri, 29 Dec 2023 15:25:56 +0200
Subject: [PATCH 2/2] [InstCombine] Fold (a (s/u)% b) (s/u)(le/ge/lt/gt) (b
(-/+) 1)
---
.../InstCombine/InstCombineCompares.cpp | 41 ++++++++++++++++
llvm/test/Transforms/InstCombine/icmp.ll | 48 +++++++++----------
2 files changed, 65 insertions(+), 24 deletions(-)
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
index 69b96445c76e9f..87d065d058ea8b 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
@@ -6855,6 +6855,47 @@ Instruction *InstCombinerImpl::visitICmpInst(ICmpInst &I) {
if (Value *V = simplifyICmpInst(I.getPredicate(), Op0, Op1, Q))
return replaceInstUsesWith(I, V);
+ {
+ Value *X;
+ const APInt *C1, *C2;
+ ICmpInst::Predicate Pred;
+ if ((match(&I, m_ICmp(Pred, m_SRem(m_Value(X), m_NonNegative(C1)),
+ m_APInt(C2))) &&
+ *C2 == *C1 - 1 &&
+ (Pred == ICmpInst::ICMP_SLT || Pred == ICmpInst::ICMP_SGE)) ||
+ (match(&I,
+ m_ICmp(Pred, m_SRem(m_Value(X), m_Negative(C1)), m_APInt(C2))) &&
+ *C2 == *C1 + 1 &&
+ (Pred == ICmpInst::ICMP_SGT || Pred == ICmpInst::ICMP_SLE))) {
+ // icmp slt (X s% C), (C - 1) --> icmp ne (X s% C), (C - 1), if C >= 0
+ // icmp sge (X s% C), (C - 1) --> icmp eq (X s% C), (C - 1), if C >= 0
+ // icmp sgt (X s% C), (C + 1) --> icmp ne (X s% C), (C + 1), if C < 0
+ // icmp sle (X s% C), (C + 1) --> icmp eq (X s% C), (C + 1), if C < 0
+ auto *NewCmp = Builder.CreateICmp(
+ (Pred == ICmpInst::ICMP_SLT || Pred == ICmpInst::ICMP_SGT)
+ ? ICmpInst::ICMP_NE
+ : ICmpInst::ICMP_EQ,
+ Op0, Op1);
+ return replaceInstUsesWith(I, NewCmp);
+ }
+
+ if (match(&I, m_ICmp(Pred, m_URem(m_Value(X), m_NonNegative(C1)),
+ m_APInt(C2))) &&
+ (Pred == ICmpInst::ICMP_SLT || Pred == ICmpInst::ICMP_SGE ||
+ Pred == ICmpInst::ICMP_UGE || Pred == ICmpInst::ICMP_ULT)) {
+ // icmp slt (X u% C), (C - 1) --> icmp ne (X u% C), (C - 1), if C >= 0
+ // icmp ult (X u% C), (C - 1) --> icmp eq (X u% C), (C - 1), if C >= 0
+ // icmp sge (X u% C), (C - 1) --> icmp eq (X u% C), (C - 1), if C >= 0
+ // icmp uge (X u% C), (C - 1) --> icmp ne (X u% C), (C - 1), if C >= 0
+ auto *NewCmp = Builder.CreateICmp(
+ (Pred == ICmpInst::ICMP_SLT || Pred == ICmpInst::ICMP_ULT)
+ ? ICmpInst::ICMP_NE
+ : ICmpInst::ICMP_EQ,
+ Op0, Op1);
+ return replaceInstUsesWith(I, NewCmp);
+ }
+ }
+
// Comparing -val or val with non-zero is the same as just comparing val
// ie, abs(val) != 0 -> val != 0
if (I.getPredicate() == ICmpInst::ICMP_NE && match(Op1, m_Zero())) {
diff --git a/llvm/test/Transforms/InstCombine/icmp.ll b/llvm/test/Transforms/InstCombine/icmp.ll
index a164ab455dc77d..873705d39b6704 100644
--- a/llvm/test/Transforms/InstCombine/icmp.ll
+++ b/llvm/test/Transforms/InstCombine/icmp.ll
@@ -14,7 +14,7 @@ declare void @use_i64(i64)
define i1 @srem_sge_test1(i64 %x) {
; CHECK-LABEL: @srem_sge_test1(
; CHECK-NEXT: [[Y:%.*]] = srem i64 [[X:%.*]], 34360750831
-; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i64 [[Y]], 34360750829
+; CHECK-NEXT: [[CMP:%.*]] = icmp eq i64 [[Y]], 34360750830
; CHECK-NEXT: ret i1 [[CMP]]
;
%Cminus1 = add i64 34360750831, -1
@@ -26,7 +26,7 @@ define i1 @srem_sge_test1(i64 %x) {
define i1 @srem_slt_test1(i64 %x) {
; CHECK-LABEL: @srem_slt_test1(
; CHECK-NEXT: [[Y:%.*]] = srem i64 [[X:%.*]], 34360750831
-; CHECK-NEXT: [[CMP:%.*]] = icmp slt i64 [[Y]], 34360750830
+; CHECK-NEXT: [[CMP:%.*]] = icmp ne i64 [[Y]], 34360750830
; CHECK-NEXT: ret i1 [[CMP]]
;
%Cminus1 = add i64 34360750831, -1
@@ -38,7 +38,7 @@ define i1 @srem_slt_test1(i64 %x) {
define i1 @srem_sge_test2(i32 %x) {
; CHECK-LABEL: @srem_sge_test2(
; CHECK-NEXT: [[Y:%.*]] = srem i32 [[X:%.*]], 1074977277
-; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[Y]], 1074977275
+; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[Y]], 1074977276
; CHECK-NEXT: ret i1 [[CMP]]
;
%Cminus1 = add i32 1074977277, -1
@@ -50,7 +50,7 @@ define i1 @srem_sge_test2(i32 %x) {
define i1 @srem_slt_test2(i32 %x) {
; CHECK-LABEL: @srem_slt_test2(
; CHECK-NEXT: [[Y:%.*]] = srem i32 [[X:%.*]], 1074977277
-; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[Y]], 1074977276
+; CHECK-NEXT: [[CMP:%.*]] = icmp ne i32 [[Y]], 1074977276
; CHECK-NEXT: ret i1 [[CMP]]
;
%Cminus1 = add i32 1074977277, -1
@@ -62,7 +62,7 @@ define i1 @srem_slt_test2(i32 %x) {
define i1 @srem_sge_test3(i16 %x) {
; CHECK-LABEL: @srem_sge_test3(
; CHECK-NEXT: [[Y:%.*]] = srem i16 [[X:%.*]], 2259
-; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i16 [[Y]], 2257
+; CHECK-NEXT: [[CMP:%.*]] = icmp eq i16 [[Y]], 2258
; CHECK-NEXT: ret i1 [[CMP]]
;
%Cminus1 = add i16 2259, -1
@@ -74,7 +74,7 @@ define i1 @srem_sge_test3(i16 %x) {
define i1 @srem_slt_test3(i16 %x) {
; CHECK-LABEL: @srem_slt_test3(
; CHECK-NEXT: [[Y:%.*]] = srem i16 [[X:%.*]], 2259
-; CHECK-NEXT: [[CMP:%.*]] = icmp slt i16 [[Y]], 2258
+; CHECK-NEXT: [[CMP:%.*]] = icmp ne i16 [[Y]], 2258
; CHECK-NEXT: ret i1 [[CMP]]
;
%Cminus1 = add i16 2259, -1
@@ -86,7 +86,7 @@ define i1 @srem_slt_test3(i16 %x) {
define i1 @srem_sge_test4(i8 %x) {
; CHECK-LABEL: @srem_sge_test4(
; CHECK-NEXT: [[Y:%.*]] = srem i8 [[X:%.*]], 63
-; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i8 [[Y]], 61
+; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[Y]], 62
; CHECK-NEXT: ret i1 [[CMP]]
;
%Cminus1 = add i8 575, -1
@@ -98,7 +98,7 @@ define i1 @srem_sge_test4(i8 %x) {
define i1 @srem_slt_test4(i8 %x) {
; CHECK-LABEL: @srem_slt_test4(
; CHECK-NEXT: [[Y:%.*]] = srem i8 [[X:%.*]], 63
-; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[Y]], 62
+; CHECK-NEXT: [[CMP:%.*]] = icmp ne i8 [[Y]], 62
; CHECK-NEXT: ret i1 [[CMP]]
;
@@ -110,8 +110,8 @@ define i1 @srem_slt_test4(i8 %x) {
define i1 @test_srem_slt_constant(i32 %a) {
; CHECK-LABEL: @test_srem_slt_constant(
-; CHECK-NEXT: [[Y:%.*]] = srem i32 [[A:%.*]], 512
-; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[Y]], 511
+; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[A:%.*]], -2147483137
+; CHECK-NEXT: [[CMP:%.*]] = icmp ne i32 [[TMP1]], 511
; CHECK-NEXT: ret i1 [[CMP]]
;
%y = srem i32 %a, 512
@@ -121,8 +121,8 @@ define i1 @test_srem_slt_constant(i32 %a) {
define i1 @test_srem_sge_constant(i32 %a) {
; CHECK-LABEL: @test_srem_sge_constant(
-; CHECK-NEXT: [[Y:%.*]] = srem i32 [[A:%.*]], 512
-; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[Y]], 510
+; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[A:%.*]], -2147483137
+; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[TMP1]], 511
; CHECK-NEXT: ret i1 [[CMP]]
;
%y = srem i32 %a, 512
@@ -132,8 +132,8 @@ define i1 @test_srem_sge_constant(i32 %a) {
define <2 x i1> @test_srem_slt_constant_splat(<2 x i32> %a) {
; CHECK-LABEL: @test_srem_slt_constant_splat(
-; CHECK-NEXT: [[Y:%.*]] = srem <2 x i32> [[A:%.*]], <i32 512, i32 512>
-; CHECK-NEXT: [[CMP:%.*]] = icmp slt <2 x i32> [[Y]], <i32 511, i32 511>
+; CHECK-NEXT: [[TMP1:%.*]] = and <2 x i32> [[A:%.*]], <i32 -2147483137, i32 -2147483137>
+; CHECK-NEXT: [[CMP:%.*]] = icmp ne <2 x i32> [[TMP1]], <i32 511, i32 511>
; CHECK-NEXT: ret <2 x i1> [[CMP]]
;
%y = srem <2 x i32> %a, <i32 512, i32 512>
@@ -143,8 +143,8 @@ define <2 x i1> @test_srem_slt_constant_splat(<2 x i32> %a) {
define <2 x i1> @test_srem_sge_constant_splat(<2 x i32> %a) {
; CHECK-LABEL: @test_srem_sge_constant_splat(
-; CHECK-NEXT: [[Y:%.*]] = srem <2 x i32> [[A:%.*]], <i32 512, i32 512>
-; CHECK-NEXT: [[CMP:%.*]] = icmp sgt <2 x i32> [[Y]], <i32 510, i32 510>
+; CHECK-NEXT: [[TMP1:%.*]] = and <2 x i32> [[A:%.*]], <i32 -2147483137, i32 -2147483137>
+; CHECK-NEXT: [[CMP:%.*]] = icmp eq <2 x i32> [[TMP1]], <i32 511, i32 511>
; CHECK-NEXT: ret <2 x i1> [[CMP]]
;
%y = srem <2 x i32> %a, <i32 512, i32 512>
@@ -203,7 +203,7 @@ define <2 x i1> @test_srem_sle_constant_splat(<2 x i32> %a) {
define i1 @test_urem_slt(i32 %x) {
; CHECK-LABEL: @test_urem_slt(
; CHECK-NEXT: [[Y:%.*]] = urem i32 [[X:%.*]], 12235
-; CHECK-NEXT: [[CMP:%.*]] = icmp ult i32 [[Y]], 12234
+; CHECK-NEXT: [[CMP:%.*]] = icmp ne i32 [[Y]], 12234
; CHECK-NEXT: ret i1 [[CMP]]
;
%Cminus1 = add i32 12235, -1
@@ -215,7 +215,7 @@ define i1 @test_urem_slt(i32 %x) {
define i1 @test_urem_sge(i32 %x) {
; CHECK-LABEL: @test_urem_sge(
; CHECK-NEXT: [[Y:%.*]] = urem i32 [[X:%.*]], 13546
-; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i32 [[Y]], 13544
+; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[Y]], 13545
; CHECK-NEXT: ret i1 [[CMP]]
;
%Cminus1 = add i32 13546, -1
@@ -227,7 +227,7 @@ define i1 @test_urem_sge(i32 %x) {
define i1 @test_urem_uge(i32 %x) {
; CHECK-LABEL: @test_urem_uge(
; CHECK-NEXT: [[Y:%.*]] = urem i32 [[X:%.*]], 18642
-; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i32 [[Y]], 18640
+; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[Y]], 18641
; CHECK-NEXT: ret i1 [[CMP]]
;
%Cminus1 = add i32 18642, -1
@@ -239,7 +239,7 @@ define i1 @test_urem_uge(i32 %x) {
define i1 @test_urem_ult(i32 %x) {
; CHECK-LABEL: @test_urem_ult(
; CHECK-NEXT: [[Y:%.*]] = urem i32 [[X:%.*]], 15344
-; CHECK-NEXT: [[CMP:%.*]] = icmp ult i32 [[Y]], 15343
+; CHECK-NEXT: [[CMP:%.*]] = icmp ne i32 [[Y]], 15343
; CHECK-NEXT: ret i1 [[CMP]]
;
%Cminus1 = add i32 15344, -1
@@ -250,8 +250,8 @@ define i1 @test_urem_ult(i32 %x) {
define <2 x i1> @test_urem_slt_constant_splat(<2 x i32> %a) {
; CHECK-LABEL: @test_urem_slt_constant_splat(
-; CHECK-NEXT: [[Y:%.*]] = srem <2 x i32> [[A:%.*]], <i32 512, i32 512>
-; CHECK-NEXT: [[CMP:%.*]] = icmp slt <2 x i32> [[Y]], <i32 511, i32 511>
+; CHECK-NEXT: [[TMP1:%.*]] = and <2 x i32> [[A:%.*]], <i32 -2147483137, i32 -2147483137>
+; CHECK-NEXT: [[CMP:%.*]] = icmp ne <2 x i32> [[TMP1]], <i32 511, i32 511>
; CHECK-NEXT: ret <2 x i1> [[CMP]]
;
%y = srem <2 x i32> %a, <i32 512, i32 512>
@@ -261,8 +261,8 @@ define <2 x i1> @test_urem_slt_constant_splat(<2 x i32> %a) {
define <2 x i1> @test_urem_sge_constant_splat(<2 x i32> %a) {
; CHECK-LABEL: @test_urem_sge_constant_splat(
-; CHECK-NEXT: [[Y:%.*]] = srem <2 x i32> [[A:%.*]], <i32 512, i32 512>
-; CHECK-NEXT: [[CMP:%.*]] = icmp sgt <2 x i32> [[Y]], <i32 510, i32 510>
+; CHECK-NEXT: [[TMP1:%.*]] = and <2 x i32> [[A:%.*]], <i32 -2147483137, i32 -2147483137>
+; CHECK-NEXT: [[CMP:%.*]] = icmp eq <2 x i32> [[TMP1]], <i32 511, i32 511>
; CHECK-NEXT: ret <2 x i1> [[CMP]]
;
%y = srem <2 x i32> %a, <i32 512, i32 512>
More information about the llvm-commits
mailing list