ruby-changes:73119
From: Maxime <ko1@a...>
Date: Tue, 30 Aug 2022 00:53:34 +0900 (JST)
Subject: [ruby-changes:73119] 39dd8b2dfb (master): Add test for lea and ret. Fix codegen for lea and ret.
https://git.ruby-lang.org/ruby.git/commit/?id=39dd8b2dfb From 39dd8b2dfbb50aab7731466b57c39eaf96e66996 Mon Sep 17 00:00:00 2001 From: Maxime Chevalier-Boisvert <maxime.chevalierboisvert@s...> Date: Mon, 6 Jun 2022 17:57:07 -0400 Subject: Add test for lea and ret. Fix codegen for lea and ret. --- yjit/src/backend/ir.rs | 19 +++++++++++++++---- yjit/src/backend/x86_64/mod.rs | 13 +++++++++++-- yjit/src/codegen.rs | 3 ++- 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/yjit/src/backend/ir.rs b/yjit/src/backend/ir.rs index fa8a7b8e2b..f6a02909d9 100644 --- a/yjit/src/backend/ir.rs +++ b/yjit/src/backend/ir.rs @@ -65,12 +65,12 @@ pub enum Op https://github.com/ruby/ruby/blob/trunk/yjit/src/backend/ir.rs#L65 // Low-level instruction to store a value to memory. Store, - // A low-level mov instruction. It accepts two operands. - Mov, - // Load effective address Lea, + // A low-level mov instruction. It accepts two operands. + Mov, + // Bitwise AND test instruction Test, @@ -705,9 +705,9 @@ def_push_2_opnd!(sub, Op::Sub); https://github.com/ruby/ruby/blob/trunk/yjit/src/backend/ir.rs#L705 def_push_2_opnd!(and, Op::And); def_push_1_opnd_no_out!(cret, Op::CRet); def_push_1_opnd!(load, Op::Load); +def_push_1_opnd!(lea, Op::Lea); def_push_2_opnd_no_out!(store, Op::Store); def_push_2_opnd_no_out!(mov, Op::Mov); -def_push_2_opnd_no_out!(lea, Op::Lea); def_push_2_opnd_no_out!(cmp, Op::Cmp); def_push_2_opnd_no_out!(test, Op::Test); @@ -914,4 +914,15 @@ mod tests { https://github.com/ruby/ruby/blob/trunk/yjit/src/backend/ir.rs#L914 asm.compile_with_regs(&mut jit, &mut cb, regs); } + + #[test] + fn test_lea_ret() + { + let (mut asm, mut jit, mut cb, regs) = setup_asm(1); + + let addr = asm.lea(Opnd::mem(64, SP, 0)); + asm.cret(addr); + + asm.compile_with_regs(&mut jit, &mut cb, regs); + } } diff --git a/yjit/src/backend/x86_64/mod.rs b/yjit/src/backend/x86_64/mod.rs index eb54ced2bf..4aa04b29aa 100644 --- a/yjit/src/backend/x86_64/mod.rs +++ b/yjit/src/backend/x86_64/mod.rs @@ -127,7 +127,7 @@ impl Assembler https://github.com/ruby/ruby/blob/trunk/yjit/src/backend/x86_64/mod.rs#L127 Op::Mov => mov(cb, insn.opnds[0].into(), insn.opnds[1].into()), // Load effective address - Op::Lea => lea(cb, insn.opnds[0].into(), insn.opnds[1].into()), + Op::Lea => lea(cb, insn.out.into(), insn.opnds[0].into()), // Test and set flags Op::Test => test(cb, insn.opnds[0].into(), insn.opnds[1].into()), @@ -149,7 +149,16 @@ impl Assembler https://github.com/ruby/ruby/blob/trunk/yjit/src/backend/x86_64/mod.rs#L149 } }, - _ => panic!("unsupported instruction passed to x86 backend") + Op::CRet => { + // TODO: bias allocation towards return register + if insn.opnds[0] != Opnd::Reg(RET_REG) { + mov(cb, RAX, insn.opnds[0].into()); + } + + ret(cb); + } + + _ => panic!("unsupported instruction passed to x86 backend: {:?}", insn.op) }; } } diff --git a/yjit/src/codegen.rs b/yjit/src/codegen.rs index 955d87eb68..28cf05e95c 100644 --- a/yjit/src/codegen.rs +++ b/yjit/src/codegen.rs @@ -324,7 +324,8 @@ fn gen_save_sp(cb: &mut CodeBlock, ctx: &mut Context) { https://github.com/ruby/ruby/blob/trunk/yjit/src/codegen.rs#L324 fn ir_gen_save_sp(jit: &JITState, asm: &mut Assembler, ctx: &mut Context) { if ctx.get_sp_offset() != 0 { let stack_pointer = ctx.ir_sp_opnd(0); - asm.lea(SP, stack_pointer); + let sp_addr = asm.lea(stack_pointer); + asm.mov(SP, sp_addr); let cfp_sp_opnd = Opnd::mem(64, CFP, RUBY_OFFSET_CFP_SP); asm.mov(cfp_sp_opnd, SP); ctx.set_sp_offset(0); -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/