Skip to content
Snippets Groups Projects
Commit 8aabec77 authored by Xavier Routh's avatar Xavier Routh
Browse files

better phi reduce condition

parent b2d0899d
No related branches found
No related tags found
1 merge request!103Forkify + Loop Canonicalization + Initial Fork Fission
Pipeline #201246 passed
...@@ -477,10 +477,17 @@ pub fn analyze_phis<'a>( ...@@ -477,10 +477,17 @@ pub fn analyze_phis<'a>(
return false; return false;
}) })
.collect(); .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. // 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 uses = walk_all_uses_stop_on(loop_continue_latch, editor, stop_on.clone());
let users = walk_all_users_stop_on(*phi, 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 let other_stop_on: HashSet<NodeID> = editor
.node_ids() .node_ids()
...@@ -509,8 +516,10 @@ pub fn analyze_phis<'a>( ...@@ -509,8 +516,10 @@ pub fn analyze_phis<'a>(
return false; return false;
}) })
.collect(); .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 set1: HashSet<_> = HashSet::from_iter(uses);
let set2: HashSet<_> = HashSet::from_iter(users); let set2: HashSet<_> = HashSet::from_iter(users);
...@@ -523,12 +532,7 @@ pub fn analyze_phis<'a>( ...@@ -523,12 +532,7 @@ pub fn analyze_phis<'a>(
LoopPHI::LoopDependant(*phi) LoopPHI::LoopDependant(*phi)
} }
else if intersection.clone().iter().any(|node| true) { 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 // 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 // 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>( ...@@ -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 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 if intersection
.iter() .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| { .any(|data_node| {
editor editor
.get_users(*data_node) .get_users(*data_node)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment