[flang-commits] [flang] [llvm] [mlir] [Flang]Fix for changed code at the end of AllocaIP. (PR #92430)
Michael Kruse via flang-commits
flang-commits at lists.llvm.org
Tue May 21 03:06:50 PDT 2024
Meinersbur wrote:
> One possible reason is that for allocatable variables the privatization demands that we allocate only if the original variable is allocated. This introduces an `if` and hence multiple blocks.
I strongly recommend not doing it this way. An unconditional alloca in the entry block has no overhead (it just moves the stack pointer for the required space). Doing it conditionally does introduces overhead. Even worse, some LLVM passes treat allocas in the entry block specially (e.g. the inliner moves them to the caller's entry block to avoid having to dynamically readjust the stack pointer; mem2reg; SROA) and adding a branch will effectively pushes all allocas after the introduced branch into a non-entry block and thus worse optimization for them too.
See the discussions at https://discourse.llvm.org/t/alloca-outside-of-entry-block/11088/5, https://discourse.llvm.org/t/mem2reg-for-non-entry-blocks/26696/5
It would be better if the memory is allocated unconditionally, and just not used it if the variable not allocated.
https://github.com/llvm/llvm-project/pull/92430
More information about the flang-commits
mailing list