[PATCH] D158081: [IR] Add writable attribute

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 16 06:58:47 PDT 2023


nikic created this revision.
nikic added reviewers: efriedma, jdoerfert, fhahn, aeubanks.
Herald added subscribers: jeroen.dobbelaere, StephenFan, asbirlea, JDevlieghere, hiraditya.
Herald added a project: All.
nikic requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

This adds a `writable` attribute, which states that any location based on the pointer that is readable is also writable. An implication of this is that if the pointer is `dereferenceable(N)`, then it's also writable up to N bytes.

However, just allowing writes without trapping is not enough to introduce spurious stores: We also have to consider data races. For that reason the `writable` attribute is specified to perform a spurious store of `dereferenceable` bytes on function entry. This makes sure that at least on function entry, additional spurious stores can be introduced.

While all being separate attributes, it's the combination of `noalias` + `writable` + `dereferenceable(N)` that is most useful in practice. This attribute can be added to `sret` arguments. I believe Rust will also be able to use it for by-value (moved) arguments. Rust likely won't be able to use it for `&mut` arguments (tree borrows does not appear to allow spurious stores).

In this patch the new attribute is only used by LICM scalar promotion. However, the actual motivation for this is to fix a correctness issue in call slot optimization, which needs this attribute to avoid optimization regressions.

Followup to the discussion on D157499 <https://reviews.llvm.org/D157499>.


https://reviews.llvm.org/D158081

Files:
  llvm/docs/LangRef.rst
  llvm/include/llvm/Bitcode/LLVMBitCodes.h
  llvm/include/llvm/IR/Attributes.td
  llvm/lib/Analysis/AliasAnalysis.cpp
  llvm/lib/Bitcode/Reader/BitcodeReader.cpp
  llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
  llvm/lib/IR/Attributes.cpp
  llvm/lib/Transforms/Utils/CodeExtractor.cpp
  llvm/test/Bitcode/attributes.ll
  llvm/test/Transforms/LICM/scalar-promote.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D158081.550730.patch
Type: text/x-patch
Size: 6010 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230816/67493f41/attachment.bin>


More information about the llvm-commits mailing list