[PATCH] D88893: [SROA] Only generate memcpy if the slices is large 'enough' (WIP).

Florian Hahn via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 6 06:11:30 PDT 2020


fhahn created this revision.
fhahn added reviewers: efriedma, Carrot, arsenm, lebedev.ri.
Herald added subscribers: dexonsmith, hiraditya, kristof.beyls.
Herald added a project: LLVM.
fhahn requested review of this revision.
Herald added a subscriber: wdng.

Currently SROA liberally creates llvm.memcpy calls when dealing with
small slices of allocas. Unfortunately there are multiple places in LLVM
that do not work too well with llvm.memcpy.

This can lead to surprising code gen, e.g. see PR47705 and PR47709 (LICM
does not hoist invariant llvm.memcyp calls).

We can side-step this issue in some cases, by letting SROA emit
loads/stores instead of memcpy if the slice is small and we can
reasonably expect vector versions of those loads and stores can be used.

The chosen threshold of 2 x widest vector register is somewhat
arbitrary, but should ensure that we can be reasonably confident that
those loads & stores will be lowered relatively efficiently.

The patch as is is not ideal, because it potentially results in a large
number of insert/extractvalue instructions to move the loaded/stored
values to and from the slice. We could (and maybe should) try to
directly emit the correct vector loads/stores.

At this stage I am mainly interested to see if there's a reason for not
doing so already. It might not be desirable to bake in too much
target-specific knowledge into something as general as SROA. I'll update
the tests if we settle on the final approach

This potentially provides some nice performance benefits, e.g. on ARM64
with -O3 -flto, 450.soplex runs roughly 2.2% faster and generates to
expected assembly for PR47705.

We should also work on improving the handling of llvm.memcpy in
different passes, but that might be tricky in some cases. For example,
it might be desirable to de-compose llvm.memcpy in separate load/store
parts if this would lead to the load part being loop-invariant.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D88893

Files:
  llvm/include/llvm/Transforms/Scalar/SROA.h
  llvm/lib/Transforms/Scalar/SROA.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D88893.296431.patch
Type: text/x-patch
Size: 4075 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201006/2dbed8e5/attachment.bin>


More information about the llvm-commits mailing list