Stream: git-wasmtime

Topic: wasmtime / issue #15262 Cranelift: aarch64: floats live a...


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

kestred opened issue #15262:

.clif Test Case

A loop that calls a function and keeps three f64 values live across the call: the call's argument v0, the factor
v1 and the running sum v6. The function has no vector value.

function %f(f64, f64, i64) -> f64 {
    sig0 = (f64) -> f64
    fn0 = %g sig0

block0(v0: f64, v1: f64, v2: i64):
    v3 = iconst.i64 0
    v4 = f64const 0.0
    v12 = iconst.i64 1
    jump block1(v3, v4)

block1(v5: i64, v6: f64):
    v7 = call fn0(v0)
    v8 = fmul v7, v1
    v9 = fadd v6, v8
    v10 = iadd v5, v12
    v11 = icmp ult v10, v2
    brif v11, block1(v10, v9), block2

block2:
    return v9
}
test run
target aarch64

; Writes whole q registers under high pressure, so that it uses v8 - v15 and,
; as AAPCS lets it, returns with only their low halves restored.
function %clobber_vectors(f64) -> f64 {
block0(v0: f64):
    v1 = splat.f64x2 v0
    v2 = fadd v1, v1
    v3 = fadd v2, v1
    v4 = fadd v3, v2
    v5 = fadd v4, v3
    v6 = fadd v5, v4
    v7 = fadd v6, v5
    v8 = fadd v7, v6
    v9 = fadd v8, v7
    v10 = fadd v9, v8
    v11 = fadd v10, v9
    v12 = fadd v11, v10
    v13 = fadd v12, v11
    v14 = fadd v13, v12
    v15 = fadd v14, v13
    v16 = fadd v15, v14
    v17 = fadd v16, v15
    v18 = fadd v17, v16
    v19 = fadd v18, v17
    v20 = fadd v19, v18
    v21 = fadd v20, v19
    v22 = fadd v21, v20
    v23 = fadd v22, v21
    v24 = fadd v23, v22
    v25 = fadd v24, v23
    v26 = fadd v25, v24
    v27 = fadd v26, v25
    v28 = fadd v27, v26
    v29 = fadd v28, v27
    v30 = fadd v29, v28
    v31 = fadd v30, v29
    v32 = fadd v31, v30
    v33 = fadd v32, v31
    v40 = fadd v1, v2
    v41 = fadd v40, v3
    v42 = fadd v41, v4
    v43 = fadd v42, v5
    v44 = fadd v43, v6
    v45 = fadd v44, v7
    v46 = fadd v45, v8
    v47 = fadd v46, v9
    v48 = fadd v47, v10
    v49 = fadd v48, v11
    v50 = fadd v49, v12
    v51 = fadd v50, v13
    v52 = fadd v51, v14
    v53 = fadd v52, v15
    v54 = fadd v53, v16
    v55 = fadd v54, v17
    v56 = fadd v55, v18
    v57 = fadd v56, v19
    v58 = fadd v57, v20
    v59 = fadd v58, v21
    v60 = fadd v59, v22
    v61 = fadd v60, v23
    v62 = fadd v61, v24
    v63 = fadd v62, v25
    v64 = fadd v63, v26
    v65 = fadd v64, v27
    v66 = fadd v65, v28
    v67 = fadd v66, v29
    v68 = fadd v67, v30
    v69 = fadd v68, v31
    v70 = fadd v69, v32
    v71 = fadd v70, v33
    v72 = extractlane v71, 1
    return v72
}

; No vector: the scalars stay in v8 - v15 across the call.
function %scalar_caller(f64, f64, f64) -> f64 {
    fn0 = colocated %clobber_vectors(f64) -> f64

block0(v0: f64, v1: f64, v2: f64):
    v3 = call fn0(v0)
    v4 = fmul v1, v2
    v5 = fadd v4, v1
    v6 = fadd v5, v2
    return v6
}
; run: %scalar_caller(0x1.0, 0x3.0, 0x5.0) == 0x17.0

; A vector live across the call: v8 - v15 stay clobbered, so it is spilled.
function %vector_caller(f64, f64) -> f64 {
    fn0 = colocated %clobber_vectors(f64) -> f64

block0(v0: f64, v1: f64):
    v2 = splat.f64x2 v1
    v3 = call fn0(v0)
    v4 = extractlane v2, 1
    v5 = fadd v4, v1
    return v5
}
; run: %vector_caller(0x1.0, 0x3.0) == 0x6.0

Steps to Reproduce

Expected Results

The loop keeps v0, v1 and v6 in v8–v15 across the call, with no load or store per iteration. AAPCS64 preserves
the low 64 bits of those registers, which is all of an f64, and the prologue saves the ones that the function
uses. With the patch, the loop from 0x2c to 0x70 moves the values between registers, and the prologue saves d8,
d9 and d15 once:

Disassembly of 136 bytes <%f>:
0:  stp x29, x30, [sp, #-0x10]!
4:  mov x29, sp
8:  stp x19, x20, [sp, #-0x10]!
c:  str d15, [sp, #-0x10]!
10:  stp    d8, d9, [sp, #-0x10]!
14:  mov    x20, x0
18:  mov    v8.16b, v0.16b
1c:  mov    v15.16b, v1.16b
20:  mov    x19, #0
24:  movi   v0.2s, #0
28:  mov    v9.16b, v0.16b
2c:  ldr    x13, #0x34
30:  b  #0x3c
34:  udf    #0
38:  udf    #0
3c:  mov    v0.16b, v8.16b
40:  blr    x13
44:  add    x19, x19, #1
48:  mov    v1.16b, v15.16b
4c:  fmul   d16, d0, d1
50:  mov    v0.16b, v9.16b
54:  fadd   d0, d0, d16
58:  mov    x0, x20
5c:  cmp    x19, x0
60:  b.hs   #0x74
64:  mov    x20, x0
68:  mov    v9.16b, v0.16b
6c:  mov    v15.16b, v1.16b
70:  b  #0x2c
74:  ldp    d8, d9, [sp], #0x10
78:  ldr    d15, [sp], #0x10
7c:  ldp    x19, x20, [sp], #0x10
80:  ldp    x29, x30, [sp], #0x10
84:  ret

Actual Results

Every iteration stores and reloads the floats: the loop from 0x28 to 0x6c has three 128-bit loads (ldur q) and
two 128-bit stores (stur q), to keep values that the callee would have preserved:

Disassembly of 128 bytes <%f>:
0:  stp x29, x30, [sp, #-0x10]!
4:  mov x29, sp
8:  stp x19, x20, [sp, #-0x10]!
c:  sub sp, sp, #0x30
10:  mov    x20, x0
14:  stur   q0, [sp]
18:  stur   q1, [sp, #0x10]
1c:  mov    x19, #0
20:  movi   v0.2s, #0
24:  stur   q0, [sp, #0x20]
28:  ldr    x13, #0x30
2c:  b  #0x38
30:  udf    #0
34:  udf    #0
38:  ldur   q0, [sp]
3c:  blr    x13
40:  add    x19, x19, #1
44:  ldur   q1, [sp, #0x10]
48:  fmul   d16, d0, d1
4c:  ldur   q0, [sp, #0x20]
50:  fadd   d0, d0, d16
54:  mov    x0, x20
58:  cmp    x19, x0
5c:  b.hs   #0x70
60:  mov    x20, x0
64:  stur   q1, [sp, #0x10]
68:  stur   q0, [sp, #0x20]
6c:  b  #0x28
70:  add    sp, sp, #0x30
74:  ldp    x19, x20, [sp], #0x10
78:  ldp    x29, x30, [sp], #0x10
7c:  ret

Versions and Environment

Cranelift version or commit: cranelift-codegen 0.137.0, with regalloc2 0.15.2, built into clif-util from wasmtime
v50.0.0 (commit ebe5e8df1f4e12c5fc2f5954926881d8d61367d8) with rustc 1.98.0, --release and default features.

Operating system: macOS 26.6.2 (build 25G83).

Architecture: arm64 (Apple M5 Pro), compiling for --target aarch64.

Extra Info

The limitation. default_aapcs_clobbers() in isa/aarch64/abi.rs says:

The upper 64 bits of v8 - v15 inclusive are also caller-saves. However, because we cannot currently represent
partial registers to regalloc2, we indicate here that every vector register is caller-save. Because this function
is used at callsites, approximating in this direction (save more than necessary) is conservative and thus safe.

This stopgap was chosen in #2254 and #2267, where a follow-up was noted so that prologues and epilogues deal only with
the lower 64 bits. In regalloc2, partial registers are out of scope (bytecodealliance/regalloc2#247).

The proposal. A function with no value wider than 64 bits loses nothing when a call clobbers only the upper
halves of v8–v15, so it can drop them from that call's clobbers without regalloc2 knowing about partial registers:

There is no new setting and no call for the embedder to make. The other users of the static clobber sets are
unchanged and stay conservative. s390x carries the same comment and could opt in the same way.

Soundness.

Evidence. With the patch, two aarch64 filetests change when blessed: in call.clif and user_stack_maps.clif,
the q-register spills become mov to v8–v15, and the prologue saves d8, d11, d12 or d15 with stp or
str. Stock clif-util fails both blessed files. With the patch and the blessed files,

target/release/clif-util test cranelift/filetests/filetests

printed 1322 tests with no failure. A runtime test, 1-run.clif beside this issue, calls a function that writes
all 128 bits of v8–v15 from a caller that keeps scalars in them across the call:

target/release/clif-util test 1-run.clif

It printed 1 tests with no failure, with and without the patch. With its expected value changed from 0x17.0 to
0x18.0, it failed with actual: 0x1.7000000000000p4, which shows that the test runs.

A precise alternative would be per-value partial clobbers in regalloc2.

<details><summary>Patch against cranelift-codegen 0.137.0</summary>

diff --git a/cranelift/codegen/src/isa/aarch64/abi.rs b/cranelift/codegen/src/isa/aarch64/abi.rs
index 8659561..8c953bc 100644
--- a/cranelift/codegen/src/isa/aarch64/abi.rs
+++ b/cranelift/codegen/src/isa/aarch64/abi.rs
@@ -1210,6 +1210,20 @@ impl ABIMachineSpec for AArch64MachineDeps {
         }
     }

+    fn get_regs_partially_clobbered_by_call(
+        call_conv: isa::CallConv,
+        is_exception: bool,
+    ) -> PRegSet {
+        // A callee that follows AAPCS64 preserves the low 64 bits of v8 - v15,

[message truncated]

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

kestred added the bug label to Issue #15262.

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

kestred added the cranelift label to Issue #15262.

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

alexcrichton added the cranelift:area:aarch64 label to Issue #15262.

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

kestred edited issue #15262:

.clif Test Case

A loop that calls a function and keeps three f64 values live across the call: the call's argument v0, the factor
v1 and the running sum v6. The function has no vector value.

test.clif

function %f(f64, f64, i64) -> f64 {
    sig0 = (f64) -> f64
    fn0 = %g sig0

block0(v0: f64, v1: f64, v2: i64):
    v3 = iconst.i64 0
    v4 = f64const 0.0
    v12 = iconst.i64 1
    jump block1(v3, v4)

block1(v5: i64, v6: f64):
    v7 = call fn0(v0)
    v8 = fmul v7, v1
    v9 = fadd v6, v8
    v10 = iadd v5, v12
    v11 = icmp ult v10, v2
    brif v11, block1(v10, v9), block2

block2:
    return v9
}

run.clif

test run
target aarch64

; Writes whole q registers under high pressure, so that it uses v8 - v15 and,
; as AAPCS lets it, returns with only their low halves restored.
function %clobber_vectors(f64) -> f64 {
block0(v0: f64):
    v1 = splat.f64x2 v0
    v2 = fadd v1, v1
    v3 = fadd v2, v1
    v4 = fadd v3, v2
    v5 = fadd v4, v3
    v6 = fadd v5, v4
    v7 = fadd v6, v5
    v8 = fadd v7, v6
    v9 = fadd v8, v7
    v10 = fadd v9, v8
    v11 = fadd v10, v9
    v12 = fadd v11, v10
    v13 = fadd v12, v11
    v14 = fadd v13, v12
    v15 = fadd v14, v13
    v16 = fadd v15, v14
    v17 = fadd v16, v15
    v18 = fadd v17, v16
    v19 = fadd v18, v17
    v20 = fadd v19, v18
    v21 = fadd v20, v19
    v22 = fadd v21, v20
    v23 = fadd v22, v21
    v24 = fadd v23, v22
    v25 = fadd v24, v23
    v26 = fadd v25, v24
    v27 = fadd v26, v25
    v28 = fadd v27, v26
    v29 = fadd v28, v27
    v30 = fadd v29, v28
    v31 = fadd v30, v29
    v32 = fadd v31, v30
    v33 = fadd v32, v31
    v40 = fadd v1, v2
    v41 = fadd v40, v3
    v42 = fadd v41, v4
    v43 = fadd v42, v5
    v44 = fadd v43, v6
    v45 = fadd v44, v7
    v46 = fadd v45, v8
    v47 = fadd v46, v9
    v48 = fadd v47, v10
    v49 = fadd v48, v11
    v50 = fadd v49, v12
    v51 = fadd v50, v13
    v52 = fadd v51, v14
    v53 = fadd v52, v15
    v54 = fadd v53, v16
    v55 = fadd v54, v17
    v56 = fadd v55, v18
    v57 = fadd v56, v19
    v58 = fadd v57, v20
    v59 = fadd v58, v21
    v60 = fadd v59, v22
    v61 = fadd v60, v23
    v62 = fadd v61, v24
    v63 = fadd v62, v25
    v64 = fadd v63, v26
    v65 = fadd v64, v27
    v66 = fadd v65, v28
    v67 = fadd v66, v29
    v68 = fadd v67, v30
    v69 = fadd v68, v31
    v70 = fadd v69, v32
    v71 = fadd v70, v33
    v72 = extractlane v71, 1
    return v72
}

; No vector: the scalars stay in v8 - v15 across the call.
function %scalar_caller(f64, f64, f64) -> f64 {
    fn0 = colocated %clobber_vectors(f64) -> f64

block0(v0: f64, v1: f64, v2: f64):
    v3 = call fn0(v0)
    v4 = fmul v1, v2
    v5 = fadd v4, v1
    v6 = fadd v5, v2
    return v6
}
; run: %scalar_caller(0x1.0, 0x3.0, 0x5.0) == 0x17.0

; A vector live across the call: v8 - v15 stay clobbered, so it is spilled.
function %vector_caller(f64, f64) -> f64 {
    fn0 = colocated %clobber_vectors(f64) -> f64

block0(v0: f64, v1: f64):
    v2 = splat.f64x2 v1
    v3 = call fn0(v0)
    v4 = extractlane v2, 1
    v5 = fadd v4, v1
    return v5
}
; run: %vector_caller(0x1.0, 0x3.0) == 0x6.0

Steps to Reproduce

Expected Results

The loop keeps v0, v1 and v6 in v8–v15 across the call, with no load or store per iteration. AAPCS64 preserves
the low 64 bits of those registers, which is all of an f64, and the prologue saves the ones that the function
uses. With the patch, the loop from 0x2c to 0x70 moves the values between registers, and the prologue saves d8,
d9 and d15 once:

Disassembly of 136 bytes <%f>:
0:  stp x29, x30, [sp, #-0x10]!
4:  mov x29, sp
8:  stp x19, x20, [sp, #-0x10]!
c:  str d15, [sp, #-0x10]!
10:  stp    d8, d9, [sp, #-0x10]!
14:  mov    x20, x0
18:  mov    v8.16b, v0.16b
1c:  mov    v15.16b, v1.16b
20:  mov    x19, #0
24:  movi   v0.2s, #0
28:  mov    v9.16b, v0.16b
2c:  ldr    x13, #0x34
30:  b  #0x3c
34:  udf    #0
38:  udf    #0
3c:  mov    v0.16b, v8.16b
40:  blr    x13
44:  add    x19, x19, #1
48:  mov    v1.16b, v15.16b
4c:  fmul   d16, d0, d1
50:  mov    v0.16b, v9.16b
54:  fadd   d0, d0, d16
58:  mov    x0, x20
5c:  cmp    x19, x0
60:  b.hs   #0x74
64:  mov    x20, x0
68:  mov    v9.16b, v0.16b
6c:  mov    v15.16b, v1.16b
70:  b  #0x2c
74:  ldp    d8, d9, [sp], #0x10
78:  ldr    d15, [sp], #0x10
7c:  ldp    x19, x20, [sp], #0x10
80:  ldp    x29, x30, [sp], #0x10
84:  ret

Actual Results

Every iteration stores and reloads the floats: the loop from 0x28 to 0x6c has three 128-bit loads (ldur q) and
two 128-bit stores (stur q), to keep values that the callee would have preserved:

Disassembly of 128 bytes <%f>:
0:  stp x29, x30, [sp, #-0x10]!
4:  mov x29, sp
8:  stp x19, x20, [sp, #-0x10]!
c:  sub sp, sp, #0x30
10:  mov    x20, x0
14:  stur   q0, [sp]
18:  stur   q1, [sp, #0x10]
1c:  mov    x19, #0
20:  movi   v0.2s, #0
24:  stur   q0, [sp, #0x20]
28:  ldr    x13, #0x30
2c:  b  #0x38
30:  udf    #0
34:  udf    #0
38:  ldur   q0, [sp]
3c:  blr    x13
40:  add    x19, x19, #1
44:  ldur   q1, [sp, #0x10]
48:  fmul   d16, d0, d1
4c:  ldur   q0, [sp, #0x20]
50:  fadd   d0, d0, d16
54:  mov    x0, x20
58:  cmp    x19, x0
5c:  b.hs   #0x70
60:  mov    x20, x0
64:  stur   q1, [sp, #0x10]
68:  stur   q0, [sp, #0x20]
6c:  b  #0x28
70:  add    sp, sp, #0x30
74:  ldp    x19, x20, [sp], #0x10
78:  ldp    x29, x30, [sp], #0x10
7c:  ret

Versions and Environment

Cranelift version or commit: cranelift-codegen 0.137.0, with regalloc2 0.15.2, built into clif-util from wasmtime
v50.0.0 (commit ebe5e8df1f4e12c5fc2f5954926881d8d61367d8) with rustc 1.98.0, --release and default features.

Operating system: macOS 26.6.2 (build 25G83).

Architecture: arm64 (Apple M5 Pro), compiling for --target aarch64.

Extra Info

The limitation. default_aapcs_clobbers() in isa/aarch64/abi.rs says:

The upper 64 bits of v8 - v15 inclusive are also caller-saves. However, because we cannot currently represent
partial registers to regalloc2, we indicate here that every vector register is caller-save. Because this function
is used at callsites, approximating in this direction (save more than necessary) is conservative and thus safe.

This stopgap was chosen in #2254 and #2267, where a follow-up was noted so that prologues and epilogues deal only with
the lower 64 bits. In regalloc2, partial registers are out of scope (bytecodealliance/regalloc2#247).

The proposal. A function with no value wider than 64 bits loses nothing when a call clobbers only the upper
halves of v8–v15, so it can drop them from that call's clobbers without regalloc2 knowing about partial registers:

There is no new setting and no call for the embedder to make. The other users of the static clobber sets are
unchanged and stay conservative. s390x carries the same comment and could opt in the same way.

Soundness.

Evidence. With the patch, two aarch64 filetests change when blessed: in call.clif and user_stack_maps.clif,
the q-register spills become mov to v8–v15, and the prologue saves d8, d11, d12 or d15 with stp or
str. Stock clif-util fails both blessed files. With the patch and the blessed files,

target/release/clif-util test cranelift/filetests/filetests

printed 1322 tests with no failure. A runtime test, run.clif beside this issue, calls a function that writes
all 128 bits of v8–v15 from a caller that keeps scalars in them across the call:

target/release/clif-util test run.clif

It printed 1 tests with no failure, with and without the patch. With its expected value changed from 0x17.0 to
0x18.0, it failed with actual: 0x1.7000000000000p4, which shows that the test runs.

A precise alternative would be per-value partial clobbers in regalloc2.

<details><summary>Patch against cranelift-codegen 0.137.0</summary>

diff --git a/cranelift/codegen/src/isa/aarch64/abi.rs b/cranelift/codegen/src/isa/aarch64/abi.rs
index 8659561..8c953bc 100644
--- a/cranelift/codegen/src/isa/aarch64/abi.rs
+++ b/cranelift/codegen/src/isa/aarch64/abi.rs
@@ -1210,6 +1210,20 @@ impl ABIMachineSpec for AArch64MachineDeps {
         }
     }

+    fn get_regs_partially_clobbered_by_call(
+        call_conv: isa::CallConv,
+        is_exception: bool,
+    ) -> PRegSet {
+        // A callee that follows AAPCS64 preserves the
[message truncated]

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

kestred edited issue #15262:

.clif Test Case

A loop that calls a function and keeps three f64 values live across the call: the call's argument v0, the factor
v1 and the running sum v6. The function has no vector value.

test.clif

function %f(f64, f64, i64) -> f64 {
    sig0 = (f64) -> f64
    fn0 = %g sig0

block0(v0: f64, v1: f64, v2: i64):
    v3 = iconst.i64 0
    v4 = f64const 0.0
    v12 = iconst.i64 1
    jump block1(v3, v4)

block1(v5: i64, v6: f64):
    v7 = call fn0(v0)
    v8 = fmul v7, v1
    v9 = fadd v6, v8
    v10 = iadd v5, v12
    v11 = icmp ult v10, v2
    brif v11, block1(v10, v9), block2

block2:
    return v9
}

Steps to Reproduce

Expected Results

The loop keeps v0, v1 and v6 in v8–v15 across the call, with no load or store per iteration. AAPCS64 preserves
the low 64 bits of those registers, which is all of an f64, and the prologue saves the ones that the function
uses. With the patch, the loop from 0x2c to 0x70 moves the values between registers, and the prologue saves d8,
d9 and d15 once:

Disassembly of 136 bytes <%f>:
0:  stp x29, x30, [sp, #-0x10]!
4:  mov x29, sp
8:  stp x19, x20, [sp, #-0x10]!
c:  str d15, [sp, #-0x10]!
10:  stp    d8, d9, [sp, #-0x10]!
14:  mov    x20, x0
18:  mov    v8.16b, v0.16b
1c:  mov    v15.16b, v1.16b
20:  mov    x19, #0
24:  movi   v0.2s, #0
28:  mov    v9.16b, v0.16b
2c:  ldr    x13, #0x34
30:  b  #0x3c
34:  udf    #0
38:  udf    #0
3c:  mov    v0.16b, v8.16b
40:  blr    x13
44:  add    x19, x19, #1
48:  mov    v1.16b, v15.16b
4c:  fmul   d16, d0, d1
50:  mov    v0.16b, v9.16b
54:  fadd   d0, d0, d16
58:  mov    x0, x20
5c:  cmp    x19, x0
60:  b.hs   #0x74
64:  mov    x20, x0
68:  mov    v9.16b, v0.16b
6c:  mov    v15.16b, v1.16b
70:  b  #0x2c
74:  ldp    d8, d9, [sp], #0x10
78:  ldr    d15, [sp], #0x10
7c:  ldp    x19, x20, [sp], #0x10
80:  ldp    x29, x30, [sp], #0x10
84:  ret

Actual Results

Every iteration stores and reloads the floats: the loop from 0x28 to 0x6c has three 128-bit loads (ldur q) and
two 128-bit stores (stur q), to keep values that the callee would have preserved:

Disassembly of 128 bytes <%f>:
0:  stp x29, x30, [sp, #-0x10]!
4:  mov x29, sp
8:  stp x19, x20, [sp, #-0x10]!
c:  sub sp, sp, #0x30
10:  mov    x20, x0
14:  stur   q0, [sp]
18:  stur   q1, [sp, #0x10]
1c:  mov    x19, #0
20:  movi   v0.2s, #0
24:  stur   q0, [sp, #0x20]
28:  ldr    x13, #0x30
2c:  b  #0x38
30:  udf    #0
34:  udf    #0
38:  ldur   q0, [sp]
3c:  blr    x13
40:  add    x19, x19, #1
44:  ldur   q1, [sp, #0x10]
48:  fmul   d16, d0, d1
4c:  ldur   q0, [sp, #0x20]
50:  fadd   d0, d0, d16
54:  mov    x0, x20
58:  cmp    x19, x0
5c:  b.hs   #0x70
60:  mov    x20, x0
64:  stur   q1, [sp, #0x10]
68:  stur   q0, [sp, #0x20]
6c:  b  #0x28
70:  add    sp, sp, #0x30
74:  ldp    x19, x20, [sp], #0x10
78:  ldp    x29, x30, [sp], #0x10
7c:  ret

Versions and Environment

Cranelift version or commit: cranelift-codegen 0.137.0, with regalloc2 0.15.2, built into clif-util from wasmtime
v50.0.0 (commit ebe5e8df1f4e12c5fc2f5954926881d8d61367d8) with rustc 1.98.0, --release and default features.

Operating system: macOS 26.6.2 (build 25G83).

Architecture: arm64 (Apple M5 Pro), compiling for --target aarch64.

Extra Info

The limitation. default_aapcs_clobbers() in isa/aarch64/abi.rs says:

The upper 64 bits of v8 - v15 inclusive are also caller-saves. However, because we cannot currently represent
partial registers to regalloc2, we indicate here that every vector register is caller-save. Because this function
is used at callsites, approximating in this direction (save more than necessary) is conservative and thus safe.

This stopgap was chosen in #2254 and #2267, where a follow-up was noted so that prologues and epilogues deal only with
the lower 64 bits. In regalloc2, partial registers are out of scope (bytecodealliance/regalloc2#247).

The proposal. A function with no value wider than 64 bits loses nothing when a call clobbers only the upper
halves of v8–v15, so it can drop them from that call's clobbers without regalloc2 knowing about partial registers:

There is no new setting and no call for the embedder to make. The other users of the static clobber sets are
unchanged and stay conservative. s390x carries the same comment and could opt in the same way.

Soundness.

Evidence. With the patch, two aarch64 filetests change when blessed: in call.clif and user_stack_maps.clif,
the q-register spills become mov to v8–v15, and the prologue saves d8, d11, d12 or d15 with stp or
str. Stock clif-util fails both blessed files. With the patch and the blessed files,

target/release/clif-util test cranelift/filetests/filetests

printed 1322 tests with no failure. The following test, run.clif calls a function that writes
all 128 bits of v8–v15 from a caller that keeps scalars in them across the call:

<details><summary>run.clif</summary>

test run
target aarch64

; Writes whole q registers under high pressure, so that it uses v8 - v15 and,
; as AAPCS lets it, returns with only their low halves restored.
function %clobber_vectors(f64) -> f64 {
block0(v0: f64):
    v1 = splat.f64x2 v0
    v2 = fadd v1, v1
    v3 = fadd v2, v1
    v4 = fadd v3, v2
    v5 = fadd v4, v3
    v6 = fadd v5, v4
    v7 = fadd v6, v5
    v8 = fadd v7, v6
    v9 = fadd v8, v7
    v10 = fadd v9, v8
    v11 = fadd v10, v9
    v12 = fadd v11, v10
    v13 = fadd v12, v11
    v14 = fadd v13, v12
    v15 = fadd v14, v13
    v16 = fadd v15, v14
    v17 = fadd v16, v15
    v18 = fadd v17, v16
    v19 = fadd v18, v17
    v20 = fadd v19, v18
    v21 = fadd v20, v19
    v22 = fadd v21, v20
    v23 = fadd v22, v21
    v24 = fadd v23, v22
    v25 = fadd v24, v23
    v26 = fadd v25, v24
    v27 = fadd v26, v25
    v28 = fadd v27, v26
    v29 = fadd v28, v27
    v30 = fadd v29, v28
    v31 = fadd v30, v29
    v32 = fadd v31, v30
    v33 = fadd v32, v31
    v40 = fadd v1, v2
    v41 = fadd v40, v3
    v42 = fadd v41, v4
    v43 = fadd v42, v5
    v44 = fadd v43, v6
    v45 = fadd v44, v7
    v46 = fadd v45, v8
    v47 = fadd v46, v9
    v48 = fadd v47, v10
    v49 = fadd v48, v11
    v50 = fadd v49, v12
    v51 = fadd v50, v13
    v52 = fadd v51, v14
    v53 = fadd v52, v15
    v54 = fadd v53, v16
    v55 = fadd v54, v17
    v56 = fadd v55, v18
    v57 = fadd v56, v19
    v58 = fadd v57, v20
    v59 = fadd v58, v21
    v60 = fadd v59, v22
    v61 = fadd v60, v23
    v62 = fadd v61, v24
    v63 = fadd v62, v25
    v64 = fadd v63, v26
    v65 = fadd v64, v27
    v66 = fadd v65, v28
    v67 = fadd v66, v29
    v68 = fadd v67, v30
    v69 = fadd v68, v31
    v70 = fadd v69, v32
    v71 = fadd v70, v33
    v72 = extractlane v71, 1
    return v72
}

; No vector: the scalars stay in v8 - v15 across the call.
function %scalar_caller(f64, f64, f64) -> f64 {
    fn0 = colocated %clobber_vectors(f64) -> f64

block0(v0: f64, v1: f64, v2: f64):
    v3 = call fn0(v0)
    v4 = fmul v1, v2
    v5 = fadd v4, v1
    v6 = fadd v5, v2
    return v6
}
; run: %scalar_caller(0x1.0, 0x3.0, 0x5.0) == 0x17.0

; A vector live across the call: v8 - v15 stay clobbered, so it is spilled.
function %vector_caller(f64, f64) -> f64 {
    fn0 = colocated %clobber_vectors(f64) -> f64

block0(v0: f64, v1: f64):
    v2 = splat.f64x2 v1
    v3 = call fn0(v0)
    v4 = extractlane v2, 1
    v5 = fadd v4, v1
    return v5
}
; run: %vector_caller(0x1.0, 0x3.0) == 0x6.0

</details>

target/release/clif-util test run.clif

It printed 1 tests with no failure, with and without the patch. With its expected value changed from 0x17.0 to
0x18.0, it failed with actual: 0x1.7000000000000p4, which shows that the test runs.

A precise alternative would be per-value partial clobbers in regalloc2.

<details><summary>Patch against cranelift-codegen 0.137.0</summary>

diff --git a/cranelift/codegen/src/isa/aarch64/abi.rs b/cranelift/codegen/src/isa/aarch64/abi.rs
index 8659561..8c953bc 100644
--- a/cranelift/codegen/src/isa/aarch64/abi.rs
+++ b/cranelift/codegen/src/isa/aarch64/abi.rs
@@ -1210,6 +1210,20 @@ impl ABIMachineSpec for AArch64MachineDeps {
         }
     }

+    fn get_regs_partially_clobbered_by_call(
+        call_conv: isa::CallConv,
+        is_exception: bool,
+    ) -> PRegSet {
+        // A callee that follows
[message truncated]

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

cfallin closed issue #15262:

.clif Test Case

A loop that calls a function and keeps three f64 values live across the call: the call's argument v0, the factor
v1 and the running sum v6. The function has no vector value.

test.clif

function %f(f64, f64, i64) -> f64 {
    sig0 = (f64) -> f64
    fn0 = %g sig0

block0(v0: f64, v1: f64, v2: i64):
    v3 = iconst.i64 0
    v4 = f64const 0.0
    v12 = iconst.i64 1
    jump block1(v3, v4)

block1(v5: i64, v6: f64):
    v7 = call fn0(v0)
    v8 = fmul v7, v1
    v9 = fadd v6, v8
    v10 = iadd v5, v12
    v11 = icmp ult v10, v2
    brif v11, block1(v10, v9), block2

block2:
    return v9
}

Steps to Reproduce

Expected Results

The loop keeps v0, v1 and v6 in v8–v15 across the call, with no load or store per iteration. AAPCS64 preserves
the low 64 bits of those registers, which is all of an f64, and the prologue saves the ones that the function
uses. With the patch, the loop from 0x2c to 0x70 moves the values between registers, and the prologue saves d8,
d9 and d15 once:

Disassembly of 136 bytes <%f>:
0:  stp x29, x30, [sp, #-0x10]!
4:  mov x29, sp
8:  stp x19, x20, [sp, #-0x10]!
c:  str d15, [sp, #-0x10]!
10:  stp    d8, d9, [sp, #-0x10]!
14:  mov    x20, x0
18:  mov    v8.16b, v0.16b
1c:  mov    v15.16b, v1.16b
20:  mov    x19, #0
24:  movi   v0.2s, #0
28:  mov    v9.16b, v0.16b
2c:  ldr    x13, #0x34
30:  b  #0x3c
34:  udf    #0
38:  udf    #0
3c:  mov    v0.16b, v8.16b
40:  blr    x13
44:  add    x19, x19, #1
48:  mov    v1.16b, v15.16b
4c:  fmul   d16, d0, d1
50:  mov    v0.16b, v9.16b
54:  fadd   d0, d0, d16
58:  mov    x0, x20
5c:  cmp    x19, x0
60:  b.hs   #0x74
64:  mov    x20, x0
68:  mov    v9.16b, v0.16b
6c:  mov    v15.16b, v1.16b
70:  b  #0x2c
74:  ldp    d8, d9, [sp], #0x10
78:  ldr    d15, [sp], #0x10
7c:  ldp    x19, x20, [sp], #0x10
80:  ldp    x29, x30, [sp], #0x10
84:  ret

Actual Results

Every iteration stores and reloads the floats: the loop from 0x28 to 0x6c has three 128-bit loads (ldur q) and
two 128-bit stores (stur q), to keep values that the callee would have preserved:

Disassembly of 128 bytes <%f>:
0:  stp x29, x30, [sp, #-0x10]!
4:  mov x29, sp
8:  stp x19, x20, [sp, #-0x10]!
c:  sub sp, sp, #0x30
10:  mov    x20, x0
14:  stur   q0, [sp]
18:  stur   q1, [sp, #0x10]
1c:  mov    x19, #0
20:  movi   v0.2s, #0
24:  stur   q0, [sp, #0x20]
28:  ldr    x13, #0x30
2c:  b  #0x38
30:  udf    #0
34:  udf    #0
38:  ldur   q0, [sp]
3c:  blr    x13
40:  add    x19, x19, #1
44:  ldur   q1, [sp, #0x10]
48:  fmul   d16, d0, d1
4c:  ldur   q0, [sp, #0x20]
50:  fadd   d0, d0, d16
54:  mov    x0, x20
58:  cmp    x19, x0
5c:  b.hs   #0x70
60:  mov    x20, x0
64:  stur   q1, [sp, #0x10]
68:  stur   q0, [sp, #0x20]
6c:  b  #0x28
70:  add    sp, sp, #0x30
74:  ldp    x19, x20, [sp], #0x10
78:  ldp    x29, x30, [sp], #0x10
7c:  ret

Versions and Environment

Cranelift version or commit: cranelift-codegen 0.137.0, with regalloc2 0.15.2, built into clif-util from wasmtime
v50.0.0 (commit ebe5e8df1f4e12c5fc2f5954926881d8d61367d8) with rustc 1.98.0, --release and default features.

Operating system: macOS 26.6.2 (build 25G83).

Architecture: arm64 (Apple M5 Pro), compiling for --target aarch64.

Extra Info

The limitation. default_aapcs_clobbers() in isa/aarch64/abi.rs says:

The upper 64 bits of v8 - v15 inclusive are also caller-saves. However, because we cannot currently represent
partial registers to regalloc2, we indicate here that every vector register is caller-save. Because this function
is used at callsites, approximating in this direction (save more than necessary) is conservative and thus safe.

This stopgap was chosen in #2254 and #2267, where a follow-up was noted so that prologues and epilogues deal only with
the lower 64 bits. In regalloc2, partial registers are out of scope (bytecodealliance/regalloc2#247).

The proposal. A function with no value wider than 64 bits loses nothing when a call clobbers only the upper
halves of v8–v15, so it can drop them from that call's clobbers without regalloc2 knowing about partial registers:

There is no new setting and no call for the embedder to make. The other users of the static clobber sets are
unchanged and stay conservative. s390x carries the same comment and could opt in the same way.

Soundness.

Evidence. With the patch, two aarch64 filetests change when blessed: in call.clif and user_stack_maps.clif,
the q-register spills become mov to v8–v15, and the prologue saves d8, d11, d12 or d15 with stp or
str. Stock clif-util fails both blessed files. With the patch and the blessed files,

target/release/clif-util test cranelift/filetests/filetests

printed 1322 tests with no failure. The following test, run.clif calls a function that writes
all 128 bits of v8–v15 from a caller that keeps scalars in them across the call:

<details><summary>run.clif</summary>

test run
target aarch64

; Writes whole q registers under high pressure, so that it uses v8 - v15 and,
; as AAPCS lets it, returns with only their low halves restored.
function %clobber_vectors(f64) -> f64 {
block0(v0: f64):
    v1 = splat.f64x2 v0
    v2 = fadd v1, v1
    v3 = fadd v2, v1
    v4 = fadd v3, v2
    v5 = fadd v4, v3
    v6 = fadd v5, v4
    v7 = fadd v6, v5
    v8 = fadd v7, v6
    v9 = fadd v8, v7
    v10 = fadd v9, v8
    v11 = fadd v10, v9
    v12 = fadd v11, v10
    v13 = fadd v12, v11
    v14 = fadd v13, v12
    v15 = fadd v14, v13
    v16 = fadd v15, v14
    v17 = fadd v16, v15
    v18 = fadd v17, v16
    v19 = fadd v18, v17
    v20 = fadd v19, v18
    v21 = fadd v20, v19
    v22 = fadd v21, v20
    v23 = fadd v22, v21
    v24 = fadd v23, v22
    v25 = fadd v24, v23
    v26 = fadd v25, v24
    v27 = fadd v26, v25
    v28 = fadd v27, v26
    v29 = fadd v28, v27
    v30 = fadd v29, v28
    v31 = fadd v30, v29
    v32 = fadd v31, v30
    v33 = fadd v32, v31
    v40 = fadd v1, v2
    v41 = fadd v40, v3
    v42 = fadd v41, v4
    v43 = fadd v42, v5
    v44 = fadd v43, v6
    v45 = fadd v44, v7
    v46 = fadd v45, v8
    v47 = fadd v46, v9
    v48 = fadd v47, v10
    v49 = fadd v48, v11
    v50 = fadd v49, v12
    v51 = fadd v50, v13
    v52 = fadd v51, v14
    v53 = fadd v52, v15
    v54 = fadd v53, v16
    v55 = fadd v54, v17
    v56 = fadd v55, v18
    v57 = fadd v56, v19
    v58 = fadd v57, v20
    v59 = fadd v58, v21
    v60 = fadd v59, v22
    v61 = fadd v60, v23
    v62 = fadd v61, v24
    v63 = fadd v62, v25
    v64 = fadd v63, v26
    v65 = fadd v64, v27
    v66 = fadd v65, v28
    v67 = fadd v66, v29
    v68 = fadd v67, v30
    v69 = fadd v68, v31
    v70 = fadd v69, v32
    v71 = fadd v70, v33
    v72 = extractlane v71, 1
    return v72
}

; No vector: the scalars stay in v8 - v15 across the call.
function %scalar_caller(f64, f64, f64) -> f64 {
    fn0 = colocated %clobber_vectors(f64) -> f64

block0(v0: f64, v1: f64, v2: f64):
    v3 = call fn0(v0)
    v4 = fmul v1, v2
    v5 = fadd v4, v1
    v6 = fadd v5, v2
    return v6
}
; run: %scalar_caller(0x1.0, 0x3.0, 0x5.0) == 0x17.0

; A vector live across the call: v8 - v15 stay clobbered, so it is spilled.
function %vector_caller(f64, f64) -> f64 {
    fn0 = colocated %clobber_vectors(f64) -> f64

block0(v0: f64, v1: f64):
    v2 = splat.f64x2 v1
    v3 = call fn0(v0)
    v4 = extractlane v2, 1
    v5 = fadd v4, v1
    return v5
}
; run: %vector_caller(0x1.0, 0x3.0) == 0x6.0

</details>

target/release/clif-util test run.clif

It printed 1 tests with no failure, with and without the patch. With its expected value changed from 0x17.0 to
0x18.0, it failed with actual: 0x1.7000000000000p4, which shows that the test runs.

A precise alternative would be per-value partial clobbers in regalloc2.

<details><summary>Patch against cranelift-codegen 0.137.0</summary>

diff --git a/cranelift/codegen/src/isa/aarch64/abi.rs b/cranelift/codegen/src/isa/aarch64/abi.rs
index 8659561..8c953bc 100644
--- a/cranelift/codegen/src/isa/aarch64/abi.rs
+++ b/cranelift/codegen/src/isa/aarch64/abi.rs
@@ -1210,6 +1210,20 @@ impl ABIMachineSpec for AArch64MachineDeps {
         }
     }

+    fn get_regs_partially_clobbered_by_call(
+        call_conv: isa::CallConv,
+        is_exception: bool,
+    ) -> PRegSet {
+        // A callee that follows
[message truncated]

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

cfallin commented on issue #15262:

Thanks. This is a known limitation, as you say. I don't think we want a function-global property computed (has_wide_values); that is brittle in that it can cause significant performance shifts when unrelated code is changed. It's also a pretty subtle invariant that we have to be careful about.

I'd rather see effort invested toward partial registers in RA2, if you're interested in pursuing this further. It might be possible to do something about this by recording "partialness" on both clobbers and on defs and detecting conflicts while accounting for that, without a full implementation of sub-registers. I'll go ahead and close this issue in favor of that because (i) the limitation is already tracked in RA2's issue tracker and (ii) the patch in this issue is not what I'd like to see pursued, as described above.

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

kestred commented on issue #15262:

@cfallin , I'll look into the complexity/cost/benefit of "partialness" in clobbers in regalloc!

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

kestred edited a comment on issue #15262:

Thanks @cfallin! I'll look into the complexity/cost/benefit of "partialness" in clobbers in regalloc2.

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

kestred edited a comment on issue #15262:

Thanks @cfallin! I'll look into the complexity/cost/benefit of "partialness" in clobbers in regalloc2.

This measures as a pretty big runtime win on the production programs I compile on MacOS
(w/o sacrificing compile time), so its something I intend to try and find a good solution for.

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

kestred edited a comment on issue #15262:

Thanks @cfallin! I'll look into the complexity/cost/benefit of "partialness" in clobbers in regalloc2.

This measures as a pretty big runtime win on the production programs I use crane lift to compile on MacOS
(w/o sacrificing compile time), so its something I intend to try and find a good solution for.


Last updated: Nov 19 2026 at 20:05 UTC