spirt_passes/reduce: fix long-standing bug involving chained replacements.

This commit is contained in:
Eduard-Mihai Burtescu 2023-07-08 04:52:04 +03:00 committed by Eduard-Mihai Burtescu
parent 7f508ba86c
commit b3670b2303

View File

@ -235,15 +235,23 @@ pub(crate) fn reduce_in_func(cx: &Context, func_def_body: &mut FuncDefBody) {
break;
}
func_def_body.inner_in_place_transform_with(&mut ReplaceValueWith(|v| match v {
Value::Const(_) => None,
_ => value_replacements
.get(&HashableValue(v))
.copied()
.map(|new| {
func_def_body.inner_in_place_transform_with(&mut ReplaceValueWith(|mut v| {
let old = v;
loop {
match v {
Value::Const(_) => break,
_ => match value_replacements.get(&HashableValue(v)) {
Some(&new) => v = new,
None => break,
},
}
}
if v != old {
any_changes = true;
new
}),
Some(v)
} else {
None
}
}));
}
}