Skip to content
Open
Show file tree
Hide file tree
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
5 changes: 4 additions & 1 deletion crates/rustc_codegen_spirv/src/linker/peephole_opts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Option<Vec<_>>>()?;
Expand Down
23 changes: 23 additions & 0 deletions tests/compiletests/ui/dis/vector_shift_mixed_sign.rs
Original file line number Diff line number Diff line change
@@ -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;
}
38 changes: 38 additions & 0 deletions tests/compiletests/ui/dis/vector_shift_mixed_sign.stderr
Original file line number Diff line number Diff line change
@@ -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
Loading