[llvm] 4c9e31a - [funcattrs] Use early return to clarify code in determinePointerAccessAttrs [NFC]

Philip Reames via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 17 10:00:45 PST 2021


Author: Philip Reames
Date: 2021-12-17T10:00:36-08:00
New Revision: 4c9e31a4814592bbda7153833e46728dc7b21100

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

LOG: [funcattrs] Use early return to clarify code in determinePointerAccessAttrs [NFC]

Instead of having the speculative path be the untaken path in the branch, explicitly have it return.  This does require tail duplicating one call, but the resulting code is shorter and easier to understand.  Also rewrite the condition using appropriate accessors.

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/IPO/FunctionAttrs.cpp b/llvm/lib/Transforms/IPO/FunctionAttrs.cpp
index 3ef38f0c108d..17c2b823b035 100644
--- a/llvm/lib/Transforms/IPO/FunctionAttrs.cpp
+++ b/llvm/lib/Transforms/IPO/FunctionAttrs.cpp
@@ -726,22 +726,20 @@ determinePointerAccessAttrs(Argument *A,
 
       Captures &= !CB.doesNotCapture(UseIndex);
 
-      // Since the optimizer (by design) cannot see the data flow corresponding
-      // to a operand bundle use, these cannot participate in the optimistic SCC
-      // analysis.  Instead, we model the operand bundle uses as arguments in
-      // call to a function external to the SCC.
-      if (IsOperandBundleUse ||
-          !SCCNodes.count(&*std::next(F->arg_begin(), UseIndex))) {
-
-        // The accessors used on call site here do the right thing for calls and
-        // invokes with operand bundles.
-
-        if (!CB.onlyReadsMemory() && !CB.onlyReadsMemory(UseIndex))
-          return Attribute::None;
-        if (!CB.doesNotAccessMemory(UseIndex))
-          IsRead = true;
+      if (CB.isArgOperand(U) && SCCNodes.count(F->getArg(UseIndex))) {
+        // This is an argument which is part of the speculative SCC.  Note that
+        // only operands corresponding to formal arguments of the callee can
+        // participate in the speculation.
+        AddUsersToWorklistIfCapturing();
+        break;
       }
 
+      // The accessors used on call site here do the right thing for calls and
+      // invokes with operand bundles.
+      if (!CB.onlyReadsMemory() && !CB.onlyReadsMemory(UseIndex))
+        return Attribute::None;
+      if (!CB.doesNotAccessMemory(UseIndex))
+        IsRead = true;
       AddUsersToWorklistIfCapturing();
       break;
     }


        


More information about the llvm-commits mailing list