Skip to content

JIT: Avoid object type check if the object is known to be a type - #24086

Merged
ndossche merged 1 commit into
php:masterfrom
ndossche:jit-recv-known-object
Oct 8, 2026
Merged

ndossche merged 1 commit into
php:masterfrom
ndossche:jit-recv-known-object

Conversation

@ndossche

@ndossche ndossche commented Oct 2, 2026

Copy link
Copy Markdown
Member

Follow-up for #24052

Before:

	mov    %r15,%r14
	lea    0x50(%r14),%rdi       ; &CV0($o)
	cmpb   $0x8,0x58(%r14)       ; Check IS_OBJECT
	jne    not_an_object         ; ...
	mov    (%rdi),%rax           ; Z_OBJ_P($o)
	lea    -0x77280f9(%rip),%rcx ; ce to compare against
	cmp    0x10(%rax),%rcx       ; Z_OBJ_P($o)->ce == ce
	je     wrong_ce
	...

After:

	mov    %r15,%r14
	lea    0x50(%r14),%rdi       ; &CV0($o)
	mov    (%rdi),%rax           ; Z_OBJ_P($o) (known to be an object)
	lea    -0x77280f9(%rip),%rcx ; ce to compare against
	cmp    0x10(%rax),%rcx       ; Z_OBJ_P($o)->ce == ce
	je     wrong_ce
	...

This also helps with an ?Foo type check: it can skip the IS_OBJECT and IS_NULL check.

This also simplifies zend_jit_verify_arg_type: the (type == IS_UNKNOWN || type == IS_OBJECT) check becomes always-true.

Before:
```asm
	mov    %r15,%r14
	lea    0x50(%r14),%rdi       ; &CV0($o)
	cmpb   $0x8,0x58(%r14)       ; Check IS_OBJECT
	jne    not_an_object         ; ...
	mov    (%rdi),%rax           ; Z_OBJ_P($o)
	lea    -0x77280f9(%rip),%rcx ; ce to compare against
	cmp    0x10(%rax),%rcx       ; Z_OBJ_P($o)->ce == ce
	je     wrong_ce
	...
```

After:
```asm
	mov    %r15,%r14
	lea    0x50(%r14),%rdi       ; &CV0($o)
	mov    (%rdi),%rax           ; Z_OBJ_P($o) (known to be an object)
	lea    -0x77280f9(%rip),%rcx ; ce to compare against
	cmp    0x10(%rax),%rcx       ; Z_OBJ_P($o)->ce == ce
	je     wrong_ce
	...
```

This also helps with an `?Foo` type check: it can skip the IS_OBJECT and IS_NULL check.

This also simplifies `zend_jit_verify_arg_type`: the
`(type == IS_UNKNOWN || type == IS_OBJECT)` check becomes always-true.
@github-actions

github-actions Bot commented Oct 3, 2026

Copy link
Copy Markdown

AWS x86_64 (c6id.metal)

Attribute Value
Environment aws
Instance type c6id.metal
Architecture x86_64
CPU Intel(R) Xeon(R) Platinum 8375C CPU @ 2.90GHz, 64 cores @ 2900 MHz
CPU settings disabled deeper C-states, disabled turbo boost, disabled hyper-threading
RAM 251 GB
Kernel 6.18.38-76.139.amzn2023.x86_64
OS Amazon Linux 2023.12.20260727
GCC 14.2.1
Binary layout strategy none
Time 2026-10-03 09:45:00 UTC
Job details https://github.com/php/php-src/actions/runs/37114074071 (Artifacts)
Changeset https://github.com/php/php-src/compare/cd8312e052..30f0cf6e6b

Laravel 12.11.0 demo app - 50 iterations, 50 warmups, 100 requests (sec)

PHP Min Max Std dev Rel std dev % Mean Mean diff % Median Median diff % Skewness Z-stat P-value Memory
PHP - baseline@cd8312e 0.38119 0.38301 0.00040 0.11% 0.38173 0.00% 0.38158 0.00% 1.493 0.000 1.000 25.90 MB
PHP - baseline@cd8312e (JIT) 0.35689 0.35776 0.00021 0.06% 0.35726 -6.41% 0.35723 -6.38% 0.576 8.614 0.000 25.98 MB
PHP - jit-recv-known-object 0.38100 0.38265 0.00029 0.08% 0.38145 -0.07% 0.38142 -0.04% 1.882 4.171 0.000 25.90 MB
PHP - jit-recv-known-object (JIT) 0.35705 0.35848 0.00027 0.08% 0.35747 -6.35% 0.35744 -6.33% 1.471 8.614 0.000 25.98 MB

Symfony 2.8.0 demo app - 50 iterations, 50 warmups, 100 requests (sec)

PHP Min Max Std dev Rel std dev % Mean Mean diff % Median Median diff % Skewness Z-stat P-value Memory
PHP - baseline@cd8312e 0.67723 0.67940 0.00049 0.07% 0.67779 0.00% 0.67762 0.00% 1.624 0.000 1.000 26.25 MB
PHP - baseline@cd8312e (JIT) 0.64253 0.64622 0.00066 0.10% 0.64323 -5.10% 0.64303 -5.11% 2.625 8.614 0.000 26.23 MB
PHP - jit-recv-known-object 0.67736 0.68170 0.00077 0.11% 0.67798 0.03% 0.67777 0.02% 3.152 -1.868 0.062 26.21 MB
PHP - jit-recv-known-object (JIT) 0.64236 0.67301 0.00562 0.87% 0.64395 -4.99% 0.64264 -5.16% 4.799 8.614 0.000 26.22 MB

Wordpress 6.9 main page - 50 iterations, 20 warmups, 20 requests (sec)

PHP Min Max Std dev Rel std dev % Mean Mean diff % Median Median diff % Skewness Z-stat P-value Memory
PHP - baseline@cd8312e 0.59640 0.60098 0.00070 0.12% 0.59735 0.00% 0.59725 0.00% 3.010 0.000 1.000 26.28 MB
PHP - baseline@cd8312e (JIT) 0.52281 0.52599 0.00065 0.12% 0.52373 -12.33% 0.52355 -12.34% 2.096 8.614 0.000 26.33 MB
PHP - jit-recv-known-object 0.59642 0.60001 0.00094 0.16% 0.59755 0.03% 0.59733 0.01% 1.699 -0.465 0.642 26.25 MB
PHP - jit-recv-known-object (JIT) 0.52306 0.53413 0.00162 0.31% 0.52434 -12.22% 0.52395 -12.27% 4.817 8.614 0.000 26.33 MB

bench.php - 50 iterations, 20 warmups, 2 requests (sec)

PHP Min Max Std dev Rel std dev % Mean Mean diff % Median Median diff % Skewness Z-stat P-value Memory
PHP - baseline@cd8312e 0.45144 0.45483 0.00078 0.17% 0.45291 0.00% 0.45289 0.00% 0.167 0.000 1.000 26.28 MB
PHP - baseline@cd8312e (JIT) 0.14386 0.14473 0.00022 0.15% 0.14431 -68.14% 0.14430 -68.14% -0.067 8.614 0.000 26.33 MB
PHP - jit-recv-known-object 0.45137 0.45542 0.00079 0.17% 0.45288 -0.01% 0.45283 -0.01% 0.669 0.358 0.720 26.25 MB
PHP - jit-recv-known-object (JIT) 0.14365 0.14517 0.00026 0.18% 0.14433 -68.13% 0.14432 -68.13% 0.461 8.614 0.000 26.33 MB

@arnaud-lb arnaud-lb left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

@github-actions

github-actions Bot commented Oct 6, 2026

Copy link
Copy Markdown

AWS x86_64 (c6id.metal)

Attribute Value
Environment aws
Instance type c6id.metal
Architecture x86_64
CPU Intel(R) Xeon(R) Platinum 8375C CPU @ 2.90GHz, 64 cores @ 2900 MHz
CPU settings disabled deeper C-states, disabled turbo boost, disabled hyper-threading
RAM 251 GB
Kernel 6.18.38-76.139.amzn2023.x86_64
OS Amazon Linux 2023.12.20260727
GCC 14.2.1
Binary layout strategy bolt-align
Time 2026-10-06 14:28:05 UTC
Job details https://github.com/php/php-src/actions/runs/37479130388 (Artifacts)
Changeset https://github.com/php/php-src/compare/cd8312e052..30f0cf6e6b

Laravel 12.11.0 demo app - 50 iterations, 50 warmups, 100 requests (sec)

PHP Min Max Std dev Rel std dev % Mean Mean diff % Median Median diff % Skewness Z-stat P-value Memory
PHP - baseline@cd8312e 0.37863 0.37930 0.00015 0.04% 0.37890 0.00% 0.37888 0.00% 0.732 0.000 1.000 31.77 MB
PHP - baseline@cd8312e (JIT) 0.35358 0.35507 0.00030 0.08% 0.35414 -6.54% 0.35407 -6.55% 1.222 8.614 0.000 31.71 MB
PHP - jit-recv-known-object 0.37875 0.37973 0.00020 0.05% 0.37918 0.07% 0.37917 0.08% 0.334 -6.397 0.000 31.76 MB
PHP - jit-recv-known-object (JIT) 0.35403 0.35566 0.00033 0.09% 0.35463 -6.41% 0.35460 -6.41% 0.990 8.614 0.000 31.71 MB

Symfony 2.8.0 demo app - 50 iterations, 50 warmups, 100 requests (sec)

PHP Min Max Std dev Rel std dev % Mean Mean diff % Median Median diff % Skewness Z-stat P-value Memory
PHP - baseline@cd8312e 0.68804 0.68908 0.00027 0.04% 0.68851 0.00% 0.68845 0.00% 0.235 0.000 1.000 31.91 MB
PHP - baseline@cd8312e (JIT) 0.64897 0.65773 0.00120 0.18% 0.64965 -5.64% 0.64947 -5.66% 6.519 8.614 0.000 31.83 MB
PHP - jit-recv-known-object 0.68792 0.68950 0.00038 0.06% 0.68854 0.00% 0.68850 0.01% 0.750 0.021 0.983 31.89 MB
PHP - jit-recv-known-object (JIT) 0.65053 0.65428 0.00058 0.09% 0.65106 -5.44% 0.65092 -5.45% 4.054 8.614 0.000 31.83 MB

Wordpress 6.9 main page - 50 iterations, 20 warmups, 20 requests (sec)

PHP Min Max Std dev Rel std dev % Mean Mean diff % Median Median diff % Skewness Z-stat P-value Memory
PHP - baseline@cd8312e 0.59356 0.59535 0.00038 0.06% 0.59435 0.00% 0.59436 0.00% 0.496 0.000 1.000 31.92 MB
PHP - baseline@cd8312e (JIT) 0.52034 0.52357 0.00053 0.10% 0.52106 -12.33% 0.52092 -12.36% 2.591 8.614 0.000 31.85 MB
PHP - jit-recv-known-object 0.59408 0.59593 0.00040 0.07% 0.59468 0.06% 0.59461 0.04% 1.467 -4.291 0.000 31.91 MB
PHP - jit-recv-known-object (JIT) 0.52155 0.52402 0.00051 0.10% 0.52239 -12.11% 0.52231 -12.12% 1.656 8.614 0.000 31.85 MB

bench.php - 50 iterations, 20 warmups, 2 requests (sec)

PHP Min Max Std dev Rel std dev % Mean Mean diff % Median Median diff % Skewness Z-stat P-value Memory
PHP - baseline@cd8312e 0.45210 0.45352 0.00032 0.07% 0.45276 0.00% 0.45281 0.00% -0.043 0.000 1.000 31.92 MB
PHP - baseline@cd8312e (JIT) 0.14453 0.14581 0.00019 0.13% 0.14480 -68.02% 0.14476 -68.03% 2.945 8.614 0.000 31.85 MB
PHP - jit-recv-known-object 0.45266 0.45478 0.00043 0.10% 0.45373 0.21% 0.45369 0.19% -0.119 -7.955 0.000 31.91 MB
PHP - jit-recv-known-object (JIT) 0.14457 0.14724 0.00038 0.26% 0.14489 -68.00% 0.14481 -68.02% 5.165 8.614 0.000 31.85 MB

@ndossche

ndossche commented Oct 8, 2026

Copy link
Copy Markdown
Member Author

Benchmark results are within noise, about −1.3 KB code size on the Symfony demo. We'll see...

@ndossche
ndossche merged commit c792847 into php:master Oct 8, 2026
18 checks passed
arnaud-lb added a commit to frodeborli/php-src that referenced this pull request Oct 9, 2026
* up/master: (180 commits)
  Changed the test expected result of `pdo_mysql/bug76815_pdo_mysql_f to %d (php#13808)
  ext/standard: name the real parameter in the unpack() offset error (php#24215)
  ext/readline: Refactor CLI readline completion generators
  Fix phpGH-24081: User opcode DISPATCH runs on a stale frame in the TAILCALL VM
  ext/standard: Validate the bcrypt cost before reading it
  JIT: Avoid object type check if the object is known to be a type (php#24086)
  zend_alloc: move a small block shrunk to the size of the bin below
  Fix phpGH-23979: Nullsafe operator must not flush delayed oplines of an enclosing function
  ext/zip: Reject ZipArchive mutators during close() (php#24025)
  Fix OSS-Fuzz #568005340: FETCH_DIM_FUNC_ARG partial conversion
  Fix too wide type inference for ASSIGN_DIM_OP
  Fix type inference of ADD_ARRAY_UNPACK with integer keys
  Evaluate ZEND_SPACESHIP in SCCP
  Add range inference for SPACESHIP
  JIT: Optimize array checks in comparisons (php#24084)
  Fix leak when the added previous exception is already in the chain (php#24177)
  date: Add `php_date_time_duration_create()` in a new `time_duration.h` (php#24072)
  ext/zip: Fix use-after-free in the archive destructor path (php#23779)
  ext/standard: Optimize array_chunk() by filling packed chunks directly
  Fix phpGH-17626: JIT corrupts opline handler when blacklisting root trace
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants