mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-15 04:30:12 +00:00
Implement InstCombine/cast-propagate.ll
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12784 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
77aac1226a
commit
f499eaca36
@ -2639,6 +2639,27 @@ Instruction *InstCombiner::visitLoadInst(LoadInst &LI) {
|
|||||||
if (GV->isConstant() && !GV->isExternal())
|
if (GV->isConstant() && !GV->isExternal())
|
||||||
if (Constant *V = GetGEPGlobalInitializer(GV->getInitializer(), CE))
|
if (Constant *V = GetGEPGlobalInitializer(GV->getInitializer(), CE))
|
||||||
return ReplaceInstUsesWith(LI, V);
|
return ReplaceInstUsesWith(LI, V);
|
||||||
|
|
||||||
|
// load (cast X) --> cast (load X) iff safe
|
||||||
|
if (CastInst *CI = dyn_cast<CastInst>(Op)) {
|
||||||
|
const Type *DestPTy = cast<PointerType>(CI->getType())->getElementType();
|
||||||
|
if (const PointerType *SrcTy =
|
||||||
|
dyn_cast<PointerType>(CI->getOperand(0)->getType())) {
|
||||||
|
const Type *SrcPTy = SrcTy->getElementType();
|
||||||
|
if (TD->getTypeSize(SrcPTy) == TD->getTypeSize(DestPTy) &&
|
||||||
|
(SrcPTy->isInteger() || isa<PointerType>(SrcPTy)) &&
|
||||||
|
(DestPTy->isInteger() || isa<PointerType>(DestPTy))) {
|
||||||
|
// Okay, we are casting from one integer or pointer type to another of
|
||||||
|
// the same size. Instead of casting the pointer before the load, cast
|
||||||
|
// the result of the loaded value.
|
||||||
|
Value *NewLoad = InsertNewInstBefore(new LoadInst(CI->getOperand(0),
|
||||||
|
CI->getName()), LI);
|
||||||
|
// Now cast the result of the load.
|
||||||
|
return new CastInst(NewLoad, LI.getType());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user