aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
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/Bitcode/Reader/BitcodeReader.cpp
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/Bitcode/Reader/BitcodeReader.cpp')
-rw-r--r--llvm/lib/Bitcode/Reader/BitcodeReader.cpp2
1 files changed, 2 insertions, 0 deletions
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
index a11690a..8907f6f 100644
--- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -2098,6 +2098,8 @@ static Attribute::AttrKind getAttrFromCode(uint64_t Code) {
return Attribute::Writable;
case bitc::ATTR_KIND_CORO_ONLY_DESTROY_WHEN_COMPLETE:
return Attribute::CoroDestroyOnlyWhenComplete;
+ case bitc::ATTR_KIND_DEAD_ON_UNWIND:
+ return Attribute::DeadOnUnwind;
}
}