aboutsummaryrefslogtreecommitdiff
path: root/llvm/docs/LangRef.rst
diff options
context:
space:
mode:
authorNikita Popov <npopov@redhat.com>2023-12-14 09:58:14 +0100
committerGitHub <noreply@github.com>2023-12-14 09:58:14 +0100
commitbf5d96c96c40e485327e8ddf4fb8f0ddae859e6f (patch)
tree3d9afdee67410dd21b2ee871f1a95996367dca33 /llvm/docs/LangRef.rst
parenta2691e363232c011fdaace9fcc094f3cd210f78b (diff)
downloadllvm-bf5d96c96c40e485327e8ddf4fb8f0ddae859e6f.zip
llvm-bf5d96c96c40e485327e8ddf4fb8f0ddae859e6f.tar.gz
llvm-bf5d96c96c40e485327e8ddf4fb8f0ddae859e6f.tar.bz2
[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.
Diffstat (limited to 'llvm/docs/LangRef.rst')
-rw-r--r--llvm/docs/LangRef.rst14
1 files changed, 14 insertions, 0 deletions
diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst
index adda52b..cee8175 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -1576,6 +1576,20 @@ Currently, only the following parameter attributes are defined:
``readonly`` or a ``memory`` attribute that does not contain
``argmem: write``.
+``dead_on_unwind``
+ At a high level, this attribute indicates that the pointer argument is dead
+ if the call unwinds, in the sense that the caller will not depend on the
+ contents of the memory. Stores that would only be visible on the unwind
+ path can be elided.
+
+ More precisely, the behavior is as-if any memory written through the
+ pointer during the execution of the function is overwritten with a poison
+ value on unwind. This includes memory written by the implicit write implied
+ by the ``writable`` attribute. The caller is allowed to access the affected
+ memory, but all loads that are not preceded by a store will return poison.
+
+ This attribute cannot be applied to return values.
+
.. _gc:
Garbage Collector Strategy Names