[PATCH] D136659: [AliasAnalysis] Introduce getModRefMask() as a generalization of pointsToConstantMemory().

Patrick Walton via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 24 20:54:40 PDT 2022


pcwalton created this revision.
Herald added subscribers: jeroen.dobbelaere, ctetreau, ormris, asbirlea, george.burgess.iv, JDevlieghere, hiraditya, kristof.beyls.
Herald added a project: All.
pcwalton updated this revision to Diff 470365.
pcwalton added a comment.
pcwalton published this revision for review.
pcwalton added a reviewer: nikic.
Herald added subscribers: llvm-commits, pcwang-thead.
Herald added a project: LLVM.

Marking as non-draft.


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
InstCombine now deletes stores through readonly noalias pointer parameters.
Internally, before this patch, AliasAnalysis was assigning Ref to reads from
constant memory; now AA can assign NoModRef, which is a tighter bound.

The following test cases were incorrect before and have been fixed:

- Analysis/BasicAA/pr18573.ll: The test @foo1 in this file stored to a pointer

based on %arr.ptr, which was marked readonly. I removed the readonly attribute.

- Transforms/LoopVectorize/AArch64/sve-gather-scatter.ll (issue #58554): This

test @gather_nxv4i32_ind64_stride2 in this file stored through the readonly
pointer %a. I removed the readonly attribute.

- Transforms/LoopVectorize/interleaved-accesses.ll: The test @load_gap_reverse

in this file stored though multiple readonly pointers. I removed the readonly
attribute and fixed the C source equivalent in the comment to match what the
function actually does.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D136659

Files:
  llvm/docs/AliasAnalysis.rst
  llvm/include/llvm/Analysis/AliasAnalysis.h
  llvm/include/llvm/Analysis/BasicAliasAnalysis.h
  llvm/include/llvm/Analysis/TypeBasedAliasAnalysis.h
  llvm/lib/Analysis/AliasAnalysis.cpp
  llvm/lib/Analysis/BasicAliasAnalysis.cpp
  llvm/lib/Analysis/MemoryDependenceAnalysis.cpp
  llvm/lib/Analysis/MemorySSA.cpp
  llvm/lib/Analysis/TypeBasedAliasAnalysis.cpp
  llvm/lib/Transforms/IPO/FunctionAttrs.cpp
  llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
  llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
  llvm/lib/Transforms/Scalar/LICM.cpp
  llvm/lib/Transforms/Scalar/LoopPredication.cpp
  llvm/test/Analysis/BasicAA/constant-memory.ll
  llvm/test/Analysis/BasicAA/pr18573.ll
  llvm/test/Analysis/BasicAA/readonly-noalias.ll
  llvm/test/Transforms/InstCombine/store.ll
  llvm/test/Transforms/LoopVectorize/AArch64/sve-gather-scatter.ll
  llvm/test/Transforms/LoopVectorize/interleaved-accesses.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D136659.470365.patch
Type: text/x-patch
Size: 21439 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221025/4f9fc767/attachment.bin>


More information about the llvm-commits mailing list