Skip to content

Commit

Permalink
Use "willreturn" in isGuaranteedToTransferExecutionToSuccessor
Browse files Browse the repository at this point in the history
The `willreturn` function attribute guarantees that a function call will
come back to the call site if the call is also known not to throw.
Therefore, this attribute can be used in
`isGuaranteedToTransferExecutionToSuccessor`.

Patch by Hideto Ueno (@uenoku)

Reviewers: jdoerfert, sstefan1

Reviewed By: jdoerfert

Subscribers: hiraditya, jfb, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D63372

llvm-svn: 364580
  • Loading branch information
Johannes Doerfert committed Jun 27, 2019
1 parent 1cf9e72 commit 6ed459f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
5 changes: 5 additions & 0 deletions llvm/lib/Analysis/ValueTracking.cpp
Expand Up @@ -4285,6 +4285,11 @@ bool llvm::isGuaranteedToTransferExecutionToSuccessor(const Instruction *I) {
if (!CS.doesNotThrow())
return false;

// A function which doens't throw and has "willreturn" attribute will
// always return.
if (CS.hasFnAttr(Attribute::WillReturn))
return true;

// Non-throwing call sites can loop infinitely, call exit/pthread_exit
// etc. and thus not return. However, LLVM already assumes that
//
Expand Down
3 changes: 3 additions & 0 deletions llvm/unittests/Analysis/ValueTrackingTest.cpp
Expand Up @@ -464,6 +464,7 @@ TEST(ValueTracking, GuaranteedToTransferExecutionToSuccessor) {
"declare void @nounwind_argmemonly(i32*) nounwind argmemonly "
"declare void @throws_but_readonly(i32*) readonly "
"declare void @throws_but_argmemonly(i32*) argmemonly "
"declare void @nounwind_willreturn(i32*) nounwind willreturn"
" "
"declare void @unknown(i32*) "
" "
Expand All @@ -476,6 +477,7 @@ TEST(ValueTracking, GuaranteedToTransferExecutionToSuccessor) {
" call void @unknown(i32* %p) nounwind argmemonly "
" call void @unknown(i32* %p) readonly "
" call void @unknown(i32* %p) argmemonly "
" call void @nounwind_willreturn(i32* %p)"
" ret void "
"} ";

Expand All @@ -497,6 +499,7 @@ TEST(ValueTracking, GuaranteedToTransferExecutionToSuccessor) {
true, // call void @unknown(i32* %p) nounwind argmemonly
false, // call void @unknown(i32* %p) readonly
false, // call void @unknown(i32* %p) argmemonly
true, // call void @nounwind_willreturn(i32* %p)
false, // ret void
};

Expand Down

0 comments on commit 6ed459f

Please sign in to comment.