diff --git a/crates/rustc_codegen_spirv/src/linker/peephole_opts.rs b/crates/rustc_codegen_spirv/src/linker/peephole_opts.rs index 6162d55a377..ce4db2327a5 100644 --- a/crates/rustc_codegen_spirv/src/linker/peephole_opts.rs +++ b/crates/rustc_codegen_spirv/src/linker/peephole_opts.rs @@ -212,7 +212,10 @@ fn match_vector_or_scalars_operand( let operands = results .iter() .map(|inst| match inst.operands[operand_index] { - Operand::IdRef(id) => Some(id), + Operand::IdRef(id) => { + let def = defs.get(&id).or_else(|| types.get(&id))?; + (def.result_type == inst.result_type).then_some(id) + } _ => None, }) .collect::>>()?; diff --git a/tests/compiletests/ui/dis/vector_shift_mixed_sign.rs b/tests/compiletests/ui/dis/vector_shift_mixed_sign.rs new file mode 100644 index 00000000000..c5e45351bd3 --- /dev/null +++ b/tests/compiletests/ui/dis/vector_shift_mixed_sign.rs @@ -0,0 +1,23 @@ +// Test that a vector shift builds when the shift amount has another signedness +// than the shifted value. A shift by an amount of the same type is still fused +// into one vector instruction. + +// build-pass +// compile-flags: -C llvm-args=--disassemble-entry=main +// normalize-stderr-test "\n\W*OpLine .*" -> "" + +use spirv_std::glam::{IVec3, UVec3}; +use spirv_std::spirv; + +#[spirv(fragment)] +pub fn main( + #[spirv(flat)] u: UVec3, + #[spirv(flat)] i: IVec3, + #[spirv(flat)] s: u32, + out_u: &mut [UVec3; 2], + out_i: &mut IVec3, +) { + out_u[0] = u >> 1; + *out_i = i << s; + out_u[1] = u >> s; +} diff --git a/tests/compiletests/ui/dis/vector_shift_mixed_sign.stderr b/tests/compiletests/ui/dis/vector_shift_mixed_sign.stderr new file mode 100644 index 00000000000..08de4119634 --- /dev/null +++ b/tests/compiletests/ui/dis/vector_shift_mixed_sign.stderr @@ -0,0 +1,38 @@ + %1 = OpFunction %2 None %3 + %4 = OpLabel + %6 = OpLoad %7 %8 + %9 = OpLoad %10 %11 + %12 = OpLoad %13 %14 + %16 = OpCompositeExtract %13 %6 0 + %18 = OpBitwiseAnd %19 %20 %21 + %22 = OpShiftRightLogical %13 %16 %18 + %23 = OpCompositeExtract %13 %6 1 + %24 = OpBitwiseAnd %19 %20 %21 + %25 = OpShiftRightLogical %13 %23 %24 + %26 = OpCompositeExtract %13 %6 2 + %27 = OpBitwiseAnd %19 %20 %21 + %28 = OpShiftRightLogical %13 %26 %27 + %29 = OpCompositeConstruct %7 %22 %25 %28 + %30 = OpInBoundsAccessChain %31 %32 %33 + OpStore %30 %29 + %35 = OpCompositeExtract %19 %9 0 + %36 = OpBitwiseAnd %13 %12 %37 + %38 = OpShiftLeftLogical %19 %35 %36 + %39 = OpCompositeExtract %19 %9 1 + %40 = OpBitwiseAnd %13 %12 %37 + %41 = OpShiftLeftLogical %19 %39 %40 + %42 = OpCompositeExtract %19 %9 2 + %43 = OpBitwiseAnd %13 %12 %37 + %44 = OpShiftLeftLogical %19 %42 %43 + %45 = OpCompositeConstruct %10 %38 %41 %44 + OpStore %46 %45 + %47 = OpBitwiseAnd %13 %12 %37 + %48 = OpBitwiseAnd %13 %12 %37 + %49 = OpBitwiseAnd %13 %12 %37 + %50 = OpCompositeConstruct %7 %47 %48 %49 + %51 = OpShiftRightLogical %7 %6 %50 + %52 = OpInBoundsAccessChain %31 %32 %53 + OpStore %52 %51 + OpNoLine + OpReturn + OpFunctionEnd