if (Value *V = SimplifyUsingDistributiveLaws(I))
return replaceInstUsesWith(I, V);
- const APInt *Val;
- if (match(RHS, m_APInt(Val))) {
- if (Val->isSignBit()) {
+ const APInt *RHSC;
+ if (match(RHS, m_APInt(RHSC))) {
+ if (RHSC->isSignBit()) {
// If wrapping is not allowed, then the addition must set the sign bit:
// X + (signbit) --> X | signbit
if (I.hasNoSignedWrap() || I.hasNoUnsignedWrap())
const APInt *C;
if (match(LHS, m_ZExt(m_Xor(m_Value(X), m_APInt(C)))) &&
C->isMinSignedValue() &&
- C->sext(LHS->getType()->getScalarSizeInBits()) == *Val) {
+ C->sext(LHS->getType()->getScalarSizeInBits()) == *RHSC) {
// add(zext(xor i16 X, -32768), -32768) --> sext X
return CastInst::Create(Instruction::SExt, X, LHS->getType());
}
- if (Val->isNegative() &&
+ if (RHSC->isNegative() &&
match(LHS, m_ZExt(m_NUWAdd(m_Value(X), m_APInt(C)))) &&
- Val->sge(-C->sext(Val->getBitWidth()))) {
+ RHSC->sge(-C->sext(RHSC->getBitWidth()))) {
// (add (zext (add nuw X, C)), Val) -> (zext (add nuw X, C+Val))
Constant *NewC =
- ConstantInt::get(X->getType(), *C + Val->trunc(C->getBitWidth()));
+ ConstantInt::get(X->getType(), *C + RHSC->trunc(C->getBitWidth()));
return new ZExtInst(Builder->CreateNUWAdd(X, NewC), I.getType());
}
}
return BinaryOperator::CreateOr(A, B);
}
+
// (add (or A, B) (and A, B)) --> (add A, B)
{
Value *A = nullptr, *B = nullptr;