Skip to content

Commit

Permalink
[InstCombine] Remove redundant add+and fold (NFCI)
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
nikic committed Oct 24, 2023
1 parent b5c4456 commit 95e4ad3
Showing 1 changed file with 0 additions and 7 deletions.
7 changes: 0 additions & 7 deletions llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 95e4ad3

Please sign in to comment.