[llvm] [FuncSpec] Update function specialization to handle phi-chains (PR #72903)

Alexandros Lamprineas via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 21 03:53:17 PST 2023


================
@@ -262,29 +269,113 @@ Cost InstCostVisitor::estimateBranchInst(BranchInst &I) {
   return estimateBasicBlocks(WorkList);
 }
 
+bool InstCostVisitor::discoverTransitivelyIncomingValues(
+    Constant *Const, PHINode *Root, DenseSet<PHINode *> &TransitivePHIs,
+    SmallVectorImpl<PHINode *> &UnknownIncomingValues) {
+
+  SmallVector<PHINode *, 64> WorkList;
+  WorkList.push_back(Root);
+  unsigned Iter = 0;
+
+  while (!WorkList.empty()) {
+    PHINode *PN = WorkList.pop_back_val();
+
+    if (++Iter > MaxDiscoveryIterations ||
+        PN->getNumIncomingValues() > MaxIncomingPhiValues) {
+      // For now just collect the Phi and later we will check whether it is
+      // in the Transitive set.
+      UnknownIncomingValues.push_back(PN);
+      continue;
+      // FIXME: return false here and remove the UnknownIncomingValues entirely.
----------------
labrinea wrote:

This will require the regresson test to be adjusted for the NOFUNCSPEC check prefix. Last time I checked it would require another 55 discovery steps or so. But that's fine because we will be removing the following loop from visitPHI, which iterates over these 55 UnknownIncomingValues.
```
for (PHINode *Phi : UnknownIncomingValues)
    if (!TransitivePHIs.contains(Phi))
      return nullptr;
```

https://github.com/llvm/llvm-project/pull/72903


More information about the llvm-commits mailing list