- Notifications
You must be signed in to change notification settings - Fork15.3k
Open
Labels
Description
The following IR (compiler explorer):
targettriple ="wasm32-unknown-wasi"definehalf@f(half%x) {start:%y =fmulhalf%x, 0xH4000; 0xH4000 == 2.0%z =fdivhalf%y, 0xH4000; 0xH4000 == 2.0rethalf%z}definehalf@callf() {%res =callhalf@f(half 0xH7BFF); 0xH7BFF = maximum finite `f16`rethalf%res}
Is compiled into the following WASM:
f: # @flocal.get0call __truncsfhf2call __extendhfsf2local.tee0local.get0f32.addf32.const0x1p-1f32.mul end_functioncallf: # @callff32.const0x1.ffcp15call f end_function
callf should return positive infinity (0xH7C00), but on WASM it will return0xH7BFF due to the extra range of thef32 used to store the intermediate result.
This Rust program, when compiled withrustc 1.81.0-nightly (3cb521a43 2024-06-22) withrustc --target wasm32-wasip1 code.rs and run withwasmtime, demonstrates the issue.
#![feature(f16)]fnf(x:f16) ->f16{x*2.0 /2.0}fnmain(){assert_eq!(f(f16::MAX),1.0 /0.0);}
The assertion should succeed, but on WASM it fails.