Repository navigation
Backlog
Description
Static audit on main @ c7e1799 found two critical correctness bugs in the per-lane direct DXIL lowering (XCL_PER_LANE=1) following #1876 and #1864. Part of #1269.
1. [Critical] Bridged non-CMPX V_CMP_* instructions ignore EXEC and corrupt inactive lane bits
- Where:
crates/xcl/src/gpu/recomp/lower.rs:1782-1784, 1817-1823,crates/xcl/src/gpu/recomp/lane_masks.rs:295-298 - Root cause:
lane_masks::is_vector(lane_masks.rs:295-298) excludes allV_CMP*(!n.starts_with("V_CMP")), soV_CMP_*PCs are never added toself.guarded.- Native
valu()(lower.rs:825-854) handles only plainU32/I32V_CMP*(ANDing withEXECat lines 849-850); every float (F32/F16/F64), 64-bit (I64/U64), 16-bit (I16/U16),V_CMP_CLASS_*, and VOP3-modified/SDWA compare falls through tobridge(). - Commit
fe78c81(Recompiler: a float v_cmpx through #1426's lowering keeps lanes outside EXEC out #1876) only setold_execforcmpx(V_CMPX*) atlower.rs:1782. For non-CMPXbridgedV_CMP_*,old_execisNone,!self.guarded.contains(&d.pc)istrue, soguardis constanttrue(Lw::write_maskseesact() == true) and lines 1819-1823 write rawcondunmasked byEXEC.
- Trigger: Under narrowed
EXEC(e.g. computewave_branches == truefrom recomp: enable whole-wave branches and dead-SCC elision in split wave64 #2203, or any guarded region / PS helper lanes):Hardware setsv_cmp_lt_u32 vcc, v0, 16 ; lanes 0..15 true s_and_saveexec_b32 s0, vcc ; EXEC = 0x0000_FFFF v_cmp_gt_f32 vcc, v1, 0.0 ; bridged: v1 = 0.0 in lanes 0..15, v1 = 1.0 in lanes 16..31 s_cbranch_vccz L_skip
vcc = 0x0000_0000(inactive lanes forced to 0) and branches toL_skip; per-lane lowering producesvcc = 0xFFFF_0000and takes the wrong branch. - Fix: Mask every bridged
V_CMP*(not onlyV_CMPX*) withEXECwhen!in_guarded_run:let old_exec = if name.starts_with("V_CMP") && !in_guarded_run { Some(self.read_bit(b, EXEC)?) } else { None };
2. [Critical] Writing to NULL (SDST = 125) clobbers EXEC (126) in per-lane lowering and corrupts lane_masks
- Where:
crates/xcl/src/gpu/recomp/lower.rs:403-424(write_num,write_bit),577-578(S_GETPC_B64),669-670(S_MOV_B64),691-692(S_CSELECT_B64),973;crates/xcl/src/gpu/recomp/lane_masks.rs:492-496, 551, 581 - Root cause: On RDNA2, SGPR
125isNULL(reads0, discards writes; standard idiom fors_and_b64 null, vcc, execto setSCCwithout clobbering any SGPR, or VOP3v_cmp_* null, ...). Commit15fff3b(Recompiler: allow inline-constant and NULL mask operands in the per-lane form #1864) added125reads andsaveexecguardssd != 125, butwrite_numandwrite_bitdo not ignorer == 125, and 64-bit writes unconditionally writesd + 1 = 126(EXEC):- Wave64:
write_bit(b, 125, bit)(e.g.s_and_b64 null, vcc, execor VOP3v_cmp_eq_u32 null, ...) writesVar::S(126) = num_marker; Var::M(126) = bit_marker;, destroyingEXECand failing with"s126: a mask read as a number". - Wave32 (silent miscompilation):
s_mov_b64 null, s[0:1]ors_cselect_b64 null, ...callswrite_num(b, 126, hi), silently overwritingEXECwithhiwithout any error! lane_masks.rs:496, 551, 581:125 < 128storesst.regs[125] = Some(v)and a subsequentmask_src(125)reads backst.regs[125]instead ofSome(FALSE).
- Wave64:
- Fix:
- Return immediately when
r == 125inwrite_numandwrite_bit; guardsd != 125around(sd, sd + 1)writes atlower.rs:577-578, 669-670, 691-692, 973. - In
lane_masks.rs, map125 => Some(FALSE)inmask_srcand requirer != 125before writingst.regs[r].
- Return immediately when
AI use
- Antigravity (Gemini 4 Neon): static code audit on
main @ c7e1799and issue drafting.
Metadata
Metadata
Assignees
Labels
No labels
Activity
throny commentedon Nov 29, 2026
Status for triage: the
V_CMP_*/ EXEC half of this issue is fixed onmainby #2503 (merged today):bridge()ingpu/recomp/lower.rsnow reads EXEC for every bridgedV_CMP*and masks the result with it, anda_bridged_v_cmp_clears_inactive_lanes_outside_execcovers it (1 passed onmain24d21a41, RTX 4080 16 GB, 621.40). What is still open here is the NULL-destination half, which is #2117; itsbridge()hunk was written against an older base and may need a rebase.AI use: Claude Code (Claude Fable 5.2) checked the code, ran the test and wrote this.