[llvm] [InstructionSimplify] Use m_CheckedInt for simplifyAndInst and simplifyOrInst (NFC) (PR #100682)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 25 18:44:00 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-analysis
Author: AtariDreams (AtariDreams)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/100682.diff
1 Files Affected:
- (modified) llvm/lib/Analysis/InstructionSimplify.cpp (+13-8)
``````````diff
diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp
index 3a7ae577bb068..59c6b434eb11f 100644
--- a/llvm/lib/Analysis/InstructionSimplify.cpp
+++ b/llvm/lib/Analysis/InstructionSimplify.cpp
@@ -2105,17 +2105,21 @@ static Value *simplifyAndInst(Value *Op0, Value *Op1, const SimplifyQuery &Q,
const APInt *Mask;
const APInt *ShAmt;
Value *X, *Y;
+ auto LogicalShiftRightIsZero = [&Mask](const APInt &ShAmt) {
+ return (~(*Mask)).lshr(ShAmt).isZero();
+ };
+ auto ShiftLeftIsZero = [&Mask](const APInt &ShAmt) {
+ return (~(*Mask)).shl(ShAmt).isZero();
+ };
if (match(Op1, m_APInt(Mask))) {
// If all bits in the inverted and shifted mask are clear:
// and (shl X, ShAmt), Mask --> shl X, ShAmt
- if (match(Op0, m_Shl(m_Value(X), m_APInt(ShAmt))) &&
- (~(*Mask)).lshr(*ShAmt).isZero())
+ if (match(Op0, m_Shl(m_Value(X), m_CheckedInt(LogicalShiftRightIsZero))))
return Op0;
// If all bits in the inverted and shifted mask are clear:
// and (lshr X, ShAmt), Mask --> lshr X, ShAmt
- if (match(Op0, m_LShr(m_Value(X), m_APInt(ShAmt))) &&
- (~(*Mask)).shl(*ShAmt).isZero())
+ if (match(Op0, m_LShr(m_Value(X), m_CheckedInt(ShiftLeftIsZero))))
return Op0;
}
@@ -2376,14 +2380,15 @@ static Value *simplifyOrInst(Value *Op0, Value *Op1, const SimplifyQuery &Q,
// (-1 >> X) | (-1 << (C - X)) --> -1
// ...with C <= bitwidth (and commuted variants).
Value *X, *Y;
+ auto UleCheck = [&X](const APInt &C) {
+ return C.ule(X->getType()->getScalarSizeInBits());
+ };
if ((match(Op0, m_Shl(m_AllOnes(), m_Value(X))) &&
match(Op1, m_LShr(m_AllOnes(), m_Value(Y)))) ||
(match(Op1, m_Shl(m_AllOnes(), m_Value(X))) &&
match(Op0, m_LShr(m_AllOnes(), m_Value(Y))))) {
- const APInt *C;
- if ((match(X, m_Sub(m_APInt(C), m_Specific(Y))) ||
- match(Y, m_Sub(m_APInt(C), m_Specific(X)))) &&
- C->ule(X->getType()->getScalarSizeInBits())) {
+ if (match(X, m_Sub(m_CheckedInt(UleCheck), m_Specific(Y))) ||
+ match(Y, m_Sub(m_CheckedInt(UleCheck), m_Specific(X)))) {
return ConstantInt::getAllOnesValue(X->getType());
}
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/100682
More information about the llvm-commits
mailing list