Commit 2bd7cea
committed
JIT: Fold IS_UNDEF check into dereference of typed property reads for tracing JIT
When the tracing JIT reads a typed property with a known result type into
a reg, the value is either of that type, a reference or IS_UNDEF.
Instead of guarding IS_UNDEF separately before making a decision on the
type, exit only if the value is neither of the expected type nor a reference.
This removes a compare and branch from the hot path of, e.g., reads of
$this->prop in loops.
Example PHP code:
```php
class Counter {
public int $x = 1;
function sum($n) {
$s = 0;
for ($i = 0; $i < $n; $i++) {
$s += $this->x;
}
return $s;
}
}
var_dump((new Counter)->sum(1000));
```
The loop compiled previously to:
```asm
.L1:
movq (%rdi), %rsi
leaq 8(%rsi), %rdi
.L2:
movq (%rdi), %rsi
movq %rsi, %rdi
addq %rcx, %rdi
jo jit$$trace_exit_5
leaq 1(%rdx), %rdx
movabsq $EG(vm_interrupt), %rcx
movb (%rcx), %cl
testb %cl, %cl
jne jit$$trace_exit_6
movq %rdi, %rcx
.L3:
cmpq %rax, %rdx
jge jit$$trace_exit_3
movq 0x20(%r14), %rsi
leaq 0x28(%rsi), %rdi
movl 0x30(%rsi), %esi
testl %esi, %esi
je jit$$trace_exit_4
cmpl $4, %esi
je .L2
jmp .L1
```
Notice that in `.L3` there's two checks on `%esi` (the type info): one
for the IS_UNDEF (via `testl`) and one to check for an int (`$4`).
The new code moves the check for reference type to the `.L1` header and
only checks for the int type in `.L3`, reducing the code executed in the
hot loop:
```asm
.L1:
cmpl $0x30a, %esi
jne jit$$trace_exit_4
movq (%rdi), %rsi
leaq 8(%rsi), %rdi
.L2:
movq (%rdi), %rsi
movq %rsi, %rdi
addq %rcx, %rdi
jo jit$$trace_exit_5
leaq 1(%rdx), %rdx
movabsq $EG(vm_interrupt), %rcx
movb (%rcx), %cl
testb %cl, %cl
jne jit$$trace_exit_6
movq %rdi, %rcx
.L3:
cmpq %rax, %rdx
jge jit$$trace_exit_3
movq 0x20(%r14), %rsi
leaq 0x28(%rsi), %rdi
movl 0x30(%rsi), %esi
cmpl $4, %esi
je .L2
jmp .L1
```1 parent a8caefc commit 2bd7cea
2 files changed
Lines changed: 105 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11831 | 11831 | | |
11832 | 11832 | | |
11833 | 11833 | | |
11834 | | - | |
| 11834 | + | |
| 11835 | + | |
11835 | 11836 | | |
11836 | 11837 | | |
11837 | 11838 | | |
11838 | 11839 | | |
11839 | 11840 | | |
11840 | | - | |
11841 | | - | |
11842 | | - | |
11843 | | - | |
11844 | | - | |
11845 | | - | |
11846 | 11841 | | |
11847 | 11842 | | |
11848 | | - | |
11849 | | - | |
11850 | | - | |
11851 | | - | |
11852 | | - | |
11853 | | - | |
11854 | 11843 | | |
11855 | 11844 | | |
11856 | 11845 | | |
| 11846 | + | |
| 11847 | + | |
| 11848 | + | |
| 11849 | + | |
| 11850 | + | |
| 11851 | + | |
| 11852 | + | |
| 11853 | + | |
| 11854 | + | |
11857 | 11855 | | |
11858 | 11856 | | |
11859 | 11857 | | |
| |||
14290 | 14288 | | |
14291 | 14289 | | |
14292 | 14290 | | |
| 14291 | + | |
14293 | 14292 | | |
14294 | 14293 | | |
14295 | 14294 | | |
| |||
14544 | 14543 | | |
14545 | 14544 | | |
14546 | 14545 | | |
14547 | | - | |
14548 | | - | |
| 14546 | + | |
| 14547 | + | |
| 14548 | + | |
| 14549 | + | |
| 14550 | + | |
| 14551 | + | |
| 14552 | + | |
| 14553 | + | |
| 14554 | + | |
14549 | 14555 | | |
14550 | 14556 | | |
14551 | 14557 | | |
| |||
14659 | 14665 | | |
14660 | 14666 | | |
14661 | 14667 | | |
14662 | | - | |
| 14668 | + | |
14663 | 14669 | | |
14664 | 14670 | | |
14665 | 14671 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
0 commit comments