Our previous implementation of unwind infrastructure was somewhat complex and brittle: it parsed generated instructions in order to reverse-engineer unwind info from prologues. It also relied on some fragile linkage to communicate instruction-layout information that VCode was not designed to provide. A much simpler, more reliable, and easier-to-reason-about approach is to embed unwind directives as pseudo-instructions in the prologue as we generate it. That way, we can say what we mean and just emit it directly. The usual reasoning that leads to the reverse-engineering approach is that metadata is hard to keep in sync across optimization passes; but here, (i) prologues are generated at the very end of the pipeline, and (ii) if we ever do a post-prologue-gen optimization, we can treat unwind directives as black boxes with unknown side-effects, just as we do for some other pseudo-instructions today. It turns out that it was easier to just build this for both x64 and aarch64 (since they share a factored-out ABI implementation), and wire up the platform-specific unwind-info generation for Windows and SystemV. Now we have simpler unwind on all platforms and we can delete the old unwind infra as soon as we remove the old backend. There were a few consequences to supporting Fastcall unwind in particular that led to a refactor of the common ABI. Windows only supports naming clobbered-register save locations within 240 bytes of the frame-pointer register, whatever one chooses that to be (RSP or RBP). We had previously saved clobbers below the fixed frame (and below nominal-SP). The 240-byte range has to include the old RBP too, so we're forced to place clobbers at the top of the frame, just below saved RBP/RIP. This is fine; we always keep a frame pointer anyway because we use it to refer to stack args. It does mean that offsets of fixed-frame slots (spillslots, stackslots) from RBP are no longer known before we do regalloc, so if we ever want to index these off of RBP rather than nominal-SP because we add support for `alloca` (dynamic frame growth), then we'll need a "nominal-BP" mode that is resolved after regalloc and clobber-save code is generated. I added a comment to this effect in `abi_impl.rs`. The above refactor touched both x64 and aarch64 because of shared code. This had a further effect in that the old aarch64 prologue generation subtracted from `sp` once to allocate space, then used stores to `[sp, offset]` to save clobbers. Unfortunately the offset only has 7-bit range, so if there are enough clobbered registers (and there can be -- aarch64 has 384 bytes of registers; at least one unit test hits this) the stores/loads will be out-of-range. I really don't want to synthesize large-offset sequences here; better to go back to the simpler pre-index/post-index `stp r1, r2, [sp, #-16]` form that works just like a "push". It's likely not much worse microarchitecturally (dependence chain on SP, but oh well) and it actually saves an instruction if there's no other frame to allocate. As a further advantage, it's much simpler to understand; simpler is usually better. This PR adds the new backend on Windows to CI as well.
163 lines
3.1 KiB
Plaintext
163 lines
3.1 KiB
Plaintext
test compile
|
|
set unwind_info=false
|
|
target aarch64
|
|
|
|
function %f1() -> i64x2 {
|
|
block0:
|
|
v0 = iconst.i64 281474976710657
|
|
v1 = splat.i64x2 v0
|
|
return v1
|
|
}
|
|
|
|
; check: stp fp, lr, [sp, #-16]!
|
|
; nextln: mov fp, sp
|
|
; nextln: movz x0, #1
|
|
; nextln: movk x0, #1, LSL #48
|
|
; nextln: dup v0.2d, x0
|
|
; nextln: ldp fp, lr, [sp], #16
|
|
; nextln: ret
|
|
|
|
function %f2() -> i16x8 {
|
|
block0:
|
|
v0 = iconst.i32 42679
|
|
v1 = ireduce.i16 v0
|
|
v2 = splat.i16x8 v1
|
|
return v2
|
|
}
|
|
|
|
; check: stp fp, lr, [sp, #-16]!
|
|
; nextln: mov fp, sp
|
|
; nextln: movz x0, #42679
|
|
; nextln: dup v0.8h, w0
|
|
; nextln: ldp fp, lr, [sp], #16
|
|
; nextln: ret
|
|
|
|
function %f3() -> b8x16 {
|
|
block0:
|
|
v0 = bconst.b32 true
|
|
v1 = breduce.b8 v0
|
|
v2 = splat.b8x16 v1
|
|
return v2
|
|
}
|
|
|
|
; check: stp fp, lr, [sp, #-16]!
|
|
; nextln: mov fp, sp
|
|
; nextln: movi v0.16b, #255
|
|
; nextln: ldp fp, lr, [sp], #16
|
|
; nextln: ret
|
|
|
|
function %f4(i32, i8x16, i8x16) -> i8x16 {
|
|
block0(v0: i32, v1: i8x16, v2: i8x16):
|
|
v3 = select v0, v1, v2
|
|
return v3
|
|
}
|
|
|
|
; check: stp fp, lr, [sp, #-16]!
|
|
; nextln: mov fp, sp
|
|
; nextln: subs wzr, w0, wzr
|
|
; nextln: vcsel v0.16b, v0.16b, v1.16b, ne (if-then-else diamond)
|
|
; nextln: ldp fp, lr, [sp], #16
|
|
; nextln: ret
|
|
|
|
function %f5(i64) -> i8x16 {
|
|
block0(v0: i64):
|
|
v1 = load.i8 v0
|
|
v2 = splat.i8x16 v1
|
|
return v2
|
|
}
|
|
|
|
; check: stp fp, lr, [sp, #-16]!
|
|
; nextln: mov fp, sp
|
|
; nextln: ld1r { v0.16b }, [x0]
|
|
; nextln: ldp fp, lr, [sp], #16
|
|
; nextln: ret
|
|
|
|
function %f6(i64, i64) -> i8x16, i8x16 {
|
|
block0(v0: i64, v1: i64):
|
|
v2 = load.i8 v0
|
|
v3 = load.i8 v1
|
|
v4 = splat.i8x16 v2
|
|
v5 = splat.i8x16 v3
|
|
return v4, v5
|
|
}
|
|
|
|
; check: stp fp, lr, [sp, #-16]!
|
|
; nextln: mov fp, sp
|
|
; nextln: ld1r { v0.16b }, [x0]
|
|
; nextln: ld1r { v1.16b }, [x1]
|
|
; nextln: ldp fp, lr, [sp], #16
|
|
; nextln: ret
|
|
|
|
function %f7(i64, i64) -> i8x16, i8x16 {
|
|
block0(v0: i64, v1: i64):
|
|
v2 = load.i8 v0
|
|
v3 = load.i8 v1
|
|
v4 = splat.i8x16 v3
|
|
v5 = splat.i8x16 v2
|
|
return v4, v5
|
|
}
|
|
|
|
; check: stp fp, lr, [sp, #-16]!
|
|
; nextln: mov fp, sp
|
|
; nextln: ldrb w0, [x0]
|
|
; nextln: ld1r { v0.16b }, [x1]
|
|
; nextln: dup v1.16b, w0
|
|
; nextln: ldp fp, lr, [sp], #16
|
|
; nextln: ret
|
|
|
|
function %f8(i64, i64) -> i8x16, i8x16 {
|
|
block0(v0: i64, v1: i64):
|
|
v2 = load.i8 v0
|
|
v3 = splat.i8x16 v2
|
|
v4 = splat.i8x16 v2
|
|
return v3, v4
|
|
}
|
|
|
|
; check: stp fp, lr, [sp, #-16]!
|
|
; nextln: mov fp, sp
|
|
; nextln: ldrb w0, [x0]
|
|
; nextln: dup v0.16b, w0
|
|
; nextln: dup v1.16b, w0
|
|
; nextln: ldp fp, lr, [sp], #16
|
|
; nextln: ret
|
|
|
|
function %f9() -> i32x2 {
|
|
block0:
|
|
v0 = iconst.i32 4278190335
|
|
v1 = splat.i32x2 v0
|
|
return v1
|
|
}
|
|
|
|
; check: stp fp, lr, [sp, #-16]!
|
|
; nextln: mov fp, sp
|
|
; nextln: movi v0.2d, #18374687579166474495
|
|
; nextln: fmov d0, d0
|
|
; nextln: ldp fp, lr, [sp], #16
|
|
; nextln: ret
|
|
|
|
function %f10() -> i32x4 {
|
|
block0:
|
|
v0 = iconst.i32 4293918720
|
|
v1 = splat.i32x4 v0
|
|
return v1
|
|
}
|
|
|
|
; check: stp fp, lr, [sp, #-16]!
|
|
; nextln: mov fp, sp
|
|
; nextln: mvni v0.4s, #15, MSL #16
|
|
; nextln: ldp fp, lr, [sp], #16
|
|
; nextln: ret
|
|
|
|
function %f11() -> f32x4 {
|
|
block0:
|
|
v0 = f32const 0x1.5
|
|
v1 = splat.f32x4 v0
|
|
return v1
|
|
}
|
|
|
|
; check: stp fp, lr, [sp, #-16]!
|
|
; nextln: mov fp, sp
|
|
; nextln: fmov v0.4s, #1.3125
|
|
; nextln: ldp fp, lr, [sp], #16
|
|
; nextln: ret
|