nak/spill_values: Follow phis from src to dest
Some checks are pending
macOS-CI / macOS-CI (dri) (push) Waiting to run
macOS-CI / macOS-CI (xlib) (push) Waiting to run

ssa_state_out has the predecessor's SSAValue, so we need look for it in
the phi_src map.

Totals:
CodeSize: 4545122720 -> 4534830176 (-0.23%); split: -0.23%, +0.00%
Number of GPRs: 10963889 -> 10963693 (-0.00%); split: -0.00%, +0.00%
SLM Size: 1855380 -> 1649308 (-11.11%); split: -11.11%, +0.01%
Static cycle count: 1104322907 -> 1093035821 (-1.02%); split: -1.02%, +0.00%
Spills to memory: 480689 -> 139107 (-71.06%)
Fills from memory: 480689 -> 139107 (-71.06%)
Spills to reg: 458804 -> 242139 (-47.22%); split: -47.23%, +0.01%
Fills from reg: 303068 -> 222030 (-26.74%); split: -26.75%, +0.01%
Max warps/SM: 7245516 -> 7245580 (+0.00%)

Totals from 9899 (5.04% of 196502) affected shaders:
CodeSize: 1056727952 -> 1046435408 (-0.97%); split: -0.98%, +0.00%
Number of GPRs: 1666652 -> 1666456 (-0.01%); split: -0.01%, +0.00%
SLM Size: 1107988 -> 901916 (-18.60%); split: -18.61%, +0.01%
Static cycle count: 254942337 -> 243655251 (-4.43%); split: -4.43%, +0.01%
Spills to memory: 480689 -> 139107 (-71.06%)
Fills from memory: 480689 -> 139107 (-71.06%)
Spills to reg: 367784 -> 151119 (-58.91%); split: -58.92%, +0.01%
Fills from reg: 222209 -> 141171 (-36.47%); split: -36.49%, +0.02%
Max warps/SM: 119188 -> 119252 (+0.05%)

Fixes: bcad2add47 ("nak: Add a spilling pass")
Reviewed-by: Faith Ekstrand <faith.ekstrand@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/35143>
This commit is contained in:
Mel Henning 2025-05-23 20:59:25 -04:00 committed by Marge Bot
parent 0e5880ebe4
commit 6c68c2c3ba

View file

@ -14,20 +14,21 @@ use std::cell::RefCell;
use std::cmp::{max, Ordering, Reverse};
use std::collections::BinaryHeap;
#[derive(Default)]
struct PhiDstMap {
phi_ssa: FxHashMap<Phi, SSAValue>,
ssa_phi: FxHashMap<SSAValue, Phi>,
}
impl PhiDstMap {
fn new() -> PhiDstMap {
PhiDstMap {
ssa_phi: Default::default(),
}
Default::default()
}
fn add_phi_dst(&mut self, phi: Phi, dst: &Dst) {
let vec = dst.as_ssa().expect("Not an SSA destination");
debug_assert!(vec.comps() == 1);
self.phi_ssa.insert(phi, vec[0]);
self.ssa_phi.insert(vec[0], phi);
}
@ -44,24 +45,27 @@ impl PhiDstMap {
fn get_phi(&self, ssa: &SSAValue) -> Option<&Phi> {
self.ssa_phi.get(ssa)
}
fn get_dst_ssa(&self, phi: &Phi) -> Option<&SSAValue> {
self.phi_ssa.get(phi)
}
}
#[derive(Default)]
struct PhiSrcMap {
phi_src: FxHashMap<Phi, SSAValue>,
src_phi: FxHashMap<SSAValue, Phi>,
}
impl PhiSrcMap {
fn new() -> PhiSrcMap {
PhiSrcMap {
phi_src: Default::default(),
}
Default::default()
}
fn add_phi_src(&mut self, phi: Phi, src: &Src) {
debug_assert!(src.is_unmodified());
let vec = src.src_ref.as_ssa().expect("Not an SSA source");
debug_assert!(vec.comps() == 1);
self.phi_src.insert(phi, vec[0]);
self.src_phi.insert(vec[0], phi);
}
pub fn from_block(block: &BasicBlock) -> PhiSrcMap {
@ -74,8 +78,8 @@ impl PhiSrcMap {
map
}
pub fn get_src_ssa(&self, phi: &Phi) -> &SSAValue {
self.phi_src.get(phi).expect("Phi source missing")
pub fn get_phi(&self, ssa: &SSAValue) -> Option<&Phi> {
self.src_phi.get(ssa)
}
}
@ -599,8 +603,8 @@ fn spill_values<S: Spill>(
let phi_src_map = &phi_src_maps[*p_idx];
for mut ssa in ssa_state_out[*p_idx].w.iter().cloned() {
if let Some(phi) = phi_dst_map.get_phi(&ssa) {
ssa = *phi_src_map.get_src_ssa(phi);
if let Some(phi) = phi_src_map.get_phi(&ssa) {
ssa = *phi_dst_map.get_dst_ssa(phi).unwrap();
}
if let Some(next_use) = bl.first_use(&ssa) {