diff --git a/crates/xcl/src/gpu/dxil/kernel.rs b/crates/xcl/src/gpu/dxil/kernel.rs index 371ac0622c..12d45829ba 100644 --- a/crates/xcl/src/gpu/dxil/kernel.rs +++ b/crates/xcl/src/gpu/dxil/kernel.rs @@ -35,7 +35,7 @@ pub struct KernelOptions { /// Version of the direct translator's output, part of the on-disk translation cache's /// identity (`recomp::pso`): bump it on any change that alters the emitted containers /// (the `gpu/dxil` sources are not in build.rs's translator source hash). -pub const TRANSLATOR_VERSION: u32 = 4; +pub const TRANSLATOR_VERSION: u32 = 5; /// `XCL_DIRECT_DXIL=1`: console compute shaders (and the kernel tests) go through this /// translator, with the HLSL path as the fallback for what it cannot translate yet. diff --git a/crates/xcl/src/gpu/dxil/module.rs b/crates/xcl/src/gpu/dxil/module.rs index 3462ca3610..225cff450b 100644 --- a/crates/xcl/src/gpu/dxil/module.rs +++ b/crates/xcl/src/gpu/dxil/module.rs @@ -1350,7 +1350,7 @@ impl Module { /// integers (DXC's shader-flag rules; `Fma` is flagged by its helper). pub fn uses_double_extensions(&self) -> bool { let Some(f64) = self.type_ids.get(&TypeDef::Double).copied() else { return false }; - self.insts.iter().any(|d| match &d.op { + self.blocks.iter().flatten().map(|&i| &self.insts[i as usize]).any(|d| match &d.op { Op::Bin(BinOp::UDiv | BinOp::SDiv, ..) => d.ty == f64, Op::Cast(CastOp::FPToUI | CastOp::FPToSI, v, _) => self.value_ty(*v) == f64, Op::Cast(CastOp::UIToFP | CastOp::SIToFP, _, t) => *t == f64, @@ -1459,3 +1459,24 @@ impl Module { self.globals.iter().filter(|g| g.addrspace == addrspace).map(|g| self.alloc_size_layout(g.ty, native16)).sum() } } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn unreachable_conversion_does_not_require_double_extensions() { + let mut m = Module::new(); + m.define_entry("main"); + m.ret(); + let dead = m.new_block(); + m.set_block(dead); + let seven = m.i32c(7); + let double = m.f64(); + m.cast(CastOp::SIToFP, seven, double); + m.ret(); + assert!(m.uses_double_extensions()); + m.optimize(); + assert!(!m.uses_double_extensions()); + } +}