Skip to content

Commit eddc193

Browse files
authored
Fix fused_cmp_branch type check (#1973)
* fix fused_cmp_branch type check * update Wasmi .wast testsuite
1 parent 8f4297b commit eddc193

2 files changed

Lines changed: 9 additions & 5 deletions

File tree

  • crates

crates/wasmi/src/engine/translator/func/mod.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1461,19 +1461,23 @@ impl FuncTranslator {
14611461
// Case: cannot fuse without a known last instruction
14621462
return Ok(None);
14631463
};
1464-
let Some(ir::Location::Reg(result_ty)) = staged_op.result_loc() else {
1464+
let Some(ir::Location::Reg(staged_ty)) = staged_op.result_loc() else {
14651465
// Case: cannot fuse without register result.
14661466
return Ok(None);
14671467
};
1468-
let ResolvedOperand::Reg(_ty) = condition.resolve(&self.layout)? else {
1468+
let ResolvedOperand::Reg(condition_ty) = condition.resolve(&self.layout)? else {
14691469
// Case: cannot fuse non-register operands
14701470
// - locals have observable behavior.
14711471
// - immediates cannot be the result of a previous instruction.
14721472
return Ok(None);
14731473
};
1474+
if staged_ty != condition_ty {
1475+
// Case: cannot fuse if staged type and condition type do not match.
1476+
return Ok(None);
1477+
}
14741478
debug_assert!(
1475-
matches!(result_ty, ValType::I32 | ValType::I64),
1476-
"unexpected condition type: {result_ty:?}"
1479+
RegKind::Ireg.matches_ty(condition_ty),
1480+
"unexpected condition type: {condition_ty:?}"
14771481
);
14781482
let cmp_op = match negate {
14791483
false => staged_op,

crates/wast/tests/wasmi

0 commit comments

Comments
 (0)