[all-commits] [llvm/llvm-project] bf5d96: [IR] Add dead_on_unwind attribute (#74289)

Nikita Popov via All-commits all-commits at lists.llvm.org
Thu Dec 14 00:58:28 PST 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: bf5d96c96c40e485327e8ddf4fb8f0ddae859e6f
      https://github.com/llvm/llvm-project/commit/bf5d96c96c40e485327e8ddf4fb8f0ddae859e6f
  Author: Nikita Popov <npopov at redhat.com>
  Date:   2023-12-14 (Thu, 14 Dec 2023)

  Changed paths:
    M llvm/docs/LangRef.rst
    M llvm/include/llvm/Bitcode/LLVMBitCodes.h
    M llvm/include/llvm/IR/Attributes.td
    M llvm/lib/Analysis/AliasAnalysis.cpp
    M llvm/lib/Bitcode/Reader/BitcodeReader.cpp
    M llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
    M llvm/lib/IR/Attributes.cpp
    M llvm/lib/Transforms/Utils/CodeExtractor.cpp
    M llvm/test/Bitcode/attributes.ll
    M llvm/test/Transforms/DeadStoreElimination/simple.ll
    M llvm/test/Transforms/LICM/scalar-promote-unwind.ll
    M llvm/test/Transforms/MemCpyOpt/callslot_throw.ll
    A llvm/test/Verifier/dead-on-unwind.ll

  Log Message:
  -----------
  [IR] Add dead_on_unwind attribute (#74289)

Add the `dead_on_unwind` 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 dead_on_unwind %out) {
    store i32 0, ptr %out
    call void @may_unwind()
    store i32 1, ptr %out
    ret void
}

define void @tgt(ptr noalias dead_on_unwind %out) {
    call void @may_unwind()
    store i32 1, ptr %out
    ret void
}
```

The optimization is not valid without `dead_on_unwind`, 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), but based on the
feedback there it is better to keep these attributes orthogonal (sret is
an ABI attribute, dead_on_unwind is an optimization attribute). This is
a reboot of that change with a separate attribute.




More information about the All-commits mailing list