[SROA] Maintain shadow/backing alloca when some slices are noncapturnig read-only...
authorRoman Lebedev <lebedev.ri@gmail.com>
Thu, 24 Feb 2022 12:24:36 +0000 (15:24 +0300)
committerRoman Lebedev <lebedev.ri@gmail.com>
Fri, 4 Mar 2022 18:08:43 +0000 (21:08 +0300)
commit703240c71fd640af7490069e8149d32d78d14da1
tree953c09db6635cefa951f7a97573335fbd17efbbd
parentf0891cd61b2f7cd57d906406ae785722bfd87603
[SROA] Maintain shadow/backing alloca when some slices are noncapturnig read-only calls to allow alloca partitioning/promotion

This is inspired by the original variant of D109749 by Graham Hunter,
but is a more general version.

Roughly, instead of promoting the alloca, we call it
a shadow/backing alloca, go through all it's slices,
clone(!) instructions that operated on it,
but make them operate on the cloned alloca,
and promote cloned alloca instead.

This keeps the shadow/backing alloca, and all the original instructions
around, which results in said shadow/backing alloca being
a perfect mirror/representation of the promoted alloca's content,
so calls that take the alloca as arguments (non-capturingly!)
can be supported.

For now, we require that the calls also don't modify the alloca's content,
but that is only to simplify the initial implementation,
and that will be supported in a follow-up.

Overall, this leads to *smaller* codesize:
https://llvm-compile-time-tracker.com/compare.php?from=a8b4f5bbab62091835205f3d648902432a4a5b58&to=aeae054055b125b011c1122f82c86457e159436f&stat=size-total
and is roughly neutral compile-time wise:
https://llvm-compile-time-tracker.com/compare.php?from=a8b4f5bbab62091835205f3d648902432a4a5b58&to=aeae054055b125b011c1122f82c86457e159436f&stat=instructions

Reviewed By: djtodoro

Differential Revision: https://reviews.llvm.org/D113520
llvm/lib/Transforms/Scalar/SROA.cpp
llvm/test/Transforms/SROA/non-capturing-call-readonly.ll