[llvm] Simplify `(a % b) lt/ge (b-1)` into `(a % b) eq/ne (b-1)` (PR #72504)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 8 12:40:48 PST 2024
================
@@ -10,6 +10,296 @@ 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 eq i64 [[Y]], 34360750830
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %y = srem i64 %x, 34360750831
+ %cmp = icmp sge i64 %y, 34360750830
+ 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_sge_test2(i32 %x) {
+; CHECK-LABEL: @srem_sge_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 sge i32 %y, 1074977276
----------------
dtcxzyw wrote:
Same as above.
https://github.com/llvm/llvm-project/pull/72504
More information about the llvm-commits
mailing list