[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 Jan 12 17:59:31 PST 2024


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff 4b3ea337ad188d5c3ff05bf64cc61c3355e66376 b3550bf4986803b538d4cb09c94fbb6b3718cc45 -- llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp llvm/lib/Transforms/InstCombine/InstCombineInternal.h
``````````

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
index 6d1e5ca36f..19908ff9ad 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
@@ -2538,8 +2538,8 @@ Instruction *InstCombinerImpl::foldICmpSRemConstant(ICmpInst &Cmp,
                               : ICmpInst::ICMP_EQ,
                           SRem,
                           ConstantInt::get(SRem->getType(), C1->isNegative()
-                                                               ? *C1 + 1
-                                                               : *C1 - 1));
+                                                                ? *C1 + 1
+                                                                : *C1 - 1));
     }
   }
 
@@ -2591,18 +2591,18 @@ Instruction *InstCombinerImpl::foldICmpSRemConstant(ICmpInst &Cmp,
 }
 
 Instruction *InstCombinerImpl::foldICmpURemConstant(ICmpInst &Cmp,
-                                  BinaryOperator *URem,
-                                  const APInt &C) {
+                                                    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));
+      ((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;
 }

``````````

</details>


https://github.com/llvm/llvm-project/pull/72504


More information about the llvm-commits mailing list