mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-07-29 10:25:12 +00:00
Teach CodeGenPrep to look past bitcast when it's duplicating return instruction
into predecessor blocks to enable tail call optimization. rdar://11958338 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@160894 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -659,10 +659,26 @@ ReturnInst *llvm::FoldReturnIntoUncondBranch(ReturnInst *RI, BasicBlock *BB,
|
||||
// If the return instruction returns a value, and if the value was a
|
||||
// PHI node in "BB", propagate the right value into the return.
|
||||
for (User::op_iterator i = NewRet->op_begin(), e = NewRet->op_end();
|
||||
i != e; ++i)
|
||||
if (PHINode *PN = dyn_cast<PHINode>(*i))
|
||||
if (PN->getParent() == BB)
|
||||
*i = PN->getIncomingValueForBlock(Pred);
|
||||
i != e; ++i) {
|
||||
Value *V = *i;
|
||||
Instruction *NewBC = 0;
|
||||
if (BitCastInst *BCI = dyn_cast<BitCastInst>(V)) {
|
||||
// Return value might be bitcasted. Clone and insert it before the
|
||||
// return instruction.
|
||||
V = BCI->getOperand(0);
|
||||
NewBC = BCI->clone();
|
||||
Pred->getInstList().insert(NewRet, NewBC);
|
||||
*i = NewBC;
|
||||
}
|
||||
if (PHINode *PN = dyn_cast<PHINode>(V)) {
|
||||
if (PN->getParent() == BB) {
|
||||
if (NewBC)
|
||||
NewBC->setOperand(0, PN->getIncomingValueForBlock(Pred));
|
||||
else
|
||||
*i = PN->getIncomingValueForBlock(Pred);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Update any PHI nodes in the returning block to realize that we no
|
||||
// longer branch to them.
|
||||
|
Reference in New Issue
Block a user