[PATCH] D85614: [TRE] Reland: allow TRE for non-capturing calls.

Alexey Lapshin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Aug 9 09:57:53 PDT 2020


avl created this revision.
avl added reviewers: efriedma, jdoerfert, laytonio.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.
avl requested review of this revision.

The D82085 <https://reviews.llvm.org/D82085> "allow TRE for non-capturing calls" caused failure during bootstrap.
This patch does the same as D82085 <https://reviews.llvm.org/D82085> plus fixes bootstrap error.

The problem with D82085 <https://reviews.llvm.org/D82085> is that it leaves lifetime.end marker inplace,
while replacing function call with a branch. It is incorrect for
byValue parameter as this parameter could be used later now.
The fix is to delete lifetime.end marker for byValue parameter.

Consider following example:

int zoo ( S p1 );

int foo ( int count, S p1 ) {

  if ( count > 10 )
    return zoo(p1);
  
  // temporarily variable created for passing byvalue parameter
  // p1 could be used when zoo(p1) is called(after TRE is done).
  // lifetime.start p1.byvalue.temp
  return foo(count+1, p1);
  // lifetime.end p1.byvalue.temp

}

After recursive call to foo is replaced with a jump into
start of the function, its parameters could be passed to
zoo function. i.e. temporarily variable created for byvalue
parameter "p1" could be passed to zoo. Having lifetime.end marker
before jumping into start of the function destroys the value
of the temporarily variable. Finally zoo receives broken operand.

This patch passes bootstrap build and bootstrap build with AddressSanitizer.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D85614

Files:
  llvm/lib/Transforms/Scalar/TailRecursionElimination.cpp
  llvm/test/Transforms/TailCallElim/basic.ll
  llvm/test/Transforms/TailCallElim/tre-byval-parameter.ll
  llvm/test/Transforms/TailCallElim/tre-multiple-exits.ll
  llvm/test/Transforms/TailCallElim/tre-noncapturing-alloca-calls.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D85614.284217.patch
Type: text/x-patch
Size: 28168 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200809/1ceff7cf/attachment.bin>


More information about the llvm-commits mailing list