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

David Green via All-commits all-commits at lists.llvm.org
Sat Dec 14 10:07:44 PST 2024


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 0032c151dcbdbf9cdd8982870c7611e6f08c504b
      https://github.com/llvm/llvm-project/commit/0032c151dcbdbf9cdd8982870c7611e6f08c504b
  Author: David Green <david.green at arm.com>
  Date:   2024-12-14 (Sat, 14 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