aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/AliasAnalysis.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/Analysis/AliasAnalysis.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/Analysis/AliasAnalysis.cpp')
-rw-r--r--llvm/lib/Analysis/AliasAnalysis.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/llvm/lib/Analysis/AliasAnalysis.cpp b/llvm/lib/Analysis/AliasAnalysis.cpp
index b8a2218..da18279 100644
--- a/llvm/lib/Analysis/AliasAnalysis.cpp
+++ b/llvm/lib/Analysis/AliasAnalysis.cpp
@@ -896,7 +896,7 @@ bool llvm::isNotVisibleOnUnwind(const Value *Object,
// Byval goes out of scope on unwind.
if (auto *A = dyn_cast<Argument>(Object))
- return A->hasByValAttr();
+ return A->hasByValAttr() || A->hasAttribute(Attribute::DeadOnUnwind);
// A noalias return is not accessible from any other code. If the pointer
// does not escape prior to the unwind, then the caller cannot access the