nak/legalize: Ensure all SSA values for a given ref are in the same file

It's possible for copy propagation to put a GPR and a UGPR into the same
vector source in an instruction.  Hardware registers, however, are
either GPRs or UGPRs and never a mix.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/29591>
This commit is contained in:
Faith Ekstrand 2024-06-12 09:01:23 -05:00 committed by Marge Bot
parent caf033b142
commit e4df28ade8

View file

@ -13,6 +13,12 @@ fn copy_ssa(b: &mut impl SSABuilder, ssa: &mut SSAValue, reg_file: RegFile) {
*ssa = tmp;
}
fn copy_ssa_ref(b: &mut impl SSABuilder, vec: &mut SSARef, reg_file: RegFile) {
for ssa in &mut vec[..] {
copy_ssa(b, ssa, reg_file);
}
}
fn src_is_upred_reg(src: &Src) -> bool {
match &src.src_ref {
SrcRef::True | SrcRef::False => false,
@ -59,6 +65,30 @@ fn copy_src_if_upred(b: &mut impl SSABuilder, src: &mut Src) {
}
}
fn copy_src_if_not_same_file(b: &mut impl SSABuilder, src: &mut Src) {
let SrcRef::SSA(vec) = &mut src.src_ref else {
return;
};
if vec.comps() == 1 {
return;
}
let mut all_same = true;
let file = vec[0].file();
for i in 1..vec.comps() {
let c_file = vec[usize::from(i)].file();
if c_file != file {
debug_assert!(c_file.to_warp() == file.to_warp());
all_same = false;
}
}
if !all_same {
copy_ssa_ref(b, vec, file.to_warp());
}
}
fn src_is_reg(src: &Src, reg_file: RegFile) -> bool {
match src.src_ref {
SrcRef::Zero | SrcRef::True | SrcRef::False => true,
@ -930,6 +960,7 @@ 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]);
copy_src_if_not_same_file(b, src);
}
if b.sm() >= 70 {