[PATCH] D76539: [CodeGenPrepare] Delete intrinsic call to llvm.assume to enable more tailcall

Guozhi Wei via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Mar 21 01:34:11 PDT 2020


Carrot created this revision.
Carrot added reviewers: arsenm, xbolva00.
Herald added subscribers: llvm-commits, hiraditya, wdng.
Herald added a project: LLVM.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D76539

Files:
  llvm/lib/CodeGen/CodeGenPrepare.cpp
  llvm/test/CodeGen/X86/tailcall-assume-xbb.ll
  llvm/test/Transforms/CodeGenPrepare/X86/extend-sink-hoist.ll
  llvm/test/Transforms/CodeGenPrepare/X86/optimizeSelect-DT.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D76539.251827.patch
Type: text/x-patch
Size: 3563 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200321/0e898b59/attachment.bin>


More information about the llvm-commits mailing list