ZJIT: Only load non-vreg opnds#16486
Conversation
| Opnd::mem(64, CFP, RUBY_OFFSET_CFP_SELF) | ||
| } | ||
|
|
||
| fn load_me_maybe(asm: &mut Assembler, recv: Opnd) -> Opnd { |
There was a problem hiding this comment.
I think this is a good idea. As long as it's MemBase-compatible, nothing breaks, and it seems more efficient for today's backend.
Let's make Assembler the self so that we can call it with asm.xxx though. It should be the default thing we'll use for any MemBase, so it should have a good-looking API.
Maybe just call it asm.load_mem? It would still need to load imm/uimm/value just in case, but the use of it is going to be mostly mem/reg/vreg, so it would mostly do "load mem".
|
|
||
| fn load_me_maybe(asm: &mut Assembler, recv: Opnd) -> Opnd { | ||
| match recv { | ||
| Opnd::VReg { .. } => recv, |
There was a problem hiding this comment.
If I understand correctly, we could also do:
| Opnd::VReg { .. } => recv, | |
| Opnd::VReg { .. } | Opnd::Reg(_) => recv, |
We might not actually hit that, but I'd feel more comfortable if we excluded the possibility of the unneeded load.
There was a problem hiding this comment.
Ya, makes sense. I was undecided about whether to add Reg, but thinking about it more, it makes sense.
53542b1 to
cede149
Compare
When we call `asm.load`, many times we're passing in a VReg, and that
causes extra loads when we lower to machine code. I'd like to only emit
a load in the case that the operand _isn't_ a VReg.
For example this code:
```ruby
class Foo
def initialize
@foo = 123
end
def foo
@foo
end
end
foo = Foo.new
5.times { foo.foo }
```
Before this patch, the machine code for `LoadField` looks like this:
```
# Insn: v18 LoadField v17, :_shape_id@0x4
# Load field id=_shape_id offset=4
0x121308320: mov x1, x0
0x121308324: ldur w1, [x1, #4]
```
Now it looks like this:
```
# Insn: v18 LoadField v17, :_shape_id@0x4
# Load field id=_shape_id offset=4
0x12339c320: ldur w1, [x0, #4]
```
We were able to eliminate a reg-reg copy.
cede149 to
6a9a851
Compare
When we call
asm.load, many times we're passing in a VReg, and that causes extra loads when we lower to machine code. I'd like to only emit a load in the case that the operand isn't a VReg.For example this code:
Before this patch, the machine code for
LoadFieldlooks like this:Now it looks like this:
We were able to eliminate a reg-reg copy.