Per-lane: unsound whole-wave predicate checks (uniform_over ignores inactive lanes, S_CBRANCH_VCCZ/NZ ANDs with EXEC, SRC_SCC 253 unchecked) #1888
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
goal:world-load
good first issue
help wanted
invalid
keep-open
off-goal
question
stale
test-only
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/xcl-dev--xcl#1888
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@microwave805 on GitHub · 2026-11-24 22:37 UTC · original
Static audit on
main @ 689f2dbfound three soundness gaps in the per-lane (XCL_PER_LANE=1) whole-wave mask predicate analysis (crates/xcl/src/gpu/recomp/lane_masks.rsandlower.rs) that cause silent control-flow inversion or per-lane divergence from RDNA2 hardware semantics. (Distinct from#1866/ Pipodi's point 2 on#1745.)1.
uniform_overignores inactive lanes (EXEC == 0)crates/xcl/src/gpu/recomp/lane_masks.rs:553-562, 605-614, 829-853uniform_over(reach, e, c)checks whetherre = reach & eimpliescor!c, completely ignoring bits outsideEXEC. Hardware scalar bitwise ops andS_CMP_EQ/LG_U32/U64setSCCfrom all 32/64 bits of the mask register, including inactive lanes:s_cmp_eq_u32 exec, -1; s_cbranch_scc1(with partialEXEC, e.g.0x0000FFFF):lane_masks.rs:558-559setsscc = !(exec ^ TRUE) = exec. Sincere = reach & exectrivially impliesexec,uniform_overaccepts the branch. On RDNA2 hardware,EXEC != 0xFFFFFFFFsoSCC = 0for the whole wave (branch not taken); in the per-lane lowering, active lanes seeexec_bit == true(SCC = 1) and take the branch (100% inverted).s_not_b32 s1, exec; s_cbranch_scc0(ors_xor_b32 s1, exec, -1; s_cbranch_scc1):lane_masks.rs:531setsv = !exec. Sincere = reach & execimplies!(!exec),uniform_overaccepts. Hardware seess1 = 0xFFFF0000 != 0(SCC = 1); active per-lane threads see!exec_bit == false(SCC = 0).s_cmp_eq_u32 vcc, 0; s_cbranch_scc1whenvcchas bits set in inactive lanes:re => !vccpassesuniform_over, so active lanes seeSCC = 1where hardware seesvcc != 0(SCC = 0).any-lane-nonzero(res != 0/S_CMP_LG) vsall-lanes-equal(S_CMP_EQ):res != 0: per-laneSCCmatches hardwareSCConly ifre => c(so at least one lane is 1 and every active lane is 1, providedreis satisfiable) OR!cholds wave-wide (not just overre, i.e.,c == FALSEincluding inactive lanes).S_CMP_EQ: per-laneSCCmatches hardwareSCConly ifc == TRUEwave-wide (all lanes including inactive ones agree) ORre => !c.2.
S_CBRANCH_VCCZ/S_CBRANCH_VCCNZwrongly ANDVCCwithEXECcrates/xcl/src/gpu/recomp/lane_masks.rs:628-634,crates/xcl/src/gpu/recomp/lower.rs:970-978Lanes::cond(self.bdd.and(v, e)) andLower::cond(self.ir.bin(Bin::And, v, e)) maskVCCwithEXEC. On RDNA2 hardware,S_CBRANCH_VCCZtestsVCC == 0across all 32/64 bits, independent ofEXEC. IfVCCretains set bits outside a narrowedEXEC(e.g.,v_cmpbefores_and_saveexec, ors_mov/s_or/s_notintoVCC),VCC & EXEC == 0makesXCL_PER_LANEtakeS_CBRANCH_VCCZwhile hardware falls through.vdirectly (without ANDing withe) and apply the wave-wide zero/nonzero check above.3. Direct
SRC_SCC(encoding253) reads bypasslane_masksvalidationcrates/xcl/src/gpu/recomp/lane_masks.rs:829-836,crates/xcl/src/gpu/recomp/lower.rs:433-436lane_masks.rs:829only checks["S_CSELECT", "S_CMOV", "S_ADDC", "S_SUBB"]for reads of a per-lane mask-opSCC. However,Lower::src()handles source encoding253(SRC_SCC) for any SALU/VALU instruction (s_mov_b32 s0, scc,s_add_u32 s0, s1, scc,v_mov_b32 v0, scc,v_add_nc_u32 v0, v1, scc, etc.). WhenSCCholds a per-lane mask bit, those instructions silently read per-lane0/1values instead of hardware's wave-uniformSCC— and if copied into an SGPR (s_mov_b32 s0, scc), subsequent branches ons0are misclassified as uniform.SSRC0,SSRC1,SRC0,SRC1,SRC2,SOFFSET) for code253(as well as implicitOPR_SSRC_SPECIAL_SCCinputs) inlane_masks.rs:829-836.(Note: separately,
lane_masks::is_vectoratlane_masks.rs:271also excludes!n.starts_with("V_CMP"), so bridged non-XV_CMP*instructions — e.g.V_CMP_LT_F32— passguard = trueatlower.rs:1647just likeV_CMPX*noted by@Pipodiin#1745point 3, allowing inactive lanes to set bits in the destination mask.)AI use
main @ 689f2dband issue drafting. Not built or run on retail game data (no game files on hand).