[llvm] 578ab33 - [Attributor][NFCI] Use a uniform necessary query to avoid a unique one

Johannes Doerfert via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 3 00:13:04 PDT 2023


Author: Johannes Doerfert
Date: 2023-08-03T00:12:45-07:00
New Revision: 578ab3312f20ee232503e106c9396509c332fe1e

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

LOG: [Attributor][NFCI] Use a uniform necessary query to avoid a unique one

If we cannot reach the target from the entry of a function without
exclusion set, we cannot reach it at all. This can allow us to filter
unique queries based on a uniform one.

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
index a6dab2810891f6..c8f05eae3b10db 100644
--- a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
+++ b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
@@ -10577,6 +10577,12 @@ struct AAInterFnReachabilityFunction
   bool isReachableImpl(Attributor &A, RQITy &RQI,
                        SmallPtrSet<const Function *, 16> *Visited) {
 
+    const Instruction *EntryI =
+        &RQI.From->getFunction()->getEntryBlock().front();
+    if (EntryI != RQI.From &&
+        !instructionCanReach(A, *EntryI, *RQI.To, nullptr, nullptr))
+      return rememberResult(A, RQITy::Reachable::No, RQI, false);
+
     SmallPtrSet<const Function *, 16> LocalVisited;
     if (!Visited)
       Visited = &LocalVisited;
@@ -10602,10 +10608,15 @@ struct AAInterFnReachabilityFunction
           return false;
         }
 
-        const AAInterFnReachability *InterFnReachability = this;
-        if (Fn != getAnchorScope())
-          InterFnReachability = A.getAAFor<AAInterFnReachability>(
-              *this, IRPosition::function(*Fn), DepClassTy::OPTIONAL);
+        if (Fn == getAnchorScope()) {
+          if (EntryI == RQI.From)
+            continue;
+          return false;
+        }
+
+        const AAInterFnReachability *InterFnReachability =
+            A.getAAFor<AAInterFnReachability>(*this, IRPosition::function(*Fn),
+                                              DepClassTy::OPTIONAL);
 
         const Instruction &FnFirstInst = Fn->getEntryBlock().front();
         if (!InterFnReachability ||


        


More information about the llvm-commits mailing list