[PATCH] D128104: [RPOFuncAttrs] Fix norecurse detection
Arthur Eubanks via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 17 16:02:04 PDT 2022
aeubanks created this revision.
aeubanks added reviewers: asbirlea, nikic.
Herald added subscribers: ormris, hiraditya.
Herald added a project: All.
aeubanks requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
We wanted to check if all uses of the function are direct calls, but the
code didn't account for passing the function as a parameter.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D128104
Files:
llvm/lib/Transforms/IPO/FunctionAttrs.cpp
llvm/test/Transforms/FunctionAttrs/norecurse.ll
Index: llvm/test/Transforms/FunctionAttrs/norecurse.ll
===================================================================
--- llvm/test/Transforms/FunctionAttrs/norecurse.ll
+++ llvm/test/Transforms/FunctionAttrs/norecurse.ll
@@ -99,7 +99,9 @@
}
; CHECK: Function Attrs
-; CHECK-SAME: norecurse nosync readnone
+; CHECK-NOT: norecurse
+; CHECK-SAME: nosync readnone
+; CHECK-NOT: norecurse
; CHECK-NEXT: define internal i32 @escapes_as_parameter
define internal i32 @escapes_as_parameter(ptr %p) {
%a = call i32 @k()
Index: llvm/lib/Transforms/IPO/FunctionAttrs.cpp
===================================================================
--- llvm/lib/Transforms/IPO/FunctionAttrs.cpp
+++ llvm/lib/Transforms/IPO/FunctionAttrs.cpp
@@ -2014,12 +2014,13 @@
// this function could be recursively (indirectly) called. Note that this
// also detects if F is directly recursive as F is not yet marked as
// a norecurse function.
- for (auto *U : F.users()) {
- auto *I = dyn_cast<Instruction>(U);
+ for (auto &U : F.uses()) {
+ auto *I = dyn_cast<Instruction>(U.getUser());
if (!I)
return false;
CallBase *CB = dyn_cast<CallBase>(I);
- if (!CB || !CB->getParent()->getParent()->doesNotRecurse())
+ if (!CB || !CB->isCallee(&U) ||
+ !CB->getParent()->getParent()->doesNotRecurse())
return false;
}
F.setDoesNotRecurse();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D128104.438057.patch
Type: text/x-patch
Size: 1379 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220617/bfdec517/attachment.bin>
More information about the llvm-commits
mailing list