Support treeification of adjacent side-effecting ops in some cases.

This commit is contained in:
Chris Fallin 2024-05-07 15:22:18 -07:00 committed by Graham Kelly
parent 908ad937e1
commit c960d728bf

View file

@ -41,8 +41,10 @@ impl Trees {
let mut remat = HashSet::default(); let mut remat = HashSet::default();
let mut multi_use = HashSet::default(); let mut multi_use = HashSet::default();
for (value, def) in body.values.entries() { for block_def in body.blocks.values() {
match def { let mut last_non_pure = None;
for &value in &block_def.insts {
match &body.values[value] {
&ValueDef::Operator(op, args, _) => { &ValueDef::Operator(op, args, _) => {
// Ignore operators with invalid args: these must // Ignore operators with invalid args: these must
// always be unreachable. // always be unreachable.
@ -69,13 +71,17 @@ impl Trees {
} else if let Some(old_owner) = owner.remove(&arg) { } else if let Some(old_owner) = owner.remove(&arg) {
owned.remove(&old_owner); owned.remove(&old_owner);
multi_use.insert(arg); multi_use.insert(arg);
} else if Self::is_movable(body, arg) { } else if Self::is_movable(body, arg) || Some(arg) == last_non_pure {
let pos = u16::try_from(i).unwrap(); let pos = u16::try_from(i).unwrap();
let value_arg = ValueArg(value, pos); let value_arg = ValueArg(value, pos);
owner.insert(arg, value_arg); owner.insert(arg, value_arg);
owned.insert(value_arg, arg); owned.insert(value_arg, arg);
} }
} }
if !op.is_pure() {
last_non_pure = Some(value);
}
} }
&ValueDef::PickOutput(..) => { &ValueDef::PickOutput(..) => {
// Can ignore use: multi-arity values are never treeified. // Can ignore use: multi-arity values are never treeified.
@ -87,6 +93,7 @@ impl Trees {
| &ValueDef::None => {} | &ValueDef::None => {}
} }
} }
}
for block in body.blocks.values() { for block in body.blocks.values() {
block.terminator.visit_uses(|u| { block.terminator.visit_uses(|u| {
let u = body.resolve_alias(u); let u = body.resolve_alias(u);