Skip to content

Commit 8275545

Browse files
committed
Guard both CopyObject emission paths with type-match check
The alias-from-term CopyObject path (pre-emit_term) always emitted CopyObject regardless of whether the operand type matched the result type. Only the alias insertion was guarded by the type check, but the CopyObject itself was always created — causing "operand type not matching result type" validation errors when the egraph unified values with different SPIR-V types. Move CopyObject emission and used_ids tracking inside the type_matches check, consistent with the emit_term CopyObject path.
1 parent f06fb76 commit 8275545

1 file changed

Lines changed: 16 additions & 16 deletions

File tree

  • rust/spirv-tools-opt/src/direct

rust/spirv-tools-opt/src/direct/mod.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,27 +1024,27 @@ pub fn optimize_module_direct(module: &Module) -> Result<Module, EgglogOptError>
10241024
// Check if the result is just a reference to another ID
10251025
if let Some(alias_id) = parse_sym_alias_from_term(parsed_term.as_ref(), &id_map) {
10261026
if alias_id != id {
1027-
// Only alias when both IDs have the same SPIR-V type.
1028-
// The egraph may unify values across SPIR-V types (e.g. two
1029-
// constants with the same bit pattern but different type IDs).
1030-
// Aliasing across types would cause OpStore type mismatches
1031-
// when resolve_aliases replaces operand references.
1027+
// Only alias and emit CopyObject when both IDs have the
1028+
// same SPIR-V type. The egraph may unify values across
1029+
// SPIR-V types (e.g. two constants with the same bit
1030+
// pattern but different type IDs, or Vec4/Vec2 both as
1031+
// Expr). CopyObject requires operand type == result type.
10321032
let type_matches = ctx.id_to_type.get(&id)
10331033
== ctx.id_to_type.get(&alias_id);
10341034
if type_matches {
10351035
id_aliases.insert(id, alias_id);
1036+
used_ids.insert(alias_id);
1037+
// Emit CopyObject to maintain SSA form
1038+
optimized_instructions.insert(
1039+
id,
1040+
Instruction::new(
1041+
Op::CopyObject,
1042+
Some(result_type),
1043+
Some(id),
1044+
vec![rspirv::dr::Operand::IdRef(alias_id)],
1045+
),
1046+
);
10361047
}
1037-
used_ids.insert(alias_id);
1038-
// Emit CopyObject to maintain SSA form
1039-
optimized_instructions.insert(
1040-
id,
1041-
Instruction::new(
1042-
Op::CopyObject,
1043-
Some(result_type),
1044-
Some(id),
1045-
vec![rspirv::dr::Operand::IdRef(alias_id)],
1046-
),
1047-
);
10481048
}
10491049
} else if let Some(ref term_tree) = parsed_term {
10501050
// Use the original result_type from the SPIR-V module.

0 commit comments

Comments
 (0)