mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-25 04:02:41 +01:00
Fix and/or/xor (cast A), (cast B) --> cast (and/or/xor A, B)
The cast patch introduced the possibility that the wrong cast opcode could be used and that this transform could trigger on different kinds of cast operations. This patch rectifies that. llvm-svn: 32538
This commit is contained in:
parent
d0bbb4e6dc
commit
32b08ba50f
@ -3270,8 +3270,9 @@ Instruction *InstCombiner::visitAnd(BinaryOperator &I) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// fold (and (cast A), (cast B)) -> (cast (and A, B))
|
// fold (and (cast A), (cast B)) -> (cast (and A, B))
|
||||||
if (CastInst *Op1C = dyn_cast<CastInst>(Op1)) {
|
if (CastInst *Op0C = dyn_cast<CastInst>(Op0))
|
||||||
if (CastInst *Op0C = dyn_cast<CastInst>(Op0)) {
|
if (CastInst *Op1C = dyn_cast<CastInst>(Op1))
|
||||||
|
if (Op0C->getOpcode() == Op1C->getOpcode()) { // same cast kind ?
|
||||||
const Type *SrcTy = Op0C->getOperand(0)->getType();
|
const Type *SrcTy = Op0C->getOperand(0)->getType();
|
||||||
if (SrcTy == Op1C->getOperand(0)->getType() && SrcTy->isIntegral() &&
|
if (SrcTy == Op1C->getOperand(0)->getType() && SrcTy->isIntegral() &&
|
||||||
// Only do this if the casts both really cause code to be generated.
|
// Only do this if the casts both really cause code to be generated.
|
||||||
@ -3281,9 +3282,7 @@ Instruction *InstCombiner::visitAnd(BinaryOperator &I) {
|
|||||||
Op1C->getOperand(0),
|
Op1C->getOperand(0),
|
||||||
I.getName());
|
I.getName());
|
||||||
InsertNewInstBefore(NewOp, I);
|
InsertNewInstBefore(NewOp, I);
|
||||||
return CastInst::createIntegerCast(NewOp, I.getType(),
|
return CastInst::create(Op0C->getOpcode(), NewOp, I.getType());
|
||||||
SrcTy->isSigned());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3675,9 +3674,10 @@ Instruction *InstCombiner::visitOr(BinaryOperator &I) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// fold (or (cast A), (cast B)) -> (cast (or A, B))
|
// fold (or (cast A), (cast B)) -> (cast (or A, B))
|
||||||
if (CastInst *Op0C = dyn_cast<CastInst>(Op0)) {
|
if (CastInst *Op0C = dyn_cast<CastInst>(Op0))
|
||||||
const Type *SrcTy = Op0C->getOperand(0)->getType();
|
|
||||||
if (CastInst *Op1C = dyn_cast<CastInst>(Op1))
|
if (CastInst *Op1C = dyn_cast<CastInst>(Op1))
|
||||||
|
if (Op0C->getOpcode() == Op1C->getOpcode()) {// same cast kind ?
|
||||||
|
const Type *SrcTy = Op0C->getOperand(0)->getType();
|
||||||
if (SrcTy == Op1C->getOperand(0)->getType() && SrcTy->isIntegral() &&
|
if (SrcTy == Op1C->getOperand(0)->getType() && SrcTy->isIntegral() &&
|
||||||
// Only do this if the casts both really cause code to be generated.
|
// Only do this if the casts both really cause code to be generated.
|
||||||
ValueRequiresCast(Op0C->getOperand(0), I.getType(), TD) &&
|
ValueRequiresCast(Op0C->getOperand(0), I.getType(), TD) &&
|
||||||
@ -3686,8 +3686,7 @@ Instruction *InstCombiner::visitOr(BinaryOperator &I) {
|
|||||||
Op1C->getOperand(0),
|
Op1C->getOperand(0),
|
||||||
I.getName());
|
I.getName());
|
||||||
InsertNewInstBefore(NewOp, I);
|
InsertNewInstBefore(NewOp, I);
|
||||||
return CastInst::createIntegerCast(NewOp, I.getType(),
|
return CastInst::create(Op0C->getOpcode(), NewOp, I.getType());
|
||||||
SrcTy->isSigned());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3857,9 +3856,10 @@ Instruction *InstCombiner::visitXor(BinaryOperator &I) {
|
|||||||
return R;
|
return R;
|
||||||
|
|
||||||
// fold (xor (cast A), (cast B)) -> (cast (xor A, B))
|
// fold (xor (cast A), (cast B)) -> (cast (xor A, B))
|
||||||
if (CastInst *Op0C = dyn_cast<CastInst>(Op0)) {
|
if (CastInst *Op0C = dyn_cast<CastInst>(Op0))
|
||||||
const Type *SrcTy = Op0C->getOperand(0)->getType();
|
|
||||||
if (CastInst *Op1C = dyn_cast<CastInst>(Op1))
|
if (CastInst *Op1C = dyn_cast<CastInst>(Op1))
|
||||||
|
if (Op0C->getOpcode() == Op1C->getOpcode()) { // same cast kind?
|
||||||
|
const Type *SrcTy = Op0C->getOperand(0)->getType();
|
||||||
if (SrcTy == Op1C->getOperand(0)->getType() && SrcTy->isIntegral() &&
|
if (SrcTy == Op1C->getOperand(0)->getType() && SrcTy->isIntegral() &&
|
||||||
// Only do this if the casts both really cause code to be generated.
|
// Only do this if the casts both really cause code to be generated.
|
||||||
ValueRequiresCast(Op0C->getOperand(0), I.getType(), TD) &&
|
ValueRequiresCast(Op0C->getOperand(0), I.getType(), TD) &&
|
||||||
@ -3868,8 +3868,7 @@ Instruction *InstCombiner::visitXor(BinaryOperator &I) {
|
|||||||
Op1C->getOperand(0),
|
Op1C->getOperand(0),
|
||||||
I.getName());
|
I.getName());
|
||||||
InsertNewInstBefore(NewOp, I);
|
InsertNewInstBefore(NewOp, I);
|
||||||
return CastInst::createIntegerCast(NewOp, I.getType(),
|
return CastInst::create(Op0C->getOpcode(), NewOp, I.getType());
|
||||||
SrcTy->isSigned());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user