[all-commits] [llvm/llvm-project] 10c2e2: [TRE] Reland: allow TRE for non-capturing calls.

avl-llvm via All-commits all-commits at lists.llvm.org
Tue May 25 01:37:56 PDT 2021


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 10c2e261598a9c1b641b5adb10d87d937aba8b58
      https://github.com/llvm/llvm-project/commit/10c2e261598a9c1b641b5adb10d87d937aba8b58
  Author: Alexey Lapshin <a.v.lapshin at mail.ru>
  Date:   2021-05-25 (Tue, 25 May 2021)

  Changed paths:
    M llvm/lib/Transforms/Scalar/TailRecursionElimination.cpp
    M llvm/test/Transforms/TailCallElim/basic.ll
    A llvm/test/Transforms/TailCallElim/tre-byval-parameter-2.ll
    A llvm/test/Transforms/TailCallElim/tre-byval-parameter.ll
    A llvm/test/Transforms/TailCallElim/tre-multiple-exits.ll
    A llvm/test/Transforms/TailCallElim/tre-noncapturing-alloca-calls.ll

  Log Message:
  -----------
  [TRE] Reland: allow TRE for non-capturing calls.

The D82085 "allow TRE for non-capturing calls" caused failure during bootstrap.
This patch does the same as D82085 plus fixes bootstrap error.

The problem with D82085 is that it does not create copies for byval
operands, while replacing function call with a branch.

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. Finally zoo receives
broken operand:

```
    int foo ( int count, S p1 ) {
    :tailrecurse
      p1_tr = phi p1, p1.byvalue.temp
      if ( count > 10 )
        return zoo(p1_tr);

      // 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
      memcpy (p1.byvalue.temp, p1_tr)
      count = count + 1
      lifetime.end p1.byvalue.temp
      br tailrecurse
    }
```

To prevent using p1.byvalue.temp after its scope finished by
lifetime.end marker this patch copies value from p1.byvalue.temp
into another temporarily variable and then copies this variable
into the input parameter for next iteration.

This patch passes bootstrap build and bootstrap build with AddressSanitizer.

Differential Revision: https://reviews.llvm.org/D85614




More information about the All-commits mailing list