From e6e108386b906302a120b53f0e0c3e92f130fa7c Mon Sep 17 00:00:00 2001 From: Leyukaka <45659323+Leyukaka@users.noreply.github.com> Date: Fri, 27 Nov 2026 20:57:14 +0100 Subject: [PATCH] compute: classify SCC-neutral SOP1 ops in the direct SCC liveness uses_scc_after() treated every SOP1 outside a short list as an unknown SCC reader, so an SCC produced by a byte-window descriptor rewrite was kept live past s_ff1_i32_b64 and refused as "numeric SCC from a symbolic descriptor field". The scans and bit edits that neither read nor write SCC (s_ff0/s_ff1, s_flbit, s_brev, s_sext, s_bitset0/1, s_bitreplicate) now pass liveness through; s_abs_i32 and the 32-bit counts overwrite it, the remaining b64 saveexec forms join the mask writers. Unclassified ops keep the conservative rule. native_direct_container compiles the rewrite followed by s_ff1_i32_b64 and s_brev_b32, and still refuses it when s_cselect_b32 reads SCC after the scan. AI-assisted. --- src/gfx1013_direct_compute.inl | 20 ++++++++++++++++---- tests/native_direct_container_check.py | 10 ++++++++++ 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/gfx1013_direct_compute.inl b/src/gfx1013_direct_compute.inl index edbd70dcb8..fbd83c1621 100644 --- a/src/gfx1013_direct_compute.inl +++ b/src/gfx1013_direct_compute.inl @@ -1707,8 +1707,12 @@ struct DirectCompute { const bool mask_scc = n == "s_andn2_b64" || n == "s_and_b64" || n == "s_or_b64" || n == "s_xor_b64" || n == "s_not_b64" || n == "s_wqm_b32" || n == "s_wqm_b64" || n == "s_quadmask_b32" || n == "s_quadmask_b64" || - n == "s_and_saveexec_b64" || n == "s_or_saveexec_b64"; - const bool overwrites = mask_scc || n == "s_bcnt0_i32_b64" || n == "s_bcnt1_i32_b64" || + n == "s_and_saveexec_b64" || n == "s_or_saveexec_b64" || n == "s_xor_saveexec_b64" || + n == "s_andn2_saveexec_b64" || n == "s_orn2_saveexec_b64" || + n == "s_nand_saveexec_b64" || n == "s_nor_saveexec_b64" || n == "s_xnor_saveexec_b64"; + const bool overwrites = mask_scc || n == "s_abs_i32" || + n == "s_bcnt0_i32_b32" || n == "s_bcnt1_i32_b32" || + n == "s_bcnt0_i32_b64" || n == "s_bcnt1_i32_b64" || inst.enc == Encoding::Sopc || n == "s_bfe_u32" || n == "s_and_b32" || n == "s_or_b32" || n == "s_max_u32" || n == "s_add_u32" || n == "s_sub_u32" || n == "s_add_i32" || n == "s_sub_i32" || n == "s_and_saveexec_b32" || @@ -1721,10 +1725,18 @@ struct DirectCompute { const bool preserves_pair = n == "s_mul_i32" || n == "s_mul_hi_i32" || n == "s_mul_hi_u32" || n == "s_bfm_b32" || n == "s_bfm_b64" || n == "s_pack_ll_b32_b16" || n == "s_pack_lh_b32_b16" || n == "s_pack_hh_b32_b16"; + const bool preserves_sop1 = n == "s_mov_b32" || n == "s_mov_b64" || + n == "s_brev_b32" || n == "s_brev_b64" || + n == "s_ff0_i32_b32" || n == "s_ff0_i32_b64" || + n == "s_ff1_i32_b32" || n == "s_ff1_i32_b64" || + n == "s_flbit_i32_b32" || n == "s_flbit_i32_b64" || + n == "s_flbit_i32" || n == "s_flbit_i32_i64" || + n == "s_sext_i32_i8" || n == "s_sext_i32_i16" || + n == "s_bitset0_b32" || n == "s_bitset0_b64" || + n == "s_bitset1_b32" || n == "s_bitset1_b64" || n == "s_bitreplicate_b64_b32"; const bool uncertain_scalar = (inst.enc == Encoding::Sopk && n != "s_movk_i32") || (inst.enc == Encoding::Sop2 && !overwrites && !preserves_pair) || - (inst.enc == Encoding::Sop1 && !overwrites && n != "s_mov_b32" && n != "s_mov_b64" && - n != "s_brev_b64" && n != "s_sext_i32_i8" && n != "s_sext_i32_i16"); + (inst.enc == Encoding::Sop1 && !overwrites && !preserves_sop1); if (reads_scc || uncertain_scalar || (inst.branch() && (inst.op == 4 || inst.op == 5))) { scc_live[j] = true; pending.push_back(j); diff --git a/tests/native_direct_container_check.py b/tests/native_direct_container_check.py index b0aeaf4d52..88f5e60650 100644 --- a/tests/native_direct_container_check.py +++ b/tests/native_direct_container_check.py @@ -319,6 +319,16 @@ def check(name, profile, data, expected=""): check("descriptor-saveexec-bypass", cs, compute(words(*address_field, 0xbf880001, saveexec, read_scc, end), table=True), "numeric SCC from a symbolic descriptor field") + pair_zero = [0xbe960380, 0xbe970380] # s_mov_b32 s22, 0 / s23, 0 (both preserve SCC) + ff1_pair = 0xbe8e1416 # s_ff1_i32_b64 s14, s[22:23] + brev = 0xbe8f0b0e # s_brev_b32 s15, s14 + use_scan = 0x7e00020f # v_mov_b32 v0, s15 + select_scc = 0x85198e80 # s_cselect_b32 s25, 0, s14 + check("descriptor-sop1-preserves-scc", cs, + compute(words(*address_field, *pair_zero, ff1_pair, brev, use_scan, end), table=True)) + check("descriptor-sop1-before-scc-read", cs, + compute(words(*address_field, *pair_zero, ff1_pair, select_scc, end), table=True), + "numeric SCC from a symbolic descriptor field") # The previous symbolic SCC is dead at WQM. Reading it before WQM # must still refuse. The nonzero high word supplies the new SCC. numeric_wqm = [0xbe9a0380, 0xbe9b0381, 0xbe980a1a] # s[24:25] = WQM(s[26:27])