forked from OSchip/llvm-project
[InstCombine] SimplifyDemandedUseBits - xor - refactor cast<ConstantInt> usage to PatternMatch. NFCI.
First step towards replacing these to add full vector support.
This commit is contained in:
parent
2b45639ea0
commit
b3330ae42c
|
@ -278,26 +278,25 @@ Value *InstCombinerImpl::SimplifyDemandedUseBits(Value *V, APInt DemandedMask,
|
|||
// are flipping are known to be set, then the xor is just resetting those
|
||||
// bits to zero. We can just knock out bits from the 'and' and the 'xor',
|
||||
// simplifying both of them.
|
||||
if (Instruction *LHSInst = dyn_cast<Instruction>(I->getOperand(0)))
|
||||
if (Instruction *LHSInst = dyn_cast<Instruction>(I->getOperand(0))) {
|
||||
ConstantInt *AndRHS, *XorRHS;
|
||||
if (LHSInst->getOpcode() == Instruction::And && LHSInst->hasOneUse() &&
|
||||
isa<ConstantInt>(I->getOperand(1)) &&
|
||||
isa<ConstantInt>(LHSInst->getOperand(1)) &&
|
||||
match(I->getOperand(1), m_ConstantInt(XorRHS)) &&
|
||||
match(LHSInst->getOperand(1), m_ConstantInt(AndRHS)) &&
|
||||
(LHSKnown.One & RHSKnown.One & DemandedMask) != 0) {
|
||||
ConstantInt *AndRHS = cast<ConstantInt>(LHSInst->getOperand(1));
|
||||
ConstantInt *XorRHS = cast<ConstantInt>(I->getOperand(1));
|
||||
APInt NewMask = ~(LHSKnown.One & RHSKnown.One & DemandedMask);
|
||||
|
||||
Constant *AndC =
|
||||
ConstantInt::get(I->getType(), NewMask & AndRHS->getValue());
|
||||
ConstantInt::get(I->getType(), NewMask & AndRHS->getValue());
|
||||
Instruction *NewAnd = BinaryOperator::CreateAnd(I->getOperand(0), AndC);
|
||||
InsertNewInstWith(NewAnd, *I);
|
||||
|
||||
Constant *XorC =
|
||||
ConstantInt::get(I->getType(), NewMask & XorRHS->getValue());
|
||||
ConstantInt::get(I->getType(), NewMask & XorRHS->getValue());
|
||||
Instruction *NewXor = BinaryOperator::CreateXor(NewAnd, XorC);
|
||||
return InsertNewInstWith(NewXor, *I);
|
||||
}
|
||||
|
||||
}
|
||||
break;
|
||||
}
|
||||
case Instruction::Select: {
|
||||
|
|
Loading…
Reference in New Issue