From 2f8b27713d1f0b54ae2d5fe7cce9218b17c0ffd6 Mon Sep 17 00:00:00 2001 From: Faith Ekstrand Date: Mon, 5 May 2025 10:37:43 -0400 Subject: [PATCH] nak: Fold Src::fold_imm() into the legalization pass Part-of: --- src/nouveau/compiler/nak/ir.rs | 13 ------------- src/nouveau/compiler/nak/legalize.rs | 10 +++++++++- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/src/nouveau/compiler/nak/ir.rs b/src/nouveau/compiler/nak/ir.rs index 748c218ce3b..fdb97d8fa94 100644 --- a/src/nouveau/compiler/nak/ir.rs +++ b/src/nouveau/compiler/nak/ir.rs @@ -1197,19 +1197,6 @@ impl Src { }) } - pub fn fold_imm(&self, src_type: SrcType) -> Src { - // Don't fold Zero - if !matches!(self.src_ref, SrcRef::Imm32(_)) { - return *self; - } - - if let Some(u) = self.as_u32(src_type) { - u.into() - } else { - *self - } - } - pub fn as_ssa(&self) -> Option<&SSARef> { if self.src_mod.is_none() { self.src_ref.as_ssa() diff --git a/src/nouveau/compiler/nak/legalize.rs b/src/nouveau/compiler/nak/legalize.rs index 6e4ae65176d..4302f964880 100644 --- a/src/nouveau/compiler/nak/legalize.rs +++ b/src/nouveau/compiler/nak/legalize.rs @@ -387,7 +387,15 @@ fn legalize_instr( let src_types = instr.src_types(); for (i, src) in instr.srcs_mut().iter_mut().enumerate() { - *src = src.fold_imm(src_types[i]); + if matches!(src.src_ref, SrcRef::Imm32(_)) { + // Fold modifiers on Imm32 sources whenever possible. Not all + // instructions suppport modifiers and immediates at the same time. + // But leave Zero sources alone as we don't want to make things + // immediates that could just be rZ. + if let Some(u) = src.as_u32(src_types[i]) { + *src = u.into(); + } + } b.copy_src_if_not_same_file(src); if !block_uniform {