[llvm] [InstCombine] Fold comparisons of remainder expressions with multiplied contants (PR #79383)

via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 26 22:39:17 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 61d098962e1b304224fb5309b94162a3e43852bb 9935f164f79de7b6b5c47d6be8e7ee1b896a6b29 -- 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 4e2abb2225..c565d7b82b 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
@@ -2602,24 +2602,24 @@ Instruction *InstCombinerImpl::foldICmpRemConstant(ICmpInst &Cmp,
   if (C2->isZero())
     return nullptr;
 
-  Instruction* I1 = dyn_cast<Instruction>(X);
-  Instruction* I2 = dyn_cast<Instruction>(Y);
+  Instruction *I1 = dyn_cast<Instruction>(X);
+  Instruction *I2 = dyn_cast<Instruction>(Y);
 
   if (Rem->getOpcode() == Instruction::SRem) {
     // Check if both NSW and NUW flags are on
-    if (!I1->hasNoUnsignedWrap()){
+    if (!I1->hasNoUnsignedWrap()) {
       return nullptr;
-    }   
-    if (!I1->hasNoSignedWrap()){
+    }
+    if (!I1->hasNoSignedWrap()) {
       return nullptr;
     }
-    if (!I2->hasNoUnsignedWrap()){
+    if (!I2->hasNoUnsignedWrap()) {
       return nullptr;
     }
-    if (!I2->hasNoSignedWrap()){
+    if (!I2->hasNoSignedWrap()) {
       return nullptr;
     }
-    if (!C1->srem(*C2).isZero()){
+    if (!C1->srem(*C2).isZero()) {
       return nullptr;
     }
     // Compute the new constant k = c1 / c2.
@@ -2633,13 +2633,13 @@ Instruction *InstCombinerImpl::foldICmpRemConstant(ICmpInst &Cmp,
                             true),
           B);
   } else {
-    if (!I1->hasNoUnsignedWrap()){
+    if (!I1->hasNoUnsignedWrap()) {
       return nullptr;
     }
-    if (!I2->hasNoUnsignedWrap()){
+    if (!I2->hasNoUnsignedWrap()) {
       return nullptr;
     }
-    if (!C1->urem(*C2).isZero()){
+    if (!C1->urem(*C2).isZero()) {
       return nullptr;
     }
     // Compute the new constant k = c1 / c2.
@@ -2647,8 +2647,7 @@ Instruction *InstCombinerImpl::foldICmpRemConstant(ICmpInst &Cmp,
     Ty = Rem->getType();
     if (K == 1) {
       NewRem = Builder.CreateURem(A, B);
-    }
-    else {
+    } else {
       NewRem = Builder.CreateURem(
           Builder.CreateMul(A, ConstantInt::get(A->getType(), K), "", true,
                             I1->hasNoSignedWrap()),

``````````

</details>


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


More information about the llvm-commits mailing list