[llvm] 01f4d40 - Simplify `(a % b) lt/ge (b-1)` into `(a % b) eq/ne (b-1)` (#72504)

via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 16 01:15:20 PST 2024


Author: elhewaty
Date: 2024-01-16T10:15:15+01:00
New Revision: 01f4d40aad58c5c34a8ae30edbf4e0ebbf235838

URL: https://github.com/llvm/llvm-project/commit/01f4d40aad58c5c34a8ae30edbf4e0ebbf235838
DIFF: https://github.com/llvm/llvm-project/commit/01f4d40aad58c5c34a8ae30edbf4e0ebbf235838.diff

LOG: Simplify `(a % b) lt/ge (b-1)` into `(a % b) eq/ne (b-1)` (#72504)

Alive2: https://alive2.llvm.org/ce/z/i7zYtE
Fixes: https://github.com/llvm/llvm-project/issues/71280

Added: 
    

Modified: 
    llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
    llvm/lib/Transforms/InstCombine/InstCombineInternal.h
    llvm/test/Transforms/InstCombine/icmp.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
index 8c0fd662255130..dec7490976cc01 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
@@ -2528,6 +2528,30 @@ Instruction *InstCombinerImpl::foldICmpShrConstant(ICmpInst &Cmp,
 Instruction *InstCombinerImpl::foldICmpSRemConstant(ICmpInst &Cmp,
                                                     BinaryOperator *SRem,
                                                     const APInt &C) {
+  {
+    const APInt *C1;
+    ICmpInst::Predicate Pred = Cmp.getPredicate();
+    if ((match(SRem->getOperand(1), m_NonNegative(C1))) &&
+        ((Pred == ICmpInst::ICMP_SLT && C == *C1 - 1) ||
+         (Pred == ICmpInst::ICMP_SGT && C == *C1 - 2) ||
+         (Pred == ICmpInst::ICMP_SGT && C == -*C1 + 1) ||
+         (Pred == ICmpInst::ICMP_SLT && C == -*C1 + 2))) {
+      // icmp slt (X s% C), (C - 1) --> icmp ne (X s% C), (C - 1), if C >= 0
+      // icmp sgt (X s% C), (C - 2) --> 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 slt (X s% C), (-C + 2) --> icmp eq (X s% C), (-C + 1), if C >= 0
+      return new ICmpInst(
+          ((Pred == ICmpInst::ICMP_SLT && C == *C1 - 1) ||
+           (Pred == ICmpInst::ICMP_SGT && C == -*C1 + 1))
+              ? ICmpInst::ICMP_NE
+              : ICmpInst::ICMP_EQ,
+          SRem,
+          ConstantInt::get(SRem->getType(), C == -*C1 + 1 || C == -*C1 + 2
+                                                ? -*C1 + 1
+                                                : *C1 - 1));
+    }
+  }
+
   // Match an 'is positive' or 'is negative' comparison of remainder by a
   // constant power-of-2 value:
   // (X % pow2C) sgt/slt 0
@@ -2575,6 +2599,23 @@ Instruction *InstCombinerImpl::foldICmpSRemConstant(ICmpInst &Cmp,
   return new ICmpInst(ICmpInst::ICMP_UGT, And, ConstantInt::get(Ty, SignMask));
 }
 
+Instruction *InstCombinerImpl::foldICmpURemConstant(ICmpInst &Cmp,
+                                                    BinaryOperator *URem,
+                                                    const APInt &C) {
+  const APInt *C1;
+  ICmpInst::Predicate Pred = Cmp.getPredicate();
+  if (match(URem->getOperand(1), m_APInt(C1)) &&
+      ((Pred == ICmpInst::ICMP_ULT && C == *C1 - 1) ||
+       (Pred == ICmpInst::ICMP_UGT && C == *C1 - 2 && C.ugt(1)))) {
+    // icmp ult (X u% C), (C - 1) --> icmp ne (X u% C), (C - 1)
+    // icmp ugt (X u% C), (C - 2) --> icmp eq (X u% C), (C - 1), if C >u 1
+    return new ICmpInst(Pred == ICmpInst::ICMP_UGT ? ICmpInst::ICMP_EQ
+                                                   : ICmpInst::ICMP_NE,
+                        URem, ConstantInt::get(URem->getType(), *C1 - 1));
+  }
+  return nullptr;
+}
+
 /// Fold icmp (udiv X, Y), C.
 Instruction *InstCombinerImpl::foldICmpUDivConstant(ICmpInst &Cmp,
                                                     BinaryOperator *UDiv,
@@ -3712,6 +3753,10 @@ Instruction *InstCombinerImpl::foldICmpBinOpWithConstant(ICmpInst &Cmp,
     if (Instruction *I = foldICmpSRemConstant(Cmp, BO, C))
       return I;
     break;
+  case Instruction::URem:
+    if (Instruction *I = foldICmpURemConstant(Cmp, BO, C))
+      return I;
+    break;
   case Instruction::UDiv:
     if (Instruction *I = foldICmpUDivConstant(Cmp, BO, C))
       return I;

diff  --git a/llvm/lib/Transforms/InstCombine/InstCombineInternal.h b/llvm/lib/Transforms/InstCombine/InstCombineInternal.h
index c24b6e3a5b33c0..0d5ffbd7b50efa 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineInternal.h
+++ b/llvm/lib/Transforms/InstCombine/InstCombineInternal.h
@@ -676,6 +676,8 @@ class LLVM_LIBRARY_VISIBILITY InstCombinerImpl final
                                    const APInt &C);
   Instruction *foldICmpSRemConstant(ICmpInst &Cmp, BinaryOperator *UDiv,
                                     const APInt &C);
+  Instruction *foldICmpURemConstant(ICmpInst &Cmp, BinaryOperator *UDiv,
+                                    const APInt &C);
   Instruction *foldICmpUDivConstant(ICmpInst &Cmp, BinaryOperator *UDiv,
                                     const APInt &C);
   Instruction *foldICmpDivConstant(ICmpInst &Cmp, BinaryOperator *Div,

diff  --git a/llvm/test/Transforms/InstCombine/icmp.ll b/llvm/test/Transforms/InstCombine/icmp.ll
index 10ab1fe118348c..d56da2fae8b6ac 100644
--- a/llvm/test/Transforms/InstCombine/icmp.ll
+++ b/llvm/test/Transforms/InstCombine/icmp.ll
@@ -10,6 +10,311 @@ 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_sgt_test1(i64 %x) {
+; CHECK-LABEL: @srem_sgt_test1(
+; CHECK-NEXT:    [[Y:%.*]] = srem i64 [[X:%.*]], 34360750831
+; CHECK-NEXT:    [[CMP:%.*]] = icmp eq i64 [[Y]], 34360750830
+; CHECK-NEXT:    ret i1 [[CMP]]
+;
+  %y = srem i64 %x, 34360750831
+  %cmp = icmp sgt i64 %y, 34360750829
+  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 ne i64 [[Y]], 34360750830
+; CHECK-NEXT:    ret i1 [[CMP]]
+;
+  %y = srem i64 %x, 34360750831
+  %cmp = icmp slt i64 %y, 34360750830
+  ret i1 %cmp
+}
+
+define i1 @srem_sgt_test2(i32 %x) {
+; CHECK-LABEL: @srem_sgt_test2(
+; CHECK-NEXT:    [[Y:%.*]] = srem i32 [[X:%.*]], 1074977277
+; CHECK-NEXT:    [[CMP:%.*]] = icmp eq i32 [[Y]], 1074977276
+; CHECK-NEXT:    ret i1 [[CMP]]
+;
+  %y = srem i32 %x, 1074977277
+  %cmp = icmp sgt i32 %y, 1074977275
+  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 ne i32 [[Y]], 1074977276
+; CHECK-NEXT:    ret i1 [[CMP]]
+;
+  %y = srem i32 %x, 1074977277
+  %cmp = icmp slt i32 %y, 1074977276
+  ret i1 %cmp
+}
+
+define i1 @srem_sgt_test3(i16 %x) {
+; CHECK-LABEL: @srem_sgt_test3(
+; CHECK-NEXT:    [[Y:%.*]] = srem i16 [[X:%.*]], 2259
+; CHECK-NEXT:    [[CMP:%.*]] = icmp eq i16 [[Y]], 2258
+; CHECK-NEXT:    ret i1 [[CMP]]
+;
+  %y = srem i16 %x, 2259
+  %cmp = icmp sgt i16 %y, 2257
+  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 ne i16 [[Y]], 2258
+; CHECK-NEXT:    ret i1 [[CMP]]
+;
+  %y = srem i16 %x, 2259
+  %cmp = icmp slt i16 %y, 2258
+  ret i1 %cmp
+}
+
+define i1 @srem_sgt_test4(i8 %x) {
+; CHECK-LABEL: @srem_sgt_test4(
+; CHECK-NEXT:    [[Y:%.*]] = srem i8 [[X:%.*]], 50
+; CHECK-NEXT:    [[CMP:%.*]] = icmp eq i8 [[Y]], 49
+; CHECK-NEXT:    ret i1 [[CMP]]
+;
+  %y = srem i8 %x, 50
+  %cmp = icmp sgt i8 %y, 48
+  ret i1 %cmp
+}
+
+define i1 @srem_slt_test4(i8 %x) {
+; CHECK-LABEL: @srem_slt_test4(
+; CHECK-NEXT:    [[Y:%.*]] = srem i8 [[X:%.*]], 50
+; CHECK-NEXT:    [[CMP:%.*]] = icmp ne i8 [[Y]], 49
+; CHECK-NEXT:    ret i1 [[CMP]]
+;
+  %y = srem i8 %x, 50
+  %cmp = icmp slt i8 %y, 49
+  ret i1 %cmp
+}
+
+define i1 @test_srem_slt_constant(i32 %a) {
+; CHECK-LABEL: @test_srem_slt_constant(
+; 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
+  %cmp = icmp slt i32 %y, 511
+  ret i1 %cmp
+}
+
+define i1 @test_srem_sgt_constant(i32 %a) {
+; CHECK-LABEL: @test_srem_sgt_constant(
+; 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
+  %cmp = icmp sgt i32 %y, 510
+  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:    [[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>
+  %cmp = icmp slt <2 x i32> %y, <i32 511, i32 511>
+  ret <2 x i1> %cmp
+}
+
+define <2 x i1> @test_srem_sgt_constant_splat(<2 x i32> %a) {
+; CHECK-LABEL: @test_srem_sgt_constant_splat(
+; 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>
+  %cmp = icmp sgt <2 x i32> %y, <i32 510, i32 510>
+  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 ne i16 [[Y]], -2258
+; CHECK-NEXT:    ret i1 [[CMP]]
+;
+  %y = srem i16 %x, -2259
+  %cmp = icmp sgt i16 %y, -2258
+  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 eq i16 [[Y]], -2258
+; CHECK-NEXT:    ret i1 [[CMP]]
+;
+  %y = srem i16 %x, -2259
+  %cmp = icmp slt i16 %y, -2257
+  ret i1 %cmp
+}
+
+define <2 x i1> @test_srem_sgt_constant_splat_neg(<2 x i32> %a) {
+; CHECK-LABEL: @test_srem_sgt_constant_splat_neg(
+; CHECK-NEXT:    [[Y:%.*]] = srem <2 x i32> [[A:%.*]], <i32 512, i32 512>
+; CHECK-NEXT:    [[CMP:%.*]] = icmp ne <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_slt_constant_splat_neg(<2 x i32> %a) {
+; CHECK-LABEL: @test_srem_slt_constant_splat_neg(
+; CHECK-NEXT:    [[Y:%.*]] = srem <2 x i32> [[A:%.*]], <i32 512, i32 512>
+; CHECK-NEXT:    [[CMP:%.*]] = icmp eq <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 -510, i32 -510>
+  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 ne i32 [[Y]], 12234
+; CHECK-NEXT:    ret i1 [[CMP]]
+;
+  %y = urem i32 %x, 12235
+  %cmp = icmp slt i32 %y, 12234
+  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 eq i32 [[Y]], 13545
+; CHECK-NEXT:    ret i1 [[CMP]]
+;
+  %y = urem i32 %x, 13546
+  %cmp = icmp sge i32 %y, 13545
+  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 eq i32 [[Y]], 18641
+; CHECK-NEXT:    ret i1 [[CMP]]
+;
+  %y = urem i32 %x, 18642
+  %cmp = icmp ugt i32 %y, 18640
+  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 ne i32 [[Y]], 15343
+; CHECK-NEXT:    ret i1 [[CMP]]
+;
+  %y = urem i32 %x, 15344
+  %cmp = icmp ult i32 %y, 15343
+  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:    [[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>
+  %cmp = icmp slt <2 x i32> %y, <i32 511, i32 511>
+  ret <2 x i1> %cmp
+}
+
+define <2 x i1> @test_urem_sgt_constant_splat(<2 x i32> %a) {
+; CHECK-LABEL: @test_urem_sgt_constant_splat(
+; 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>
+  %cmp = icmp sgt <2 x i32> %y, <i32 510, i32 510>
+  ret <2 x i1> %cmp
+}
+
+define <2 x i1> @test_urem_ugt_constant_splat(<2 x i32> %a) {
+; CHECK-LABEL: @test_urem_ugt_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 ugt <2 x i32> %y, <i32 510, i32 510>
+  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
+}
+
+; negative tests for urem
+; if C <= 1 in ugt
+define i1 @test_neg_ult_1(i32 %x) {
+; CHECK-LABEL: @test_neg_ult_1(
+; CHECK-NEXT:    ret i1 true
+;
+  %y = urem i32 %x, 1
+  %cmp = icmp ult i32 %y, -1
+  ret i1 %cmp
+}
+
 define i32 @test1(i32 %X) {
 ; CHECK-LABEL: @test1(
 ; CHECK-NEXT:    [[X_LOBIT:%.*]] = lshr i32 [[X:%.*]], 31
@@ -20,6 +325,50 @@ define i32 @test1(i32 %X) {
   ret i32 %b
 }
 
+; negative tests off by one
+define i1 @test_urem_ult_neg(i32 %x) {
+; CHECK-LABEL: @test_urem_ult_neg(
+; CHECK-NEXT:    [[Y:%.*]] = urem i32 [[X:%.*]], 15344
+; CHECK-NEXT:    [[CMP:%.*]] = icmp ult i32 [[Y]], 15342
+; CHECK-NEXT:    ret i1 [[CMP]]
+;
+  %y = urem i32 %x, 15344
+  %cmp = icmp ult i32 %y, 15342
+  ret i1 %cmp
+}
+
+define i1 @srem_slt_neg(i64 %x) {
+; CHECK-LABEL: @srem_slt_neg(
+; CHECK-NEXT:    [[Y:%.*]] = srem i64 [[X:%.*]], 34360750831
+; CHECK-NEXT:    [[CMP:%.*]] = icmp slt i64 [[Y]], 34360750829
+; CHECK-NEXT:    ret i1 [[CMP]]
+;
+  %y = srem i64 %x, 34360750831
+  %cmp = icmp slt i64 %y, 34360750829
+  ret i1 %cmp
+}
+
+define i1 @srem_sgt_neg(i32 %x) {
+; CHECK-LABEL: @srem_sgt_neg(
+; CHECK-NEXT:    [[Y:%.*]] = srem i32 [[X:%.*]], 1074977277
+; CHECK-NEXT:    [[CMP:%.*]] = icmp sgt i32 [[Y]], 1074977274
+; CHECK-NEXT:    ret i1 [[CMP]]
+;
+  %y = srem i32 %x, 1074977277
+  %cmp = icmp sgt i32 %y, 1074977274
+  ret i1 %cmp
+}
+
+
+define i1 @srem_sle_neg_neg(i16 %x) {
+; CHECK-LABEL: @srem_sle_neg_neg(
+; CHECK-NEXT:    ret i1 false
+;
+  %y = srem i16 %x, -2259
+  %cmp = icmp slt i16 %y, -2258
+  ret i1 %cmp
+}
+
 define <2 x i32> @test1vec(<2 x i32> %X) {
 ; CHECK-LABEL: @test1vec(
 ; CHECK-NEXT:    [[X_LOBIT:%.*]] = lshr <2 x i32> [[X:%.*]], <i32 31, i32 31>


        


More information about the llvm-commits mailing list