mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-07-18 10:24:45 +00:00
IC: (X & 5) == 13 --> false
IC: (X | 8) == 4 --> false git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@7257 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -697,15 +697,35 @@ Instruction *InstCombiner::visitSetCondInst(BinaryOperator &I) {
|
|||||||
// integers at the end of their ranges...
|
// integers at the end of their ranges...
|
||||||
//
|
//
|
||||||
if (ConstantInt *CI = dyn_cast<ConstantInt>(Op1)) {
|
if (ConstantInt *CI = dyn_cast<ConstantInt>(Op1)) {
|
||||||
if (CI->isNullValue()) {
|
// Simplify seteq and setne instructions...
|
||||||
if (I.getOpcode() == Instruction::SetNE)
|
if (I.getOpcode() == Instruction::SetEQ ||
|
||||||
return new CastInst(Op0, Type::BoolTy, I.getName());
|
I.getOpcode() == Instruction::SetNE) {
|
||||||
else if (I.getOpcode() == Instruction::SetEQ) {
|
bool isSetNE = I.getOpcode() == Instruction::SetNE;
|
||||||
|
|
||||||
|
if (CI->isNullValue()) { // Simplify [seteq|setne] X, 0
|
||||||
|
CastInst *Val = new CastInst(Op0, Type::BoolTy, I.getName()+".not");
|
||||||
|
if (isSetNE) return Val;
|
||||||
|
|
||||||
// seteq X, 0 -> not (cast X to bool)
|
// seteq X, 0 -> not (cast X to bool)
|
||||||
Instruction *Val = new CastInst(Op0, Type::BoolTy, I.getName()+".not");
|
|
||||||
InsertNewInstBefore(Val, I);
|
InsertNewInstBefore(Val, I);
|
||||||
return BinaryOperator::createNot(Val, I.getName());
|
return BinaryOperator::createNot(Val, I.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If the first operand is (and|or) with a constant, and the second
|
||||||
|
// operand is a constant, simplify a bit.
|
||||||
|
if (BinaryOperator *BO = dyn_cast<BinaryOperator>(Op0))
|
||||||
|
if (ConstantInt *BOC = dyn_cast<ConstantInt>(BO->getOperand(1)))
|
||||||
|
if (BO->getOpcode() == Instruction::Or) {
|
||||||
|
// If bits are being or'd in that are not present in the constant we
|
||||||
|
// are comparing against, then the comparison could never succeed!
|
||||||
|
if (!(*BOC & *~*CI)->isNullValue())
|
||||||
|
return ReplaceInstUsesWith(I, ConstantBool::get(isSetNE));
|
||||||
|
} else if (BO->getOpcode() == Instruction::And) {
|
||||||
|
// If bits are being compared against that are and'd out, then the
|
||||||
|
// comparison can never succeed!
|
||||||
|
if (!(*CI & *~*BOC)->isNullValue())
|
||||||
|
return ReplaceInstUsesWith(I, ConstantBool::get(isSetNE));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check to see if we are comparing against the minimum or maximum value...
|
// Check to see if we are comparing against the minimum or maximum value...
|
||||||
|
Reference in New Issue
Block a user