From b3670b23037407f95e218548f03b541bd05b4ac2 Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Sat, 8 Jul 2023 04:52:04 +0300 Subject: [PATCH] spirt_passes/reduce: fix long-standing bug involving chained replacements. --- .../src/linker/spirt_passes/reduce.rs | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/crates/rustc_codegen_spirv/src/linker/spirt_passes/reduce.rs b/crates/rustc_codegen_spirv/src/linker/spirt_passes/reduce.rs index 7b6760c095..3be962c0f6 100644 --- a/crates/rustc_codegen_spirv/src/linker/spirt_passes/reduce.rs +++ b/crates/rustc_codegen_spirv/src/linker/spirt_passes/reduce.rs @@ -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| { - any_changes = true; - 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; + Some(v) + } else { + None + } })); } }