From 2501a75575f1f4ec5c619bd069dce93c950fdf26 Mon Sep 17 00:00:00 2001 From: pthier Date: Thu, 12 Jan 2023 12:53:14 +0100 Subject: [PATCH] [maglev][arm64] Use one less scratch register in PushAllHelper Instead of pushing 2 arguments at the same time, we push 1 argument together with padreg (to ensure alignment) and overwrite padreg afterwards. That way we can re-use scratch registers used for the first argument to materialise the second one. Bug: v8:7700 Change-Id: I6d32b61f6e75ec488b4cf4128ced966bcf0ed1bd Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/4161758 Commit-Queue: Patrick Thier Reviewed-by: Victor Gomes Auto-Submit: Patrick Thier Cr-Commit-Position: refs/heads/main@{#85251} --- src/maglev/arm64/maglev-assembler-arm64-inl.h | 40 +++++++++---------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/src/maglev/arm64/maglev-assembler-arm64-inl.h b/src/maglev/arm64/maglev-assembler-arm64-inl.h index 5ced213a3f..f66f5820cb 100644 --- a/src/maglev/arm64/maglev-assembler-arm64-inl.h +++ b/src/maglev/arm64/maglev-assembler-arm64-inl.h @@ -150,6 +150,22 @@ inline void PushIteratorReverse(MaglevAssembler* masm, } } +template +inline void PushAligned(MaglevAssembler* masm, Arg1 arg1, Arg2 arg2) { + { + // Push the first argument together with padding to ensure alignment. + // The second argument is not pushed together with the first so we can + // re-use any scratch registers used to materialise the first argument for + // the second one. + UseScratchRegisterScope temps(masm); + masm->MacroAssembler::Push(ToRegister(masm, &temps, arg1), padreg); + } + { + UseScratchRegisterScope temps(masm); + masm->MacroAssembler::str(ToRegister(masm, &temps, arg2), MemOperand(sp)); + } +} + template struct PushAllHelper { static void Push(MaglevAssembler* masm, Arg arg) { @@ -176,11 +192,7 @@ struct PushAllHelper { } else if constexpr (is_iterator_range::value) { if (arg2.begin() != arg2.end()) { auto val = *arg2.begin(); - { - UseScratchRegisterScope temps(masm); - masm->MacroAssembler::Push(ToRegister(masm, &temps, arg1), - ToRegister(masm, &temps, val)); - } + PushAligned(masm, arg1, val); PushAll(masm, base::make_iterator_range(std::next(arg2.begin()), arg2.end()), args...); @@ -188,11 +200,7 @@ struct PushAllHelper { PushAll(masm, arg1, args...); } } else { - { - UseScratchRegisterScope temps(masm); - masm->MacroAssembler::Push(ToRegister(masm, &temps, arg1), - ToRegister(masm, &temps, arg2)); - } + PushAligned(masm, arg1, arg2); PushAll(masm, args...); } } @@ -207,21 +215,13 @@ struct PushAllHelper { masm, base::make_iterator_range(std::next(arg2.begin()), arg2.end()), args...); - { - UseScratchRegisterScope temps(masm); - masm->MacroAssembler::Push(ToRegister(masm, &temps, val), - ToRegister(masm, &temps, arg1)); - } + PushAligned(masm, val, arg1); } else { PushAllReverse(masm, arg1, args...); } } else { PushAllReverse(masm, args...); - { - UseScratchRegisterScope temps(masm); - masm->MacroAssembler::Push(ToRegister(masm, &temps, arg2), - ToRegister(masm, &temps, arg1)); - } + PushAligned(masm, arg2, arg1); } } };