aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/IR
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/lib/IR
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/lib/IR')
-rw-r--r--llvm/lib/IR/Attributes.cpp3
1 files changed, 2 insertions, 1 deletions
diff --git a/llvm/lib/IR/Attributes.cpp b/llvm/lib/IR/Attributes.cpp
index 10a74ed6..fd51602 100644
--- a/llvm/lib/IR/Attributes.cpp
+++ b/llvm/lib/IR/Attributes.cpp
@@ -1962,7 +1962,8 @@ AttributeMask AttributeFuncs::typeIncompatible(Type *Ty,
.addAttribute(Attribute::ReadOnly)
.addAttribute(Attribute::Dereferenceable)
.addAttribute(Attribute::DereferenceableOrNull)
- .addAttribute(Attribute::Writable);
+ .addAttribute(Attribute::Writable)
+ .addAttribute(Attribute::DeadOnUnwind);
if (ASK & ASK_UNSAFE_TO_DROP)
Incompatible.addAttribute(Attribute::Nest)
.addAttribute(Attribute::SwiftError)