// fold (and (cast A), (cast B)) -> (cast (and A, B))
if (CastInst *Op0C = dyn_cast<CastInst>(Op0)) {
+ const Type *SrcTy = Op0C->getOperand(0)->getType();
if (CastInst *Op1C = dyn_cast<CastInst>(Op1))
- if (Op0C->getOperand(0)->getType() == Op1C->getOperand(0)->getType() &&
- Op0C->getOperand(0)->getType()->isIntegral()) {
+ if (SrcTy == Op1C->getOperand(0)->getType() && SrcTy->isIntegral() &&
+ !SrcTy->isLosslesslyConvertibleTo(Op0C->getType())) {
Instruction *NewOp = BinaryOperator::createAnd(Op0C->getOperand(0),
Op1C->getOperand(0),
I.getName());
// fold (or (cast A), (cast B)) -> (cast (or A, B))
if (CastInst *Op0C = dyn_cast<CastInst>(Op0)) {
+ const Type *SrcTy = Op0C->getOperand(0)->getType();
if (CastInst *Op1C = dyn_cast<CastInst>(Op1))
- if (Op0C->getOperand(0)->getType() == Op1C->getOperand(0)->getType() &&
- Op0C->getOperand(0)->getType()->isIntegral()) {
+ if (SrcTy == Op1C->getOperand(0)->getType() && SrcTy->isIntegral() &&
+ !SrcTy->isLosslesslyConvertibleTo(Op0C->getType())) {
Instruction *NewOp = BinaryOperator::createOr(Op0C->getOperand(0),
Op1C->getOperand(0),
I.getName());
// fold (xor (cast A), (cast B)) -> (cast (xor A, B))
if (CastInst *Op0C = dyn_cast<CastInst>(Op0)) {
+ const Type *SrcTy = Op0C->getOperand(0)->getType();
if (CastInst *Op1C = dyn_cast<CastInst>(Op1))
- if (Op0C->getOperand(0)->getType() == Op1C->getOperand(0)->getType() &&
- Op0C->getOperand(0)->getType()->isIntegral()) {
+ if (SrcTy == Op1C->getOperand(0)->getType() && SrcTy->isIntegral() &&
+ !SrcTy->isLosslesslyConvertibleTo(Op0C->getType())) {
Instruction *NewOp = BinaryOperator::createXor(Op0C->getOperand(0),
Op1C->getOperand(0),
I.getName());