Skip to content
Snippets Groups Projects

Possible fix for reduce cycles

Merged rarbore2 requested to merge fix_reduce_cycles into main
2 files
+ 27
4
Compare changes
  • Side-by-side
  • Inline
Files
2
+ 15
2
@@ -233,14 +233,21 @@ fn loop_reachability_helper(
pub fn reduce_cycles(
function: &Function,
def_use: &ImmutableDefUseMap,
fork_join_map: &HashMap<NodeID, NodeID>,
fork_join_nest: &HashMap<NodeID, Vec<NodeID>>,
) -> HashMap<NodeID, HashSet<NodeID>> {
let reduces = (0..function.nodes.len())
.filter(|idx| function.nodes[*idx].is_reduce())
.map(NodeID::new);
let mut result = HashMap::new();
let join_fork_map: HashMap<NodeID, NodeID> = fork_join_map
.into_iter()
.map(|(fork, join)| (*join, *fork))
.collect();
for reduce in reduces {
let (_, _, reduct) = function.nodes[reduce.idx()].try_reduce().unwrap();
let (join, _, reduct) = function.nodes[reduce.idx()].try_reduce().unwrap();
let fork = join_fork_map[&join];
// First, find all data nodes that are used by the `reduct` input of the
// reduce, including the `reduct` itself.
@@ -249,7 +256,13 @@ pub fn reduce_cycles(
let mut worklist = vec![reduct];
while let Some(item) = worklist.pop() {
for u in get_uses(&function.nodes[item.idx()]).as_ref() {
if !function.nodes[u.idx()].is_control() && !use_reachable.contains(u) {
if !function.nodes[u.idx()].is_control()
&& !use_reachable.contains(u)
&& function.nodes[u.idx()]
.try_phi()
.map(|(control, _)| fork_join_nest[&fork].contains(&control))
.unwrap_or(true)
{
use_reachable.insert(*u);
worklist.push(*u);
}
Loading