[llvm] e4406ce - [RPOFuncAttrs] Fix norecurse detection

Arthur Eubanks via llvm-commits llvm-commits at lists.llvm.org
Sat Jun 18 12:20:20 PDT 2022


Author: Arthur Eubanks
Date: 2022-06-18T12:20:10-07:00
New Revision: e4406cefa053567d047d0e4ec20a70bbeade4d10

URL: https://github.com/llvm/llvm-project/commit/e4406cefa053567d047d0e4ec20a70bbeade4d10
DIFF: https://github.com/llvm/llvm-project/commit/e4406cefa053567d047d0e4ec20a70bbeade4d10.diff

LOG: [RPOFuncAttrs] Fix norecurse detection

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.

Reviewed By: nikic

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

Added: 
    

Modified: 
    llvm/lib/Transforms/IPO/FunctionAttrs.cpp
    llvm/test/Transforms/FunctionAttrs/norecurse.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/IPO/FunctionAttrs.cpp b/llvm/lib/Transforms/IPO/FunctionAttrs.cpp
index 360a37f112ea6..769cad60c06d5 100644
--- a/llvm/lib/Transforms/IPO/FunctionAttrs.cpp
+++ b/llvm/lib/Transforms/IPO/FunctionAttrs.cpp
@@ -2014,12 +2014,13 @@ static bool addNoRecurseAttrsTopDown(Function &F) {
   // 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();

diff  --git a/llvm/test/Transforms/FunctionAttrs/norecurse.ll b/llvm/test/Transforms/FunctionAttrs/norecurse.ll
index b1130b93d23d7..7baa7034aaa4b 100644
--- a/llvm/test/Transforms/FunctionAttrs/norecurse.ll
+++ b/llvm/test/Transforms/FunctionAttrs/norecurse.ll
@@ -99,7 +99,9 @@ define void @p() norecurse {
 }
 
 ; 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()


        


More information about the llvm-commits mailing list