From 92a7486bf3264f89719809ef0a314db3429e83d4 Mon Sep 17 00:00:00 2001 From: Chris Fallin Date: Wed, 30 Nov 2022 00:07:32 -0800 Subject: [PATCH] regalloc bug: mark locals as used when value already has locals, e.g. for function param --- src/backend/localify.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/backend/localify.rs b/src/backend/localify.rs index 3dea14e..f16b8ed 100644 --- a/src/backend/localify.rs +++ b/src/backend/localify.rs @@ -137,6 +137,10 @@ impl<'a> Context<'a> { // If there is already an allocation (e.g. for a // function parameter), return. if !results.values[u].is_empty() { + // Ensure the local(s) are marked as live. + for &local in &results.values[u] { + live_locals.insert(local); + } return; } @@ -170,10 +174,17 @@ impl<'a> Context<'a> { .tys() .iter() .map(|&ty| { + log::trace!( + "looking for location for {} can_reuse {} with live_locals {:?}", + u, + can_reuse, + live_locals, + ); let reused = if can_reuse { // Try to find a local of the right type that is not live. let affinities = affinities.get(&u).map(|v| &v[..]).unwrap_or(&[]); + log::trace!(" -> affinities: {:?}", affinities); let mut try_list = affinities .iter() .filter_map(|&aff_val| { @@ -189,16 +200,23 @@ impl<'a> Context<'a> { try_list .find(|&(local, local_ty)| { + log::trace!( + " -> considering {} ty {:?}", + local, + local_ty + ); local_ty == ty && live_locals.insert(local) }) .map(|(local, _)| local) } else { None }; + log::trace!(" -> reused: {:?}", reused); reused.unwrap_or_else(|| { let local = results.locals.push(ty); live_locals.insert(local); + log::trace!(" -> new allocation: {}", local); local }) })