From 6fed1b7d8a339b1d25d85f8c398a381bd9eff95d Mon Sep 17 00:00:00 2001 From: rarbore2 <rarbore2@illinois.edu> Date: Mon, 18 Nov 2024 18:23:16 -0600 Subject: [PATCH] Fix LCA calculation in dom tree --- hercules_ir/src/dom.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/hercules_ir/src/dom.rs b/hercules_ir/src/dom.rs index 9708e3b2..f9046b43 100644 --- a/hercules_ir/src/dom.rs +++ b/hercules_ir/src/dom.rs @@ -82,6 +82,9 @@ impl DomTree { * ancestor of the two nodes that is as far down the tree as possible. */ pub fn least_common_ancestor(&self, mut a: NodeID, mut b: NodeID) -> NodeID { + if a == self.root || b == self.root { + return self.root; + } while self.idom[&a].0 > self.idom[&b].0 { a = self.idom[&a].1; } -- GitLab