summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/Scalar/CodeGenPrepare.cpp
diff options
context:
space:
mode:
authorEvan Cheng <evan.cheng@apple.com>2012-07-27 21:21:26 +0000
committerEvan Cheng <evan.cheng@apple.com>2012-07-27 21:21:26 +0000
commit249716e8aef5ac234a9a29f3ed3d0a931884192e (patch)
treed4adb36ca78ae9eac416fa110cf079d4b723ed14 /llvm/lib/Transforms/Scalar/CodeGenPrepare.cpp
parent97e14e02f11a73c2705ac0cd8388b77fed59fc33 (diff)
downloadbcm5719-llvm-249716e8aef5ac234a9a29f3ed3d0a931884192e.tar.gz
bcm5719-llvm-249716e8aef5ac234a9a29f3ed3d0a931884192e.zip
Teach CodeGenPrep to look past bitcast when it's duplicating return instruction
into predecessor blocks to enable tail call optimization. rdar://11958338 llvm-svn: 160894
Diffstat (limited to 'llvm/lib/Transforms/Scalar/CodeGenPrepare.cpp')
-rw-r--r--llvm/lib/Transforms/Scalar/CodeGenPrepare.cpp17
1 files changed, 14 insertions, 3 deletions
diff --git a/llvm/lib/Transforms/Scalar/CodeGenPrepare.cpp b/llvm/lib/Transforms/Scalar/CodeGenPrepare.cpp
index f425cd03be6..4b4a8c598fc 100644
--- a/llvm/lib/Transforms/Scalar/CodeGenPrepare.cpp
+++ b/llvm/lib/Transforms/Scalar/CodeGenPrepare.cpp
@@ -645,10 +645,18 @@ bool CodeGenPrepare::DupRetToEnableTailCallOpts(ReturnInst *RI) {
if (!TLI)
return false;
+ PHINode *PN = 0;
+ BitCastInst *BCI = 0;
Value *V = RI->getReturnValue();
- PHINode *PN = V ? dyn_cast<PHINode>(V) : NULL;
- if (V && !PN)
- return false;
+ if (V) {
+ BCI = dyn_cast<BitCastInst>(V);
+ if (BCI)
+ V = BCI->getOperand(0);
+
+ PN = dyn_cast<PHINode>(V);
+ if (!PN)
+ return false;
+ }
BasicBlock *BB = RI->getParent();
if (PN && PN->getParent() != BB)
@@ -666,6 +674,9 @@ bool CodeGenPrepare::DupRetToEnableTailCallOpts(ReturnInst *RI) {
if (PN) {
BasicBlock::iterator BI = BB->begin();
do { ++BI; } while (isa<DbgInfoIntrinsic>(BI));
+ if (&*BI == BCI)
+ // Also skip over the bitcast.
+ ++BI;
if (&*BI != RI)
return false;
} else {
OpenPOWER on IntegriCloud