[PATCH] D153453: [MemCpyOpt] implement single BB stack-move optimization which unify the static unescaped allocas

Kohei Asano via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 15 04:10:43 PDT 2023


khei4 added a comment.

@nikic Thanks! I was wondering `readonly` call isn't MemoryUse(Currently, not that can probably be patched);)

  %src = alloca %struct.Foo, align 4
  %dest = alloca %struct.Foo, align 4
  store %struct.Foo { i32 10, i32 20, i32 30 }, ptr %src
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %dest, ptr align 4 %src, i64 12, i1 false)
  %_v = call i32 @use_readonly(ptr nocapture readonly %dest)
  %_v2 = call i32 @use_readonly(ptr nocapture readonly %src)
  ret void

I'll add a test for this case and rebase it!



================
Comment at: llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp:1626
+      auto *LastMA = MSSA->getMemoryAccess(LastUser);
+      auto *EndMA = MSSAU->createMemoryAccessAfter(End, LastMA, LastMA);
+      MSSAU->insertDef(cast<MemoryDef>(EndMA), /*RenameUses=*/true);
----------------
So, replace the second argument with LastMA->getDefiningAccess() works. It seems like getDefiningAccess is idempotent for MemoryDef.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153453/new/

https://reviews.llvm.org/D153453



More information about the llvm-commits mailing list