[PATCH] D156844: [Inliner] Add return attributes to callsites not marked `willreturn`
Noah Goldstein via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 1 18:45:42 PDT 2023
goldstein.w.n created this revision.
goldstein.w.n added reviewers: nikic, fhahn, efriedma.
Herald added subscribers: StephenFan, hiraditya.
Herald added a project: All.
goldstein.w.n requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
The actual callsite we are adding to doesn't need to be `willreturn`,
only ever instructions between the callsite and the return.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D156844
Files:
llvm/lib/Transforms/Utils/InlineFunction.cpp
llvm/test/Transforms/Inline/nonnull.ll
Index: llvm/test/Transforms/Inline/nonnull.ll
===================================================================
--- llvm/test/Transforms/Inline/nonnull.ll
+++ llvm/test/Transforms/Inline/nonnull.ll
@@ -160,7 +160,7 @@
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()
Index: llvm/lib/Transforms/Utils/InlineFunction.cpp
===================================================================
--- llvm/lib/Transforms/Utils/InlineFunction.cpp
+++ llvm/lib/Transforms/Utils/InlineFunction.cpp
@@ -1331,13 +1331,16 @@
}
}
-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();
+ if (BeginIt == End->getIterator())
+ return true;
return !llvm::isGuaranteedToTransferExecutionToSuccessor(
- Begin->getIterator(), End->getIterator(), InlinerAttributeWindow + 1);
+ ++BeginIt, End->getIterator(), InlinerAttributeWindow + 1);
}
static AttrBuilder IdentifyValidAttributes(CallBase &CB) {
@@ -1399,7 +1402,8 @@
// 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) ||
+ RetVal->mayThrow())
continue;
// Add to the existing attributes of NewRetVal, i.e. the cloned call
// instruction.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D156844.546290.patch
Type: text/x-patch
Size: 1945 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230802/c05f3187/attachment.bin>
More information about the llvm-commits
mailing list