Skip to content

Commit d1ecc1f

Browse files
authored
Make narrowing float->int casts on wasm go via wider ints (#7973)
Fixes #7972
1 parent 6e57d6c commit d1ecc1f

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/CodeGen_WebAssembly.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,17 @@ void CodeGen_WebAssembly::visit(const Cast *op) {
175175
}
176176
}
177177
}
178+
179+
// Narrowing float -> int casts should go via an integer type of the
180+
// matching width (see https://github.com/halide/Halide/issues/7972)
181+
if (op->value.type().is_float() &&
182+
(op->type.is_int() || op->type.is_uint()) &&
183+
op->type.bits() < op->value.type().bits()) {
184+
Expr equiv = Cast::make(op->type.with_bits(op->value.type().bits()), op->value);
185+
equiv = Cast::make(op->type, equiv);
186+
codegen(equiv);
187+
return;
188+
}
178189
}
179190

180191
CodeGen_Posix::visit(op);

0 commit comments

Comments
 (0)