Index: llvm/lib/Analysis/LazyValueInfo.cpp =================================================================== --- llvm/lib/Analysis/LazyValueInfo.cpp +++ llvm/lib/Analysis/LazyValueInfo.cpp @@ -1085,13 +1085,38 @@ CmpInst::Predicate EdgePred = isTrueDest ? ICI->getPredicate() : ICI->getInversePredicate(); - if (isa(RHS)) { - if (ICI->isEquality() && LHS == Val) { + if (isa(RHS) && ICI->isEquality()) { + if (LHS == Val) { + // We know that V has the RHS constant if the edge predicate is equality. if (EdgePred == ICmpInst::ICMP_EQ) return ValueLatticeElement::get(cast(RHS)); else if (!isa(RHS)) return ValueLatticeElement::getNot(cast(RHS)); } + + if (ConstantInt *CIRHS = dyn_cast(RHS)) { + ConstantInt *Mask; + if (match(LHS, m_And(m_Specific(Val), m_ConstantInt(Mask)))) { + const APInt &FixedBits = CIRHS->getValue(); + APInt MaskValue = Mask->getValue(); + MaskValue.flipAllBits(); + + if (MaskValue.isMask()) { + using VLE = ValueLatticeElement; + if ((MaskValue & FixedBits) == 0) { + if (EdgePred == ICmpInst::ICMP_EQ) + return VLE::getRange({FixedBits, FixedBits + MaskValue + 1}); + else + return VLE::getRange({FixedBits + MaskValue + 1, FixedBits}); + } else { + if (EdgePred == ICmpInst::ICMP_EQ) + return VLE(); + else + return VLE::getOverdefined(); + } + } + } + } } Type *Ty = Val->getType();