[llvm] [CodeGen] Don't renumber invalid domtree (PR #102427)

Alexis Engelke via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 7 23:53:29 PDT 2024


https://github.com/aengelke created https://github.com/llvm/llvm-project/pull/102427

Machine block placement might remove nodes from the function but does not update the dominator tree accordingly. Instead of renumbering (which might crash due to accessing removed blocks), set the domtree to null to make clear that it is invalid at this point.

Fixup of #102107.

NB: this is only to fix compilations. Will address the TODO and add a test later.

>From b4f4a3e8ee6ba0f813a51febdbecef6162f5a341 Mon Sep 17 00:00:00 2001
From: Alexis Engelke <engelke at in.tum.de>
Date: Thu, 8 Aug 2024 06:48:10 +0000
Subject: [PATCH] [CodeGen] Don't renumber invalid domtree

Machine block placement might remove nodes from the function but does
not update the dominator tree accordingly. Instead of renumbering (which
might crash due to accessing removed blocks), set the domtree to null to
make clear that it is invalid at this point.

Fixup of #102107.
---
 llvm/lib/CodeGen/MachineBlockPlacement.cpp | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/llvm/lib/CodeGen/MachineBlockPlacement.cpp b/llvm/lib/CodeGen/MachineBlockPlacement.cpp
index 9010c3cfc4247..be783bc4e2973 100644
--- a/llvm/lib/CodeGen/MachineBlockPlacement.cpp
+++ b/llvm/lib/CodeGen/MachineBlockPlacement.cpp
@@ -3649,7 +3649,11 @@ void MachineBlockPlacement::assignBlockOrder(
     const std::vector<const MachineBasicBlock *> &NewBlockOrder) {
   assert(F->size() == NewBlockOrder.size() && "Incorrect size of block order");
   F->RenumberBlocks();
-  MPDT->updateBlockNumbers();
+  // At this point, we possibly removed blocks from the function, so we can't
+  // renumber the domtree. At this point, we don't need it anymore, though.
+  // TODO: move this to the point where the dominator tree is actually
+  // invalidated (i.e., where blocks are removed without updating the domtree).
+  MPDT = nullptr;
 
   bool HasChanges = false;
   for (size_t I = 0; I < NewBlockOrder.size(); I++) {



More information about the llvm-commits mailing list