Stream: git-wasmtime

Topic: wasmtime / issue #12336 Cranelift: NaN canonicalization p...


view this post on Zulip Wasmtime GitHub notifications bot (Jan 13 2026 at 22:09):

zzjas opened issue #12336:

.clif Test Case

test compile
set enable_nan_canonicalization=true
target s390x

function %fadd_f128(i64, f128, f128) {
block0(v0: i64, v1: f128, v2: f128):
    v3 = fadd v1, v2
    store v3, v0
    return
}

Steps to Reproduce

RUST_BACKTRACE=1 cargo run -p cranelift-tools -- test test.clif

Expected Results

No crash

Actual Results

thread 'worker #0' (2560515) panicked at cranelift/codegen/src/nan_canonicalization.rs:121:13:
Could not canonicalize NaN: Unexpected result type found.

Versions and Environment

Cranelift version or commit: e82a7abfd3e88145450a5465def20f6781e0eb65

Extra Info

F16 (on RISC-V with zfh) and F128 (on s390x) are valid floating-point types that pass the is_fp_arith() check in nan_canonicalization.rs but fall through to the panic in add_nan_canon_seq():

https://github.com/bytecodealliance/wasmtime/blob/e82a7abfd3e88145450a5465def20f6781e0eb65/cranelift/codegen/src/nan_canonicalization.rs#L92-L123

Adding the following arm will fix the F128 for s390x:

        types::F128 => {
            let nan_const = pos.func.dfg.constants.insert(Ieee128::NAN.into());
            let canon_nan = pos.ins().f128const(nan_const);
            scalar_select(pos, canon_nan);
        }

I'm not sure if F16 needs to be fixed because of #7322.

Thanks for looking into this and I'm happy to submit a PR if the fix to F128 looks ok.

view this post on Zulip Wasmtime GitHub notifications bot (Jan 13 2026 at 22:09):

zzjas added the bug label to Issue #12336.

view this post on Zulip Wasmtime GitHub notifications bot (Jan 13 2026 at 22:09):

zzjas added the cranelift label to Issue #12336.

view this post on Zulip Wasmtime GitHub notifications bot (Jan 13 2026 at 22:45):

alexcrichton commented on issue #12336:

I think it'd be reasonable to add support to the nan_canonicalization.rs pass for this yeah, and if you're willing to make a PR that'd be much appreciated!

view this post on Zulip Wasmtime GitHub notifications bot (Jan 13 2026 at 23:05):

zzjas commented on issue #12336:

Happy to make a PR! Just to confirm, do you think just fixing for F128 is enough or would it better to fix for both F128 and F16? Thanks!

view this post on Zulip Wasmtime GitHub notifications bot (Jan 13 2026 at 23:12):

alexcrichton commented on issue #12336:

I'd personally leave that call to you as a subjective balance between implementation complexity and how motivated you are. Cranelift is probably going to have somewhat patchy support for f16/f128 for awhile unless a particularly motivated contributor comes by, so the exact state of support to me I think is fine with whatever so long as it's incrementally moving forward

view this post on Zulip Wasmtime GitHub notifications bot (Jan 14 2026 at 00:23):

cfallin closed issue #12336:

.clif Test Case

test compile
set enable_nan_canonicalization=true
target s390x

function %fadd_f128(i64, f128, f128) {
block0(v0: i64, v1: f128, v2: f128):
    v3 = fadd v1, v2
    store v3, v0
    return
}

Steps to Reproduce

RUST_BACKTRACE=1 cargo run -p cranelift-tools -- test test.clif

Expected Results

No crash

Actual Results

thread 'worker #0' (2560515) panicked at cranelift/codegen/src/nan_canonicalization.rs:121:13:
Could not canonicalize NaN: Unexpected result type found.

Versions and Environment

Cranelift version or commit: e82a7abfd3e88145450a5465def20f6781e0eb65

Extra Info

F16 (on RISC-V with zfh) and F128 (on s390x) are valid floating-point types that pass the is_fp_arith() check in nan_canonicalization.rs but fall through to the panic in add_nan_canon_seq():

https://github.com/bytecodealliance/wasmtime/blob/e82a7abfd3e88145450a5465def20f6781e0eb65/cranelift/codegen/src/nan_canonicalization.rs#L92-L123

Adding the following arm will fix the F128 for s390x:

        types::F128 => {
            let nan_const = pos.func.dfg.constants.insert(Ieee128::NAN.into());
            let canon_nan = pos.ins().f128const(nan_const);
            scalar_select(pos, canon_nan);
        }

I'm not sure if F16 needs to be fixed because of #7322.

Thanks for looking into this and I'm happy to submit a PR if the fix to F128 looks ok.


Last updated: Jan 29 2026 at 13:25 UTC