[PATCH] D157499: [IR] Add noreadafterunwind attribute

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 9 06:02:53 PDT 2023


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

Add the `noreadafterunwind` attribute, which states that the caller will not read from this argument if the call unwinds. This allows eliding stores that could otherwise be visible on the unwind path, for example:

  declare void @may_unwind()
  
  define void @src(ptr noalias noreadafterunwind %out) {
      store i32 0, ptr %out
      call void @may_unwind()
      store i32 1, ptr %out
      ret void
  }
  
  define void @tgt(ptr noalias noreadafterunwind %out) {
      call void @may_unwind()
      store i32 1, ptr %out
      ret void
  }

The optimization is not valid without `noreadafterunwind`, because the `i32 0` value might be read if `@may_unwind` unwinds.

This attribute is primarily intended to be used on `sret` arguments. In fact, I previously wanted to change the semantics of sret to include this "no read after unwind" property (see D116998 <https://reviews.llvm.org/D116998>), but based on the feedback there it is better to keep these attributes orthogonal (sret is an ABI attribute, noreadafterunwind is an optimization attribute). This is a reboot of that change with a separate attribute.


https://reviews.llvm.org/D157499

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/Transforms/Utils/CodeExtractor.cpp
  llvm/test/Transforms/DeadStoreElimination/simple.ll
  llvm/test/Transforms/LICM/scalar-promote-unwind.ll
  llvm/test/Transforms/MemCpyOpt/callslot_throw.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D157499.548586.patch
Type: text/x-patch
Size: 6962 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230809/5f1107cb/attachment.bin>


More information about the llvm-commits mailing list