Improve RLOAD/RSTORE handling#133
Conversation
| IR_USE_LIVE_POS_FROM_REF(ref), | ||
| IR_DEF_LIVE_POS_FROM_REF(ref)); |
There was a problem hiding this comment.
I'm not sure about the start/end positions here. I don't fully understand the differences between the various sub-positions.
* Add fixed live ranges for RSTOREs * Allocate registers normally for RLOAD, so that a copy is made in case an RSTORE conflicts with the RLOAD live range * Introduce IR_LIVE_INTERVAL_ALLOW_FIXED: Allows to allocate a register from the fixed_regs set, when hints match * Do not add a fixed live range for PARAM/RLOAD of fixed regs, as it's not necessary
dstogov
left a comment
There was a problem hiding this comment.
Thanks for the attempt!
I didn't look into all implementation details yet, most probably, this is logically right, but this makes significant overhead. I see 6% slowdown on Wordpress function JIT (both time and callgrind) and also degradation in generated code because of inference of few RLOAD intervals (e.g. bench.php total() with function JIIT). May be we miss some RLOADs in zend_jit_ir.c.
Another "proper" way to fix this would be handling anti-dependencies between RLOAD usages and RSTOREs in "Global Code Motion" and "Local Scheduling". (some related background can be found at https://github.com/SeaOfNodes/Simple/blob/main/chapter11/README.md#inserting-anti-dependencies ). This is not simple and dangerous for stable releases...
For now, I think it's better to find a simple work-around. E.g. disable IF folding into COND if condition is RLOAD. Will this work?
|
Yes, disabling folding into |
See 703eb90 |
|
It doesn't appear to be enough. In the case of PHP-21460, the cond op is LOAD() of an RLOAD(). Here is a less minimized reproducer: |
This seems compiled right test:
movq 0x10(%r15), %rax ; RLOAD + first LOAD
movq 0x20(%rax), %rax ; second LOAD
movl $0xffff, %r15d ; RSTORE
cmpq $0, (%r15) ; second RLOAD + third LOAD + second IF
jne .L1
movl $2, %ecx ; COND sank to IF_FALSE of the second IF
testq %rax, %rax ; COND condition (result of second LOAD)
movl $1, %eax
cmoveq %rcx, %rax
movq %rax, 0xffff
movq $0xffff, %rax
jmpq *%rax
.L1:
movq $0xffff, %rax
jmpq *%raxWhat is wrong? |
|
My bad, wrong reproducer. With this one, the result is incorrect: |
|
Aha. This shouldn't be difficult to fix. Thanks. |
BTW Do you know what kind of PHP code produces this? |
|
Please don't close this PR. It may be useful. |
There is a small reproducer in this comment: |
The result of
RLOAD()may be be clobbered by anRSTORE()before use: GH-132.This is an attempt to fix that:
Generated code in PHP JIT mostly didn't change after this.
TODO: