Stream: git-wasmtime

Topic: wasmtime / PR #15349 cranelift: fix x64 saturating add/su...


view this post on Zulip Wasmtime GitHub notifications bot (Nov 18 2026 at 17:17):

ColonelToad removed the review request for wasmtime-compiler-reviewers from PR #15349.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 18 2026 at 17:17):

ColonelToad opened PR #15349 from ColonelToad:fix/15279-x64-sat-load to bytecodealliance:main:

Fixes #15279.

On x64, sadd_sat/ssub_sat of 32- and 64-bit lanes have no single
instruction, so they are lowered as a wrapping add/sub followed by overflow
detection. The detection reuses both operands, but the second operand of the
wrapping operation is an XmmMem128:

function %f(i32x4, i64) -> i32x4 {
block0(v0: i32x4, v1: i64):
    v2 = load.i32x4 v1
    v3 = sadd_sat v0, v2
    return v3
}
The load is sunk into the wrapping vpaddd as a memory operand, and the
overflow detection then asks for the same value in a register, which trips the
inst_sunk assertion in put_value_in_regs.
Materialize both operands in registers before the wrapping operation. The
loaded operand becomes a vmovdqu that is reused by the detection instead of
being folded into the arithmetic. This fixes all four affected forms
(sadd_sat/ssub_sat for i32x4/i64x2).
I kept the fix in the lowering rules rather than in the sink logic: the CLIF
value still has a single use and only the rule knows it is consumed twice, so
this is the conservative place to make the register requirement explicit.
Tests:
- New cranelift/filetests/filetests/isa/x64/sat-arith-load.clif covering
sadd_sat/ssub_sat for i32x4/i64x2 with a loaded operand, plus a
two-load case.
- cargo test -p cranelift-tools --test logged-filetests
- cargo test -p cranelift-codegen
AI tool usage: I used an AI coding assistant (DeepSeek V4.1 Flash via OpenCode)
to help draft this patch and its tests. I reviewed every change, ran the
relevant tests locally, and can explain the reasoning behind the
implementation.
````

view this post on Zulip Wasmtime GitHub notifications bot (Nov 18 2026 at 17:17):

ColonelToad requested cfallin for a review on PR #15349.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 18 2026 at 17:17):

ColonelToad requested wasmtime-compiler-reviewers for a review on PR #15349.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 18 2026 at 18:09):

alexcrichton edited PR #15349:

Fixes #15279.

On x64, sadd_sat/ssub_sat of 32- and 64-bit lanes have no single
instruction, so they are lowered as a wrapping add/sub followed by overflow
detection. The detection reuses both operands, but the second operand of the
wrapping operation is an XmmMem128:

function %f(i32x4, i64) -> i32x4 {
block0(v0: i32x4, v1: i64):
    v2 = load.i32x4 v1
    v3 = sadd_sat v0, v2
    return v3
}

The load is sunk into the wrapping vpaddd as a memory operand, and the
overflow detection then asks for the same value in a register, which trips the
inst_sunk assertion in put_value_in_regs.
Materialize both operands in registers before the wrapping operation. The
loaded operand becomes a vmovdqu that is reused by the detection instead of
being folded into the arithmetic. This fixes all four affected forms
(sadd_sat/ssub_sat for i32x4/i64x2).
I kept the fix in the lowering rules rather than in the sink logic: the CLIF
value still has a single use and only the rule knows it is consumed twice, so
this is the conservative place to make the register requirement explicit.
Tests:

view this post on Zulip Wasmtime GitHub notifications bot (Nov 18 2026 at 20:44):

github-actions[bot] added the label cranelift:area:x64 on PR #15349.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 18 2026 at 20:44):

github-actions[bot] added the label cranelift on PR #15349.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 18 2026 at 22:01):

:thumbs_up: cfallin submitted PR review:

Thanks!

view this post on Zulip Wasmtime GitHub notifications bot (Nov 18 2026 at 22:01):

cfallin added PR #15349 cranelift: fix x64 saturating add/sub lowering with memory operands to the merge queue.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 18 2026 at 22:24):

:check: cfallin merged PR #15349.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 18 2026 at 22:24):

cfallin removed PR #15349 cranelift: fix x64 saturating add/sub lowering with memory operands from the merge queue.


Last updated: Nov 19 2026 at 20:05 UTC