[all-commits] [llvm/llvm-project] 36bbd6: [InstCombine] Allow memcpys from constant memory t...

Patrick Walton via All-commits all-commits at lists.llvm.org
Sun Oct 30 14:41:40 PDT 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 36bbd68667dbe46626982d3a150891fb85bcc9a8
      https://github.com/llvm/llvm-project/commit/36bbd68667dbe46626982d3a150891fb85bcc9a8
  Author: Patrick Walton <pcwalton at fb.com>
  Date:   2022-10-30 (Sun, 30 Oct 2022)

  Changed paths:
    M llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
    M llvm/test/Transforms/InstCombine/memcpy-from-global.ll

  Log Message:
  -----------
  [InstCombine] Allow memcpys from constant memory to readonly nocapture parameters to be elided.

Currently, InstCombine can elide a memcpy from a constant to a local alloca if
that alloca is passed as a nocapture parameter to a *function* that's readnone
or readonly, but it can't forward the memcpy if the *argument* is marked
readonly nocapture, even though readonly guarantees that the callee won't
mutate the pointee through that pointer. This patch adds support for detecting
and handling such situations, which arise relatively frequently in Rust, a
frontend that liberally emits readonly.

A more general version of this optimization would use alias analysis to check
the call's ModRef info for the pointee, but I was concerned about blowing up
compile time, so for now I'm just checking for one of readnone on the function,
readonly on the function, or readonly on the parameter.

Differential Revision: https://reviews.llvm.org/D136822




More information about the All-commits mailing list