<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/123800>123800</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Bug in LDS lowering, F.hasAddressTaken() under-estimates escape analysis
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
            ergawy,
            JonChesterfield
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          JonChesterfield
      </td>
    </tr>
</table>

<pre>
    Reported by @ergawy as O0 reaching a trap. Reproducer is somewhat lengthy (mostly openmp runtime code, from O0).

AMDGPUMemoryUtils::getTransitiveUsesOfLDS builds a set of LDS variables that are used by (non-kernel) functions that have their address taken. Kernels that call an unknown function then allocate all those variables.

The bug here goes:
```
1. kernel __omp_offloading_fc00_5e49a7c_main_l13
2. stashes a pointer to function __omp_offloading_fc00_5e49a7c_main_l13_omp_outlined_wrapper (and later calls it, indirectly)
3. __omp_offloading_fc00_5e49a7c_main_l13_omp_outlined_wrapper directly calls function __kmpc_get_shared_variables
4. __kmpc_get_shared_variables uses LDS global ZL32SharedMemVariableSharingSpacePtr
```

Since the function accessing the LDS variable doesn't have it's address taken, the variable doesn't get added to the set of problematic variables. However that function is called by some other function whose address is taken, so it needed to be.

Instead of hasAddressTaken, this needs to be a (basic) escape analysis test. Transitive instead of only checking the immediate user. Crawling CallGraph marking functions would work but hopefully there's a cleaner fix.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJykVEGP2zYT_TX0ZbACTdlr-6CDsoHzfW2CBNmkh16METmWWFOkwKHs-t8XlJX1dlsUBQoYsEC-GT6-94bIbFtPVIn1O6EUxRYvV6GUUE9CqZ-Cf-qIE8WjJWfy-vr9AsfUhVi92Vw0wVyrrzSEmMhAcwWxkrd-gAyfJURC3VnfAkKKOBTwlYYYzKgpgmXg0NOlwwSOfJu6Kwi17QMnd4UwkO8HiKN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