nak/legalize: Use ConstTracker to skip some movs
Some checks are pending
macOS-CI / macOS-CI (dri) (push) Waiting to run
macOS-CI / macOS-CI (xlib) (push) Waiting to run

Totals:
CodeSize: 4531122000 -> 4523280144 (-0.17%); split: -0.17%, +0.00%
Static cycle count: 2705057234 -> 2704474031 (-0.02%); split: -0.02%, +0.00%
Fills from reg: 203387 -> 203380 (-0.00%)

Totals from 132940 (67.55% of 196789) affected shaders:
CodeSize: 4119643920 -> 4111802064 (-0.19%); split: -0.19%, +0.00%
Static cycle count: 2273444838 -> 2272861635 (-0.03%); split: -0.03%, +0.00%
Fills from reg: 193909 -> 193902 (-0.00%)

Reviewed-by: Mary Guillemard <mary@mary.zone>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/38173>
This commit is contained in:
Mel Henning 2025-10-30 18:27:18 -04:00 committed by Marge Bot
parent 4890e91f49
commit 28d0ff419f

View file

@ -2,6 +2,7 @@
// SPDX-License-Identifier: MIT
use crate::api::{GetDebugFlags, DEBUG};
use crate::const_tracker::ConstTracker;
use crate::ir::*;
use crate::liveness::{BlockLiveness, Liveness, SimpleLiveness};
@ -377,12 +378,18 @@ pub trait LegalizeBuildHelpers: SSABuilder {
pub struct LegalizeBuilder<'a> {
b: SSAInstrBuilder<'a>,
const_tracker: &'a mut ConstTracker,
}
impl<'a> LegalizeBuilder<'a> {
fn new(sm: &'a dyn ShaderModel, alloc: &'a mut SSAValueAllocator) -> Self {
fn new(
sm: &'a dyn ShaderModel,
alloc: &'a mut SSAValueAllocator,
const_tracker: &'a mut ConstTracker,
) -> Self {
LegalizeBuilder {
b: SSAInstrBuilder::new(sm, alloc),
const_tracker,
}
}
@ -404,6 +411,17 @@ impl<'a> Builder for LegalizeBuilder<'a> {
fn sm(&self) -> u8 {
self.b.sm()
}
fn copy_to(&mut self, dst: Dst, mut src: Src) {
if let Some(ssa_ref) = src.as_ssa() {
if let &[ssa_value] = &ssa_ref[..] {
if let Some(new_src) = self.const_tracker.get(&ssa_value) {
src = new_src.clone().into();
}
}
};
self.b.copy_to(dst, src);
}
}
impl<'a> SSABuilder for LegalizeBuilder<'a> {
@ -558,6 +576,7 @@ impl Shader<'_> {
for f in &mut self.functions {
let live = SimpleLiveness::for_function(f);
let mut pinned: FxHashSet<_> = Default::default();
let mut const_tracker = ConstTracker::new();
for (bi, b) in f.blocks.iter_mut().enumerate() {
let bl = live.block_live(bi);
@ -565,13 +584,23 @@ impl Shader<'_> {
let mut instrs = Vec::new();
for (ip, mut instr) in b.instrs.drain(..).enumerate() {
if let Op::Pin(pin) = &instr.op {
if let Dst::SSA(ssa) = &pin.dst {
pinned.insert(ssa.clone());
match &instr.op {
Op::Pin(pin) => {
if let Dst::SSA(ssa) = &pin.dst {
pinned.insert(ssa.clone());
}
}
Op::Copy(copy) => {
const_tracker.add_copy(copy);
}
_ => (),
}
let mut b = LegalizeBuilder::new(sm, &mut f.ssa_alloc);
let mut b = LegalizeBuilder::new(
sm,
&mut f.ssa_alloc,
&mut const_tracker,
);
legalize_instr(sm, &mut b, bl, bu, &pinned, ip, &mut instr);
b.push_instr(instr);
instrs.append(&mut b.into_vec());