Repository navigation
Commit 78d56e0
authored
JIT: Optimize array checks in comparisons (#24084)
There are two optimizations:
1. This patch implements the JIT counterpart of the VM change 2d6b869 to
optimize comparisons against empty arrays.
2. This patch ensures that if a type can be array, the element count
check happens inline rather than going to a slow path.
PHP demo code for #1:
```php
function f(array $a) {
if ($a) return 0;
return 1;
}
```
Before #1 (for func JIT in this case):
```asm
.L1:
movq $0x418d88c0, (%r14) ; EX(opline) = opline
leaq 0x50(%r14), %rdi ; arg = &CV0($a)
movabsq $zend_is_true, %rax
callq *%rax
testb %al, %al
je .L2
```
After #1:
```asm
.L1:
movq 0x50(%r14), %rax ; Z_ARRVAL($a)
cmpl $0, 0x1c(%rax) ; compare nNumOfElements
je .L2
```
PHP demo code for #2:
```php
function is_empty(array $a) {
if ($a === []) return 1;
return 2;
}
```
Before #2:
```asm
.L1:
leaq 0x50(%r14), %rdi ; arg1 = &CV0($a)
movl $0x418d8ad8, %esi ; arg2 = &literal []
movabsq $zend_is_identical, %rax
callq *%rax
testb %al, %al
je .L2
```
After #2:
```asm
.L1:
movq 0x50(%r14), %rax ; Z_ARRVAL($a)
cmpl $0, 0x1c(%rax) ; compare nNumOfElements
jne .L2
```
It ain't much, but it should help.
I think many small frontend improvements can make a nice change in
total together.1 parent 222c13f commit 78d56e0
1 file changed
Lines changed: 29 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7263 | 7263 | | |
7264 | 7264 | | |
7265 | 7265 | | |
| 7266 | + | |
| 7267 | + | |
| 7268 | + | |
| 7269 | + | |
| 7270 | + | |
| 7271 | + | |
| 7272 | + | |
7266 | 7273 | | |
7267 | 7274 | | |
7268 | 7275 | | |
| |||
7424 | 7431 | | |
7425 | 7432 | | |
7426 | 7433 | | |
| 7434 | + | |
| 7435 | + | |
| 7436 | + | |
| 7437 | + | |
| 7438 | + | |
| 7439 | + | |
| 7440 | + | |
| 7441 | + | |
7427 | 7442 | | |
7428 | 7443 | | |
7429 | 7444 | | |
| |||
7762 | 7777 | | |
7763 | 7778 | | |
7764 | 7779 | | |
7765 | | - | |
7766 | | - | |
| 7780 | + | |
| 7781 | + | |
| 7782 | + | |
| 7783 | + | |
| 7784 | + | |
| 7785 | + | |
| 7786 | + | |
| 7787 | + | |
| 7788 | + | |
| 7789 | + | |
| 7790 | + | |
| 7791 | + | |
| 7792 | + | |
| 7793 | + | |
7767 | 7794 | | |
7768 | 7795 | | |
7769 | 7796 | | |
| |||
0 commit comments