Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions crates/xcl/src/gpu/dxil/module/opt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ impl Module {

fn cse_kind(&self, op: &Op) -> Cse {
match op {
Op::Gep(p, _) if !self.is_const_global_ptr(*p) => Cse::Block,
Op::Bin(..) | Op::Cast(..) | Op::Cmp(..) | Op::Select(..) | Op::Extract(..) | Op::Gep(..) => Cse::Dom,
Op::Load(p, _) if self.is_const_global_ptr(*p) => Cse::Dom,
Op::Call(f, _) if self.funcs[*f as usize].attrs == FnAttrs::ReadNone => Cse::Dom,
Expand Down Expand Up @@ -1033,6 +1034,42 @@ mod tests {
.count()
}

#[test]
fn a_pointer_to_storage_is_made_again_in_each_block() {
let mut m = Module::new();
m.define_entry("main");
let i32t = m.i32();
let arr = m.array(2, i32t);
let g = m.global("xcl_xs", arr, 3, None, false, 4);
let (zero, one) = (m.i32c(0), m.i32c(1));
let lane_ty = m.func_ty(i32t, &[]);
let lane_fn = m.declare("dx.op.waveGetLaneIndex", lane_ty, FnAttrs::ReadNone);
let next = m.new_block();
let done = m.new_block();
let b = m.entry_block();
m.set_block(b);
let lane = m.call(lane_fn, &[]);
let go = m.cmp(Pred::Eq, lane, zero);
for to in [Some(next), None] {
let p = m.gep(g, &[zero, one]);
m.store(p, zero, 4);
let q = m.gep(g, &[zero, one]);
m.store(q, one, 4);
match to {
Some(to) => {
m.cond_br(go, to, done);
m.set_block(to);
}
None => m.br(done),
}
}
m.set_block(done);
m.ret();
m.optimize();
let geps = |b: &Vec<u32>| b.iter().filter(|&&i| matches!(m.insts[i as usize].op, Op::Gep(..))).count();
assert_eq!(m.blocks.iter().map(geps).collect::<Vec<_>>(), [1, 1, 0]);
}

#[test]
fn block_cse_invalidates_wave_and_quad_calls_across_discard() {
let build = |op_name: &str, with_discard: bool| -> (Module, u32) {
Expand Down
Loading