Use "willreturn" in isGuaranteedToTransferExecutionToSuccessor

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@364580 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Johannes Doerfert 2019-06-27 19:29:48 +00:00
parent 27daa20eac
commit 775fc9548c
2 changed files with 8 additions and 0 deletions

View File

@ -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
//

View File

@ -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*) "
" "
@ -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 "
"} ";
@ -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
};