diff --git a/hercules_opt/src/forkify.rs b/hercules_opt/src/forkify.rs index abd0aacad4233667ddc64ccc1dd9c0652c303bb3..f3ce186e030550dde12fb3f12fb5a386d67547e3 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)