[all-commits] [llvm/llvm-project] 5e247d: [SROA] Optimize reloaded values in allocas that es...

David Green via All-commits all-commits at lists.llvm.org
Thu Dec 12 02:27:50 PST 2024


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 5e247d726d7a54cf0acc997bc17b50e7494e6fa3
      https://github.com/llvm/llvm-project/commit/5e247d726d7a54cf0acc997bc17b50e7494e6fa3
  Author: David Green <david.green at arm.com>
  Date:   2024-12-12 (Thu, 12 Dec 2024)

  Changed paths:
    M llvm/include/llvm/Analysis/PtrUseVisitor.h
    M llvm/include/llvm/Transforms/Utils/SSAUpdater.h
    M llvm/lib/Transforms/Scalar/SROA.cpp
    M llvm/lib/Transforms/Utils/SSAUpdater.cpp
    M llvm/test/Transforms/SROA/non-capturing-call-readonly.ll
    M llvm/test/Transforms/SROA/readonlynocapture.ll

  Log Message:
  -----------
  [SROA] Optimize reloaded values in allocas that escape into readonly nocapture calls. (#116645)

Given an alloca that potentially has many uses in big complex code and
escapes into a call that is readonly+nocapture, we cannot easily split
up the alloca. There are several optimizations that will attempt to take
a value that is stored and a reload, and replace the load with the
original stored value. Instcombine has some simple heuristics, GVN can
sometimes do it, as can CSE in limited situations. They all suffer from
the same issue with complex code - they start from a load/store and need
to prove no-alias for all code between, which in complex cases might be
a lot to look through. Especially if the ptr is an alloca with many uses
that is over the normal escape capture limits.

The pass that does do well with allocas is SROA, as it has a complete
view of all of the uses. This patch adds a case to SROA where it can
detect allocas that are passed into calls that are no-capture readonly.
It can then optimize the reloaded values inside the alloca slice with
the stored value knowing that it is valid no matter the location of the
loads/stores from the no-escaping nature of the alloca.



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list