[PATCH] D149563: [TRE] Do not mark alloca's as escaped if the function only writes to argmem

Joshua Cao via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue May 9 01:14:03 PDT 2023


caojoshua added a comment.

Stepping back, the purpose of the analysis is to determine which allocas 'escape'. If an alloca does not escape, we cannot mark a call as a tail call. The definition of escaped is not defined in the source. For the purpose of deciding which calls can be tail called, I would say an alloca is escaped if its address is accessible from outside of the function, i.e. a global. In this case, we would not be able to make a tail call, because the alloca would be lost when the caller's frame is overwritten.

In general, I think there is a lot of missed opportunities for tail calls in TRE. In this example:

  unsigned *foo(unsigned *n) { // define dso_local ptr @foo(ptr noundef returned writeonly %n) memory(argmem: write)
      *n = 12;
      return n;
  }
  
  void bar() {
      unsigned n; // lets say this is an alloca, and does not become a register
      foo(&n);
      could_be_tail_called();

`n` is captured when calling `foo()` because `n` is returned. Since `foo()` writes to memory, TRE marks n as escaped, and no functions can be marked as a tail call. Looking at the function, I don't see how the `n` alloca escapes, and it should not prevent any tail calls.

I think my current assumptions regarding function attributes in this patch are incorrect. I'll abandon this patch. If I revisit this idea, I'll back it up with data so I can make a stronger case.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149563/new/

https://reviews.llvm.org/D149563



More information about the llvm-commits mailing list