From 8df0ef85e304465d964011d74bb8c6f120681e0a Mon Sep 17 00:00:00 2001
From: Aaron Councilman <aaronjc4@illinois.edu>
Date: Tue, 19 Nov 2024 11:39:40 -0600
Subject: [PATCH] Fix: delete old phi nodes

---
 hercules_opt/src/sroa.rs | 3 +--
 juno_frontend/src/lib.rs | 7 +++----
 2 files changed, 4 insertions(+), 6 deletions(-)

diff --git a/hercules_opt/src/sroa.rs b/hercules_opt/src/sroa.rs
index ccc2605c..efa7bd90 100644
--- a/hercules_opt/src/sroa.rs
+++ b/hercules_opt/src/sroa.rs
@@ -342,6 +342,7 @@ pub fn sroa(editor: &mut FunctionEditor, reverse_postorder: &Vec<NodeID>, types:
                             },
                         );
                     });
+                    to_delete.push(node);
                 } else {
                     worklist.push_back(WorkItem::AllocatedPhi {
                         control,
@@ -426,8 +427,6 @@ pub fn sroa(editor: &mut FunctionEditor, reverse_postorder: &Vec<NodeID>, types:
 
     // Create new nodes nodes
     for (node_id, node) in to_insert {
-        assert!(node_id == editor.func().nodes.len());
-        println!("Inserting {:?} : {:?}", node_id, node);
         editor.edit(|mut edit| {
             let id = edit.add_node(node);
             assert!(node_id == id.idx());
diff --git a/juno_frontend/src/lib.rs b/juno_frontend/src/lib.rs
index e54e88fc..59240fe9 100644
--- a/juno_frontend/src/lib.rs
+++ b/juno_frontend/src/lib.rs
@@ -151,14 +151,13 @@ pub fn compile_ir(
     if x_dot {
         pm.add_pass(hercules_opt::pass::Pass::Xdot(true));
     }
-    add_pass!(pm, verify, SROA);
-    if x_dot {
-        pm.add_pass(hercules_opt::pass::Pass::Xdot(true));
-    }
     add_pass!(pm, verify, Inline);
     // Run SROA pretty early (though after inlining which can make SROA more effective) so that
     // CCP, GVN, etc. can work on the result of SROA
     add_pass!(pm, verify, SROA);
+    // We run phi-elim again because SROA can introduce new phis that might be able to be
+    // simplified
+    add_verified_pass!(pm, verify, PhiElim);
     if x_dot {
         pm.add_pass(hercules_opt::pass::Pass::Xdot(true));
     }
-- 
GitLab