[Coroutine] Allocas used by StoreInst does not always escape
authorXun Li <xun@fb.com>
Mon, 16 Nov 2020 17:14:44 +0000 (09:14 -0800)
committerXun Li <xun@fb.com>
Mon, 16 Nov 2020 17:14:44 +0000 (09:14 -0800)
commit985c524001d4dbaab17c2f59dac5f20f43695ae3
tree006f1fca87bb067c8daae846448f9c613d4430fc
parenta3be1287091463f4099cdb1710883645329cda7e
[Coroutine] Allocas used by StoreInst does not always escape

In the existing logic, for a given alloca, as long as its pointer value is stored into another location, it's considered as escaped.
This is a bit too conservative. Specifically, in non-optimized build mode, it's often to have patterns of code that first store an alloca somewhere and then load it right away.
These used should be handled without conservatively marking them escaped.

This patch tracks how the memory location where an alloca pointer is stored into is being used. As long as we only try to load from that location and nothing else, we can still
consider the original alloca not escaping and keep it on the stack instead of putting it on the frame.

Differential Revision: https://reviews.llvm.org/D91305
llvm/lib/Transforms/Coroutines/CoroFrame.cpp
llvm/test/Transforms/Coroutines/coro-alloca-06.ll [new file with mode: 0644]