[llvm] 95e4ad3 - [InstCombine] Remove redundant add+and fold (NFCI)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 24 08:11:45 PDT 2023
Author: Nikita Popov
Date: 2023-10-24T17:10:27+02:00
New Revision: 95e4ad3f0f6a948176e278f8e147d1667dbf58b7
URL: https://github.com/llvm/llvm-project/commit/95e4ad3f0f6a948176e278f8e147d1667dbf58b7
DIFF: https://github.com/llvm/llvm-project/commit/95e4ad3f0f6a948176e278f8e147d1667dbf58b7.diff
LOG: [InstCombine] Remove redundant add+and fold (NFCI)
This is handling a special case of demanded bits simplification
(which has multi-use support for adds, so it's not applicable in
that case either).
Added:
Modified:
llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
index 42734c42750f30e..070d386b2f18d24 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
@@ -2248,13 +2248,6 @@ Instruction *InstCombinerImpl::visitAnd(BinaryOperator &I) {
const APInt *AddC;
if (match(Op0, m_Add(m_Value(X), m_APInt(AddC)))) {
- // If we add zeros to every bit below a mask, the add has no effect:
- // (X + AddC) & LowMaskC --> X & LowMaskC
- unsigned Ctlz = C->countl_zero();
- APInt LowMask(APInt::getLowBitsSet(Width, Width - Ctlz));
- if ((*AddC & LowMask).isZero())
- return BinaryOperator::CreateAnd(X, Op1);
-
// If we are masking the result of the add down to exactly one bit and
// the constant we are adding has no bits set below that bit, then the
// add is flipping a single bit. Example:
More information about the llvm-commits
mailing list