Direct DXIL: block-local CSE in Module::optimize does not invalidate wave/quad intrinsics across dx.op.discard #1881
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?
Imported from ivall/xcl. Originally posted by microwave805 on 2026-11-24T22:37:50Z.
Static audit on
main @ 689f2dbfound that block-local CSE inModule::optimize()caches wave and quad intrinsics acrossdx.op.discardwithin the same basic block.Where
crates/xcl/src/gpu/dxil/module/opt.rs:82-106(wave_call,cse_kind)crates/xcl/src/gpu/dxil/module/opt.rs:448-475(block-locallocalCSE table)Root cause
cse_kind()classifies alldx.op.wave*anddx.op.quad*calls (exceptdx.op.waveIsFirstLane) asCse::Block, storing them in a per-blocklocalmap (opt.rs:448).In DXIL pixel shaders,
dx.op.discard(cond)(opcode 82) is a normal mid-block call — not a block terminator — that demotes lanes withcond == trueto helper lanes, changing the wave's active lane set for all subsequent wave/quad operations in the same block. Becauseopt.rs:449-475never clearslocalwhen visiting adx.op.discardcall, any wave/quad intrinsic afterdx.op.discardwith identical operands (such asdx.op.waveActiveBallot(true)ordx.op.waveReadLaneFirst(x)) is replaced with the pre-discard value computed before lanes were demoted.Trigger
Any DXIL pixel shader block containing a wave or quad op (e.g.
waveActiveBallot(true)), followed bydx.op.discard(cond), followed by the same wave or quad op in the same basic block.Module::optimize()eliminates the second call and reuses the pre-discard result.Fix direction
In
opt.rs:449-475, whenopisOp::Call(f, _)withself.funcs[*f as usize].name == "dx.op.discard", calllocal.clear(), and add a unit test inmodule/opt.rsverifying that identicalwaveActiveBallotcalls on opposite sides ofdx.op.discardare not merged.AI use
main @ 689f2dband issue drafting.upstream-sync referenced this issue2026-11-25 04:08:41 +00:00