diff options
author | Guozhi Wei <carrot@google.com> | 2020-03-04 11:10:32 -0800 |
---|---|---|
committer | Guozhi Wei <carrot@google.com> | 2020-03-04 11:10:32 -0800 |
commit | ee9a3eba769787bd87ac47945508751dafa5a46b (patch) | |
tree | c2cd82b7fff8dbbb50550e4d9b4f4d5e489180b8 /llvm/lib/CodeGen/CodeGenPrepare.cpp | |
parent | 4ab2ea9fc09d93ef136a690f3f94d3c791540fcf (diff) | |
download | llvm-ee9a3eba769787bd87ac47945508751dafa5a46b.zip llvm-ee9a3eba769787bd87ac47945508751dafa5a46b.tar.gz llvm-ee9a3eba769787bd87ac47945508751dafa5a46b.tar.bz2 |
[CodeGenPrepare] Handle ExtractValueInst in dupRetToEnableTailCallOpts
As the test case shows if there is an ExtractValueInst in the Ret block, function dupRetToEnableTailCallOpts can't duplicate it into the block containing call. So later no tail call is generated in CodeGen.
This patch adds the ExtractValueInst handling code in function dupRetToEnableTailCallOpts and FoldReturnIntoUncondBranch, and later tail call can be generated for this case.
Differential Revision: https://reviews.llvm.org/D74242
Diffstat (limited to 'llvm/lib/CodeGen/CodeGenPrepare.cpp')
-rw-r--r-- | llvm/lib/CodeGen/CodeGenPrepare.cpp | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/llvm/lib/CodeGen/CodeGenPrepare.cpp b/llvm/lib/CodeGen/CodeGenPrepare.cpp index 1ac459d..052316f 100644 --- a/llvm/lib/CodeGen/CodeGenPrepare.cpp +++ b/llvm/lib/CodeGen/CodeGenPrepare.cpp @@ -2102,6 +2102,7 @@ bool CodeGenPrepare::dupRetToEnableTailCallOpts(BasicBlock *BB, bool &ModifiedDT return false; PHINode *PN = nullptr; + ExtractValueInst *EVI = nullptr; BitCastInst *BCI = nullptr; Value *V = RetI->getReturnValue(); if (V) { @@ -2109,6 +2110,14 @@ bool CodeGenPrepare::dupRetToEnableTailCallOpts(BasicBlock *BB, bool &ModifiedDT if (BCI) V = BCI->getOperand(0); + EVI = dyn_cast<ExtractValueInst>(V); + if (EVI) { + V = EVI->getOperand(0); + if (!std::all_of(EVI->idx_begin(), EVI->idx_end(), + [](unsigned idx) { return idx == 0; })) + return false; + } + PN = dyn_cast<PHINode>(V); if (!PN) return false; @@ -2122,7 +2131,9 @@ bool CodeGenPrepare::dupRetToEnableTailCallOpts(BasicBlock *BB, bool &ModifiedDT if (PN) { BasicBlock::iterator BI = BB->begin(); // Skip over debug and the bitcast. - do { ++BI; } while (isa<DbgInfoIntrinsic>(BI) || &*BI == BCI); + do { + ++BI; + } while (isa<DbgInfoIntrinsic>(BI) || &*BI == BCI || &*BI == EVI); if (&*BI != RetI) return false; } else { |