From 8aabec77960f670699491ed1214bdb44b0c9ccf7 Mon Sep 17 00:00:00 2001 From: Xavier Routh <xrouth2@illinois.edu> Date: Thu, 30 Jan 2025 09:34:14 -0600 Subject: [PATCH] better phi reduce condition --- hercules_opt/src/forkify.rs | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/hercules_opt/src/forkify.rs b/hercules_opt/src/forkify.rs index abd0aaca..f3ce186e 100644 --- a/hercules_opt/src/forkify.rs +++ b/hercules_opt/src/forkify.rs @@ -477,10 +477,17 @@ pub fn analyze_phis<'a>( return false; }) .collect(); + + let continue_idx = editor + .get_uses(natural_loop.header) + .position(|node| natural_loop.control[node.idx()]) + .unwrap(); + + let loop_continue_latch = editor.node(phi).try_phi().unwrap().1[continue_idx]; // TODO: We may need to stop on exiting the loop for looking for data cycles. - let uses = walk_all_uses_stop_on(*phi, editor, stop_on.clone()); - let users = walk_all_users_stop_on(*phi, editor, stop_on.clone()); + let uses = walk_all_uses_stop_on(loop_continue_latch, editor, stop_on.clone()); + let users = walk_all_users_stop_on(loop_continue_latch, editor, stop_on.clone()); let other_stop_on: HashSet<NodeID> = editor .node_ids() @@ -509,8 +516,10 @@ pub fn analyze_phis<'a>( return false; }) .collect(); + + - let mut uses_for_dependance = walk_all_users_stop_on(*phi, editor, other_stop_on); + let mut uses_for_dependance = walk_all_users_stop_on(loop_continue_latch, editor, other_stop_on); let set1: HashSet<_> = HashSet::from_iter(uses); let set2: HashSet<_> = HashSet::from_iter(users); @@ -523,12 +532,7 @@ pub fn analyze_phis<'a>( LoopPHI::LoopDependant(*phi) } else if intersection.clone().iter().any(|node| true) { - let continue_idx = editor - .get_uses(natural_loop.header) - .position(|node| natural_loop.control[node.idx()]) - .unwrap(); - let loop_continue_latch = editor.node(phi).try_phi().unwrap().1[continue_idx]; // PHIs on the frontier of the uses by the candidate phi, i.e in uses_for_dependance need // to have headers that postdominate the loop continue latch. The value of the PHI used needs to be defined @@ -538,7 +542,8 @@ pub fn analyze_phis<'a>( // If some other node in the cycle is used, there is not a valid node to assign it after making the cycle a reduce. if intersection .iter() - .filter(|node| **node != loop_continue_latch) + .filter(|node| **node != loop_continue_latch ) + .filter(|node| !(editor.node(*node).is_reduce() || editor.node(*node).is_phi())) .any(|data_node| { editor .get_users(*data_node) -- GitLab