aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/CodeGenPrepare.cpp
diff options
context:
space:
mode:
authorGuozhi Wei <carrot@google.com>2020-03-31 11:55:51 -0700
committerGuozhi Wei <carrot@google.com>2020-03-31 11:55:51 -0700
commit6d20937c29a1a1d67fc5e8caf8538b4aa5614505 (patch)
tree91a3c21de2adb099cded1f5560c88a7e795e3fc2 /llvm/lib/CodeGen/CodeGenPrepare.cpp
parent08682dcc8631bcbfd68834a7dc352499a0a06af0 (diff)
downloadllvm-6d20937c29a1a1d67fc5e8caf8538b4aa5614505.zip
llvm-6d20937c29a1a1d67fc5e8caf8538b4aa5614505.tar.gz
llvm-6d20937c29a1a1d67fc5e8caf8538b4aa5614505.tar.bz2
[CodeGenPrepare] Delete intrinsic call to llvm.assume to enable more tailcall
The attached test case is simplified from tcmalloc. Both function calls should be optimized as tailcall. But llvm can only optimize the first call. The second call can't be optimized because function dupRetToEnableTailCallOpts failed to duplicate ret into block case2. There 2 problems blocked the duplication: 1 Intrinsic call llvm.assume is not handled by dupRetToEnableTailCallOpts. 2 The control flow is more complex than expected, dupRetToEnableTailCallOpts can only duplicate ret into its predecessor, but here we have an intermediate block between call and ret. The solutions: 1 Since CodeGenPrepare is already at the end of LLVM IR phase, we can simply delete the intrinsic call to llvm.assume. 2 A general solution to the complex control flow is hard, but for this case, after exit2 is duplicated into case1, exit2 is the only successor of exit1 and exit1 is the only predecessor of exit2, so they can be combined through eliminateFallThrough. But this function is called too late, there is no more dupRetToEnableTailCallOpts after it. We can add an earlier call to eliminateFallThrough to solve it. Differential Revision: https://reviews.llvm.org/D76539
Diffstat (limited to 'llvm/lib/CodeGen/CodeGenPrepare.cpp')
-rw-r--r--llvm/lib/CodeGen/CodeGenPrepare.cpp8
1 files changed, 8 insertions, 0 deletions
diff --git a/llvm/lib/CodeGen/CodeGenPrepare.cpp b/llvm/lib/CodeGen/CodeGenPrepare.cpp
index 1fd5154..4a416c3 100644
--- a/llvm/lib/CodeGen/CodeGenPrepare.cpp
+++ b/llvm/lib/CodeGen/CodeGenPrepare.cpp
@@ -495,6 +495,9 @@ bool CodeGenPrepare::runOnFunction(Function &F) {
if (!LargeOffsetGEPMap.empty())
MadeChange |= splitLargeGEPOffsets();
+ if (MadeChange)
+ eliminateFallThrough(F);
+
// Really free removed instructions during promotion.
for (Instruction *I : RemovedInsts)
I->deleteValue();
@@ -1964,6 +1967,11 @@ bool CodeGenPrepare::optimizeCallInst(CallInst *CI, bool &ModifiedDT) {
if (II) {
switch (II->getIntrinsicID()) {
default: break;
+ case Intrinsic::assume: {
+ II->eraseFromParent();
+ return true;
+ }
+
case Intrinsic::experimental_widenable_condition: {
// Give up on future widening oppurtunties so that we can fold away dead
// paths and merge blocks before going into block-local instruction