[llvm] 4d51c62 - [Inliner] Add return attributes to callsites not marked `willreturn`/`nounwind`
Noah Goldstein via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 16 20:41:47 PDT 2023
Author: Noah Goldstein
Date: 2023-08-16T22:43:04-05:00
New Revision: 4d51c6258e8391738e5c002b36de3b5538d31b8c
URL: https://github.com/llvm/llvm-project/commit/4d51c6258e8391738e5c002b36de3b5538d31b8c
DIFF: https://github.com/llvm/llvm-project/commit/4d51c6258e8391738e5c002b36de3b5538d31b8c.diff
LOG: [Inliner] Add return attributes to callsites not marked `willreturn`/`nounwind`
The actual callsite we are adding to doesn't need to be
`willreturn`/`nounwind`, only ever instructions between the callsite
and the return.
Reviewed By: nikic
Differential Revision: https://reviews.llvm.org/D156844
Added:
Modified:
llvm/lib/Transforms/Utils/InlineFunction.cpp
llvm/test/Transforms/Inline/nonnull.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Utils/InlineFunction.cpp b/llvm/lib/Transforms/Utils/InlineFunction.cpp
index 9b4c62a7a70c85..b70236c47415d2 100644
--- a/llvm/lib/Transforms/Utils/InlineFunction.cpp
+++ b/llvm/lib/Transforms/Utils/InlineFunction.cpp
@@ -1331,13 +1331,15 @@ static void AddAliasScopeMetadata(CallBase &CB, ValueToValueMapTy &VMap,
}
}
-static bool MayContainThrowingOrExitingCall(Instruction *Begin,
- Instruction *End) {
+static bool MayContainThrowingOrExitingCallAfterCB(CallBase *Begin,
+ ReturnInst *End) {
assert(Begin->getParent() == End->getParent() &&
"Expected to be in same basic block!");
+ auto BeginIt = Begin->getIterator();
+ assert(BeginIt != End->getIterator() && "Non-empty BB has empty iterator");
return !llvm::isGuaranteedToTransferExecutionToSuccessor(
- Begin->getIterator(), End->getIterator(), InlinerAttributeWindow + 1);
+ ++BeginIt, End->getIterator(), InlinerAttributeWindow + 1);
}
static AttrBuilder IdentifyValidAttributes(CallBase &CB) {
@@ -1393,7 +1395,7 @@ static void AddReturnAttributes(CallBase &CB, ValueToValueMapTy &VMap) {
// limit the check to both RetVal and RI are in the same basic block and
// there are no throwing/exiting instructions between these instructions.
if (RI->getParent() != RetVal->getParent() ||
- MayContainThrowingOrExitingCall(RetVal, RI))
+ MayContainThrowingOrExitingCallAfterCB(RetVal, RI))
continue;
// Add to the existing attributes of NewRetVal, i.e. the cloned call
// instruction.
diff --git a/llvm/test/Transforms/Inline/nonnull.ll b/llvm/test/Transforms/Inline/nonnull.ll
index faaf65bb60d0f6..9c0a225c57646b 100644
--- a/llvm/test/Transforms/Inline/nonnull.ll
+++ b/llvm/test/Transforms/Inline/nonnull.ll
@@ -159,7 +159,7 @@ define nonnull ptr @callee8() {
define ptr @caller8() {
; CHECK-LABEL: define ptr @caller8() {
-; CHECK-NEXT: [[R_I:%.*]] = call ptr @buz()
+; CHECK-NEXT: [[R_I:%.*]] = call nonnull ptr @buz()
; CHECK-NEXT: ret ptr [[R_I]]
;
%r = call nonnull ptr @callee8()
More information about the llvm-commits
mailing list