[llvm] Implement foldICmpRemConstant in InstCombineCompares (PR #77410)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 8 21:05:05 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 f6dbd4cc5f52b6d40f98cf09af22b276b8e1f289 1ebf04dceb32e44d90209070c3d6e6d7349d6559 -- 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 0add51b817..dadfae6f45 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
@@ -2587,7 +2587,8 @@ Instruction *InstCombinerImpl::foldICmpRemConstant(ICmpInst &Cmp,
BinaryOperator *MulY = cast<BinaryOperator>(Y);
// Check if the operands are multiplication operations.
- if (MulX->getOpcode() != Instruction::Mul || MulY->getOpcode() != Instruction::Mul)
+ if (MulX->getOpcode() != Instruction::Mul ||
+ MulY->getOpcode() != Instruction::Mul)
return nullptr;
// Get the multiplication operands and constants.
@@ -2599,7 +2600,8 @@ Instruction *InstCombinerImpl::foldICmpRemConstant(ICmpInst &Cmp,
const APInt *C1Value, *C2Value;
// Check if the constants satisfy the condition c1 % c2 == 0.
- if (!match(C1, m_APInt(C1Value)) || !match(C2, m_APInt(C2Value)) || C1Value->urem(*C2Value) != 0)
+ if (!match(C1, m_APInt(C1Value)) || !match(C2, m_APInt(C2Value)) ||
+ C1Value->urem(*C2Value) != 0)
return nullptr;
// Compute the new constant k = c1 / c2.
@@ -2607,11 +2609,11 @@ Instruction *InstCombinerImpl::foldICmpRemConstant(ICmpInst &Cmp,
Type *Ty = Rem->getType();
// Create a new remainder instruction (a * k) % b.
- Value *NewRem = Builder.CreateURem(Builder.CreateMul(A, ConstantInt::get(A->getType(), K)), B);
+ Value *NewRem = Builder.CreateURem(
+ Builder.CreateMul(A, ConstantInt::get(A->getType(), K)), B);
return new ICmpInst(Pred, NewRem, ConstantInt::get(Ty, C));
}
-
/// Fold icmp (udiv X, Y), C.
Instruction *InstCombinerImpl::foldICmpUDivConstant(ICmpInst &Cmp,
BinaryOperator *UDiv,
@@ -3003,7 +3005,7 @@ Instruction *InstCombinerImpl::foldICmpAddConstant(ICmpInst &Cmp,
// Fold icmp pred (add X, C2), C.
Type *Ty = Add->getType();
-
+
// If the add does not wrap, we can always adjust the compare by subtracting
// the constants. Equality comparisons are handled elsewhere. SGE/SLE/UGE/ULE
// are canonicalized to SGT/SLT/UGT/ULT.
@@ -3748,10 +3750,10 @@ Instruction *InstCombinerImpl::foldICmpBinOpWithConstant(ICmpInst &Cmp,
case Instruction::SRem:
if (Instruction *I = foldICmpSRemConstant(Cmp, BO, C))
return I;
- [[fallthrough]];
+ [[fallthrough]];
case Instruction::URem:
- if (Instruction *I = foldICmpRemConstant(Cmp, BO, C))
- return I;
+ if (Instruction *I = foldICmpRemConstant(Cmp, BO, C))
+ return I;
break;
case Instruction::UDiv:
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineInternal.h b/llvm/lib/Transforms/InstCombine/InstCombineInternal.h
index 748fe04c47..9be32f69bf 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineInternal.h
+++ b/llvm/lib/Transforms/InstCombine/InstCombineInternal.h
@@ -673,7 +673,7 @@ public:
Instruction *foldICmpSRemConstant(ICmpInst &Cmp, BinaryOperator *SRem,
const APInt &C);
Instruction *foldICmpRemConstant(ICmpInst &Cmp, BinaryOperator *Rem,
- const APInt &C);
+ const APInt &C);
Instruction *foldICmpUDivConstant(ICmpInst &Cmp, BinaryOperator *UDiv,
const APInt &C);
Instruction *foldICmpDivConstant(ICmpInst &Cmp, BinaryOperator *Div,
``````````
</details>
https://github.com/llvm/llvm-project/pull/77410
More information about the llvm-commits
mailing list