Fix similar missing optimization opportunity in XOR.

llvm-svn: 31123
This commit is contained in:
Nick Lewycky 2006-10-22 22:22:58 +00:00
parent bb3084546a
commit 6f5c30fcec
1 changed files with 22 additions and 13 deletions

View File

@ -349,19 +349,28 @@ namespace {
} }
} break; } break;
case Instruction::Xor: { case Instruction::Xor: {
ConstantIntegral *CI = dyn_cast<ConstantIntegral>(V1); if (ConstantIntegral *CI = dyn_cast<ConstantIntegral>(V1)) {
if (!CI) break; const Type *Ty = BO->getType();
if (CI->isAllOnesValue()) { if (CI->isAllOnesValue()) {
if (BO->getOperand(0) == V1) if (BO->getOperand(0) == V1)
add(Opcode, ConstantBool::getFalse(), BO->getOperand(1), false); add(Opcode, Constant::getNullValue(Ty),
BO->getOperand(1), false);
if (BO->getOperand(1) == V1) if (BO->getOperand(1) == V1)
add(Opcode, ConstantBool::getFalse(), BO->getOperand(0), false); add(Opcode, Constant::getNullValue(Ty),
BO->getOperand(0), false);
} }
if (CI->isNullValue()) { if (CI->isNullValue()) {
if (BO->getOperand(0) == ConstantBool::getTrue()) ConstantIntegral *Op0 =
add(Opcode, ConstantBool::getTrue(), BO->getOperand(1), false); dyn_cast<ConstantIntegral>(BO->getOperand(0));
if (BO->getOperand(1) == ConstantBool::getTrue()) ConstantIntegral *Op1 =
add(Opcode, ConstantBool::getTrue(), BO->getOperand(0), false); dyn_cast<ConstantIntegral>(BO->getOperand(1));
if (Op0 && Op0->isAllOnesValue())
add(Opcode, ConstantIntegral::getAllOnesValue(Ty),
BO->getOperand(1), false);
if (Op1 && Op1->isAllOnesValue())
add(Opcode, ConstantIntegral::getAllOnesValue(Ty),
BO->getOperand(0), false);
}
} }
} break; } break;
default: default: