A lightweight WebAssembly runtime that is fast, secure, and standards-compliant
aarch64: Fix regalloc of `atomic_load.i128` (#14889)
Alex Crichton5afd63588b1f
diff --git a/cranelift/codegen/src/isa/aarch64/inst/mod.rs b/cranelift/codegen/src/isa/aarch64/inst/mod.rsindex 9463db08b8..1eb4552539 100644--- a/cranelift/codegen/src/isa/aarch64/inst/mod.rs+++ b/cranelift/codegen/src/isa/aarch64/inst/mod.rs@@ -588,9 +588,11 @@ fn aarch64_get_operands(inst: &mut Inst, collector: &mut impl OperandVisitor) {..} => {collector.reg_use(rn);- collector.reg_def(rt1);- collector.reg_def(rt2);- collector.reg_def(scratch);+ // These registers are written to in a retry loop so their register+ // assignment can't reuse `rn`, thus they are early-defs.+ collector.reg_early_def(rt1);+ collector.reg_early_def(rt2);+ collector.reg_early_def(scratch);}Inst::StoreRelease { rt, rn, .. } => {collector.reg_use(rn);diff --git a/cranelift/filetests/filetests/isa/aarch64/atomic_load.clif b/cranelift/filetests/filetests/isa/aarch64/atomic_load.clifindex ef894f8add..2fe076c136 100644--- a/cranelift/filetests/filetests/isa/aarch64/atomic_load.clif+++ b/cranelift/filetests/filetests/isa/aarch64/atomic_load.clif@@ -9,14 +9,55 @@ block0(v0: i64):; VCode:; block0:-; load_acquire_128 x0, x1, [x0], scratch=x4+; mov x5, x0+; load_acquire_128 x0, x1, [x5], scratch=x4; ret;; Disassembled:; block0: ; offset 0x0-; ldaxp x0, x1, [x0] ; trap: heap_oob-; stxp w4, x0, x1, [x0] ; trap: heap_oob-; cbnz x4, #0+; mov x5, x0+; ldaxp x0, x1, [x5] ; trap: heap_oob+; stxp w4, x0, x1, [x5] ; trap: heap_oob+; cbnz x4, #4+; ret++function %atomic_load_i128_scratch(i64) -> i128 {+ ss0 = explicit_slot 16, align = 16+block0(v0: i64):+ v1 = uextend.i128 v0+ v2 = stack_addr.i64 ss0+ store.i128 little v1, v2+ v3 = atomic_load.i128 little v2+ return v3+}++; VCode:+; stp fp, lr, [sp, #-16]!+; mov fp, sp+; sub sp, sp, #16+; block0:+; movz x6, #0+; mov x7, sp+; stp x0, x6, [x7]+; load_acquire_128 x0, x1, [x7], scratch=x8+; add sp, sp, #16+; ldp fp, lr, [sp], #16+; ret+;+; Disassembled:+; block0: ; offset 0x0+; stp x29, x30, [sp, #-0x10]!+; mov x29, sp+; sub sp, sp, #0x10+; block1: ; offset 0xc+; mov x6, #0+; mov x7, sp+; stp x0, x6, [x7] ; trap: heap_oob+; ldaxp x0, x1, [x7] ; trap: heap_oob+; stxp w8, x0, x1, [x7] ; trap: heap_oob+; cbnz x8, #0x18+; add sp, sp, #0x10+; ldp x29, x30, [sp], #0x10; retfunction %atomic_load_i64(i64) -> i64 {diff --git a/cranelift/filetests/filetests/runtests/atomic-128.clif b/cranelift/filetests/filetests/runtests/atomic-128.clifindex 35449a406b..a55e885d69 100644--- a/cranelift/filetests/filetests/runtests/atomic-128.clif+++ b/cranelift/filetests/filetests/runtests/atomic-128.clif@@ -31,6 +31,36 @@ block0(v0: i128):; run: %atomic_load(0xC0FFEEEE_ABCDEF01_DECAFFFF_12345678) == 0xC0FFEEEE_ABCDEF01_DECAFFFF_12345678+; specifically testing the case where the address of what's being loaded is dead+; after the atomic load+function %atomic_load_dead_addr_callee(i64) -> i128 {+block0(v0: i64):+ v1 = atomic_load.i128 v0+ return v1+}++function %atomic_load_dead_addr(i128) -> i128 {+ ss0 = explicit_slot 32, align=8+ fn0 = %atomic_load_dead_addr_callee(i64) -> i128++block0(v0: i128):+ ; Dynamically align the slot to 16+ v1 = stack_addr.i64 ss0+ v2 = iconst.i64 15+ v3 = band v1, v2+ v4 = iconst.i64 16+ v5 = isub v4, v3+ v6 = iadd v1, v5++ store.i128 notrap v0, v6+ v7 = call fn0(v6)+ return v7+}+; run: %atomic_load_dead_addr(0) == 0+; run: %atomic_load_dead_addr(0x1234) == 0x1234+; run: %atomic_load_dead_addr(0xC0FFEEEE_ABCDEF01_DECAFFFF_12345678) == 0xC0FFEEEE_ABCDEF01_DECAFFFF_12345678++function %atomic_store(i128) -> i128 {ss0 = explicit_slot 32, align=8