[llvm] r260666 - [attrs] Consolidate the test for a non-SCC, non-convergent function call

Chandler Carruth via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 12 01:23:54 PST 2016


Author: chandlerc
Date: Fri Feb 12 03:23:53 2016
New Revision: 260666

URL: http://llvm.org/viewvc/llvm-project?rev=260666&view=rev
Log:
[attrs] Consolidate the test for a non-SCC, non-convergent function call
with the test for a non-convergent intrinsic call.

While it is possible to use the call records to search for function
calls, we're going to do an instruction scan anyways to find the
intrinsics, we can handle both cases while scanning instructions. This
will also make the logic more amenable to the new pass manager which
doesn't use the same call graph structure.

My next patch will remove use of CallGraphNode entirely and allow this
code to work with both the old and new pass manager. Fortunately, it
should also get strictly simpler without changing functionality.

Modified:
    llvm/trunk/lib/Transforms/IPO/FunctionAttrs.cpp

Modified: llvm/trunk/lib/Transforms/IPO/FunctionAttrs.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/FunctionAttrs.cpp?rev=260666&r1=260665&r2=260666&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/FunctionAttrs.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/FunctionAttrs.cpp Fri Feb 12 03:23:53 2016
@@ -959,27 +959,21 @@ static bool removeConvergentAttrs(const
     if (F->hasFnAttribute(Attribute::OptimizeNone))
       return false;
 
-    // Can't remove convergent if any of F's callees -- ignoring functions in
-    // the SCC itself -- are convergent.
-    if (llvm::any_of(*CGN, [&](const CallGraphNode::CallRecord &CR) {
-          Function *F = CR.second->getFunction();
-          return SCCNodes.count(F) == 0 && (!F || F->isConvergent());
-        }))
-      return false;
+    for (Instruction &I : instructions(*F))
+      if (auto CS = CallSite(&I)) {
+        // Can't remove convergent if any of F's callees -- ignoring functions
+        // in the SCC itself -- are convergent. This needs to consider both
+        // function calls and intrinsic calls. We also assume indirect calls
+        // might call a convergent function.
+        // FIXME: We should revisit this when we put convergent onto calls
+        // instead of functions so that indirect calls which should be
+        // convergent are required to be marked as such.
+        Function *Callee = CS.getCalledFunction();
+        if (!Callee || (SCCNodes.count(Callee) == 0 && Callee->isConvergent()))
+          return false;
+      }
 
-    // CGN doesn't contain calls to intrinsics, so iterate over all of F's
-    // callsites, looking for any calls to convergent intrinsics.  If we find
-    // one, F must remain marked as convergent.
-    auto IsConvergentIntrinsicCall = [](Instruction &I) {
-      CallSite CS(cast<Value>(&I));
-      if (!CS)
-        return false;
-      Function *Callee = CS.getCalledFunction();
-      return Callee && Callee->isIntrinsic() && Callee->isConvergent();
-    };
-    return !llvm::any_of(*F, [=](BasicBlock &BB) {
-      return llvm::any_of(BB, IsConvergentIntrinsicCall);
-    });
+    return true;
   };
 
   // We can remove the convergent attr from functions in the SCC if they all




More information about the llvm-commits mailing list