From 3e5f9989b005ca268444a913d6c2f2b71d81bc9a Mon Sep 17 00:00:00 2001 From: Ilya Lesokhin Date: Thu, 14 Nov 2024 16:33:13 +0200 Subject: [PATCH] Fix possibly missed optimization. --- .../src/optimizations/match_optimizer.rs | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/crates/cairo-lang-lowering/src/optimizations/match_optimizer.rs b/crates/cairo-lang-lowering/src/optimizations/match_optimizer.rs index 0718e35f1d5..5323649759e 100644 --- a/crates/cairo-lang-lowering/src/optimizations/match_optimizer.rs +++ b/crates/cairo-lang-lowering/src/optimizations/match_optimizer.rs @@ -322,15 +322,22 @@ impl<'a> Analyzer<'a> for MatchOptimizerContext { return; }; - let Some(var_usage) = remapping.get(&candidate.match_variable) else { - // Revoke the candidate. - info.candidate = None; - return; - }; let orig_match_variable = candidate.match_variable; - candidate.match_variable = var_usage.var_id; - if remapping.len() > 1 { + // The term 'additional_remappings' refers to remappings for variables other than the match + // variable. + let goto_has_additional_remappings = + if let Some(var_usage) = remapping.get(&candidate.match_variable) { + candidate.match_variable = var_usage.var_id; + remapping.len() > 1 + } else { + // Note that remapping.is_empty() is false here. + true + }; + + if goto_has_additional_remappings { + // here, we have remappings for variables other than the match variable. + if candidate.future_merge || candidate.additional_remappings.is_some() { // TODO(ilya): Support multiple remappings with future merges.