[all-commits] [llvm/llvm-project] 01859d: [AliasAnalysis] Introduce getModRefInfoMask() as a...

Patrick Walton via All-commits all-commits at lists.llvm.org
Mon Oct 31 13:04:17 PDT 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 01859da84bad95fd51d6a03b08b60c660e642a4f
      https://github.com/llvm/llvm-project/commit/01859da84bad95fd51d6a03b08b60c660e642a4f
  Author: Patrick Walton <pcwalton at fb.com>
  Date:   2022-10-31 (Mon, 31 Oct 2022)

  Changed paths:
    M llvm/docs/AliasAnalysis.rst
    M llvm/include/llvm/Analysis/AliasAnalysis.h
    M llvm/include/llvm/Analysis/BasicAliasAnalysis.h
    M llvm/include/llvm/Analysis/ObjCARCAliasAnalysis.h
    M llvm/include/llvm/Analysis/TypeBasedAliasAnalysis.h
    M llvm/lib/Analysis/AliasAnalysis.cpp
    M llvm/lib/Analysis/BasicAliasAnalysis.cpp
    M llvm/lib/Analysis/MemoryDependenceAnalysis.cpp
    M llvm/lib/Analysis/MemorySSA.cpp
    M llvm/lib/Analysis/ObjCARCAliasAnalysis.cpp
    M llvm/lib/Analysis/TypeBasedAliasAnalysis.cpp
    M llvm/lib/Target/AMDGPU/AMDGPUAliasAnalysis.cpp
    M llvm/lib/Target/AMDGPU/AMDGPUAliasAnalysis.h
    M llvm/lib/Transforms/IPO/FunctionAttrs.cpp
    M llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
    M llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
    M llvm/lib/Transforms/Scalar/LICM.cpp
    M llvm/lib/Transforms/Scalar/LoopPredication.cpp
    M llvm/test/Analysis/BasicAA/constant-memory.ll
    M llvm/test/Transforms/InstCombine/memcpy-from-global.ll
    M llvm/test/Transforms/InstCombine/store.ll

  Log Message:
  -----------
  [AliasAnalysis] Introduce getModRefInfoMask() as a generalization of pointsToConstantMemory().

The pointsToConstantMemory() method returns true only if the memory pointed to
by the memory location is globally invariant. However, the LLVM memory model
also has the semantic notion of *locally-invariant*: memory that is known to be
invariant for the life of the SSA value representing that pointer. The most
common example of this is a pointer argument that is marked readonly noalias,
which the Rust compiler frequently emits.

It'd be desirable for LLVM to treat locally-invariant memory the same way as
globally-invariant memory when it's safe to do so. This patch implements that,
by introducing the concept of a *ModRefInfo mask*. A ModRefInfo mask is a bound
on the Mod/Ref behavior of an instruction that writes to a memory location,
based on the knowledge that the memory is globally-constant memory (in which
case the mask is NoModRef) or locally-constant memory (in which case the mask
is Ref). ModRefInfo values for an instruction can be combined with the
ModRefInfo mask by simply using the & operator. Where appropriate, this patch
has modified uses of pointsToConstantMemory() to instead examine the mask.

The most notable optimization change I noticed with this patch is that now
redundant loads from readonly noalias pointers can be eliminated across calls,
even when the pointer is captured. Internally, before this patch,
AliasAnalysis was assigning Ref to reads from constant memory; now AA can
assign NoModRef, which is a tighter bound.

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




More information about the All-commits mailing list