[llvm] [SandboxVectorizer] Implement topdown/bottomup vectorizers in unison (PR #205249)

Anshil Gandhi via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 29 13:01:58 PDT 2026


================
@@ -288,6 +288,55 @@ Action *BottomUpVec::vectorizeRec(ArrayRef<Value *> Bndl,
   const auto &LegalityRes = StopForDebug ? Legality.getForcedPackForDebugging()
                                          : Legality.canVectorize(Bndl);
   LLVM_DEBUG(dbgs() << DEBUG_PREFIX << "Legality: " << LegalityRes << "\n");
+
+  if (Direction == VecDirection::TopDown) {
+    auto ActionPtr = std::make_unique<Action>(&LegalityRes, Bndl,
+                                              ArrayRef<Value *>(), Depth);
+
+    if (LegalityRes.getSubclassID() == LegalityResultID::Widen)
+      IMaps->registerVector(Bndl, ActionPtr.get());
+
+    // Pre-order push so defs are before uses.
+    Action *Action = ActionPtr.get();
+    Actions.push_back(std::move(ActionPtr));
+
+    if (LegalityRes.getSubclassID() == LegalityResultID::Widen) {
+      // Find users of Bndl to recurse down.
+      // Group the first user of each element if they match.
+      SmallVector<Value *, 4> NextUserBndl;
+      bool CanFormUserBndl = true;
+      for (Value *V : Bndl) {
+        if (V->user_begin() == V->user_end()) {
+          CanFormUserBndl = false;
+          break;
+        }
+        NextUserBndl.push_back(*V->user_begin());
+      }
+
+      if (CanFormUserBndl) {
+        auto *U0 = dyn_cast<Instruction>(NextUserBndl[0]);
+        if (!U0 || IMaps->isVectorized(U0))
+          CanFormUserBndl = false;
+        else {
+          for (Value *U : drop_begin(NextUserBndl)) {
+            auto *UI = dyn_cast<Instruction>(U);
+            if (!UI || UI->getOpcode() != U0->getOpcode() ||
+                UI->getType() != U0->getType() || IMaps->isVectorized(UI)) {
+              CanFormUserBndl = false;
+              break;
+            }
+          }
+        }
+      }
+
+      if (CanFormUserBndl)
+        vectorizeRec(NextUserBndl, {}, Depth + 1, Legality);
----------------
gandhi56 wrote:

Yes but I don't use `Bndl` at all during topdown vectorization.

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


More information about the llvm-commits mailing list