Bitcasts are transitive. Bitcast-Bitcast-X becomes Bitcast-X.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@138722 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Nadav Rotem
2011-08-28 11:51:08 +00:00
parent b1b051ec97
commit be6ceb6ebc
3 changed files with 25 additions and 0 deletions

View File

@ -1659,6 +1659,11 @@ Instruction *InstCombiner::visitBitCast(BitCastInst &CI) {
if (DestTy == Src->getType())
return ReplaceInstUsesWith(CI, Src);
// Bitcasts are transitive.
if (BitCastInst* BSrc = dyn_cast<BitCastInst>(Src)) {
return CastInst::Create(Instruction::BitCast, BSrc->getOperand(0), DestTy);
}
if (PointerType *DstPTy = dyn_cast<PointerType>(DestTy)) {
PointerType *SrcPTy = cast<PointerType>(SrcTy);
Type *DstElTy = DstPTy->getElementType();