[PATCH] D116532: [LangRef] Add noreadonunwind attribute
Nikita Popov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 3 04:08:34 PST 2022
nikic created this revision.
nikic added reviewers: reames, jdoerfert, fhahn, asbirlea.
nikic requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
This introduces a `noreadonunwind` attribute, which is intended to allow additional optimizations in DSE and MemCpyOpt. The simplest example is:
declare void @may_unwind()
define void @test(i32* noalias noreadonunwind sret(i32) %out) {
store i32 0, i32* %out
call void @may_unwind()
store i32 1, i32* %out
ret void
}
Without the `noreadonunwind` attribute, we can not eliminate the first store, because the call might unwind, and the caller may observe the state after the first store.
The attribute is currently defined in a way that does not make a read after unwind immediate UB and just makes it return poison instead. I'm open to making it immediate UB though, I don't think there's a lot of practical difference either way.
Frontends will likely want to annotate `sret` parameters with `noreadonunwind`.
See https://lists.llvm.org/pipermail/llvm-dev/2021-December/154164.html for preliminary discussion on this.
https://reviews.llvm.org/D116532
Files:
llvm/docs/LangRef.rst
Index: llvm/docs/LangRef.rst
===================================================================
--- llvm/docs/LangRef.rst
+++ llvm/docs/LangRef.rst
@@ -1267,6 +1267,15 @@
This indicates that callee does not free the pointer argument. This is not
a valid attribute for return values.
+``noreadonunwind``
+ This indicates that the underlying object of a pointer argument is not read
+ on the unwind path in the following sense: If a call with ``noreadonunwind``
+ argument unwinds, then the underlying object associated with the pointer
+ argument is overwritten with a :ref:`poison value <poisonvalue>`. As such,
+ reads from this object do not result in immediate undefined behavior, but
+ program behavior cannot depend on the object containing any specific value.
+ This attribute cannot be applied to return values.
+
.. _nest:
``nest``
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D116532.397039.patch
Type: text/x-patch
Size: 878 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220103/d2c59637/attachment.bin>
More information about the llvm-commits
mailing list