Skip to content

Opcache idea: Support !is_int($x) #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
TysonAndre opened this issue Nov 12, 2019 · 0 comments
Closed

Opcache idea: Support !is_int($x) #7

TysonAndre opened this issue Nov 12, 2019 · 0 comments

Comments

@TysonAndre
Copy link
Owner

TysonAndre commented Nov 12, 2019

Related to #6 - the BOOL_NOT can be skipped

» ~/php-8.0.0-dev-install/bin/php -d opcache.file_cache= -d opcache.opt_debug_level=0x20000 test.php

$_main: ; (lines=1, args=0, vars=0, tmps=0)
    ; (after optimizer)
    ; /path/to/test.php:1-6
L0 (6):     RETURN int(1)

f1: ; (lines=10, args=2, vars=2, tmps=2)
    ; (after optimizer)
    ; /path/to/test.php:2-5
L0 (2):     CV0($x) = RECV 1
L1 (2):     CV1($y) = RECV 2
L2 (3):     INIT_FCALL 1 96 string("var_export")
L3 (3):     T3 = TYPE_CHECK (long) CV1($y)
L4 (3):     T2 = BOOL_NOT T3
L5 (3):     SEND_VAL T2 1
L6 (3):     DO_ICALL
L7 (4):     T3 = TYPE_CHECK (long) CV1($y)
L8 (4):     T2 = BOOL_NOT T3
L9 (4):     RETURN T2
TysonAndre pushed a commit that referenced this issue Apr 25, 2021
When encountering the following SSA graph:

    BB1:
    #2.T1 [string] = COALESCE #1.CV0($str) [null, string] BB2

    BB2:
    #5.T1 [string] = QM_ASSIGN string("")

    BB3:
    #7.X1 [string] = Phi(#2.X1 [string], #5.X1 [string])
    FREE #7.T1 [string]

We would currently determine that #7, #5 are dead, and eliminate
the FREE and QM_ASSIGN. However, we cannot eliminate #2, as
COALESCE is also responsible for control flow.

Fix this my marking all non-CV phis as live to start with. This
can be relaxed to check the kind of the source instruction, but
I couldn't immediately come up with a case where it would be
useful.
TysonAndre pushed a commit that referenced this issue May 31, 2021
The following opcodes would be generated:

  ...
  BB1:
  0003 JMP BB3

  BB2:
  0004 INIT_FCALL 1 96 string("chr")
  0005 #10.T3 [long] = SR #3.CV0($int) [long] #7.CV2($i) ...
  0006 #11.T4 [long] RANGE[0..127] = BW_AND #10.T3 [long] ...
  0007 #12.T3 [long] RANGE[128..255] = BW_OR #11.T4 [long] ...
  0008 SEND_VAL #12.T3 [long] RANGE[128..255] 1
  0009 #13.V3 [ref, rc1, rcn, any] = DO_ICALL
  0010 ASSIGN_OP (CONCAT) #6.CV1($out) [rc1, rcn, string]
  0011 ADD #7.CV2($i)... int(7) #7.CV2($i) ... -> #15.CV2($i) ...

  BB3:
  0012 #8.T4 [long] = SR #3.CV0($int) #7.CV2($i) [long, double]
  0013 #9.T3 [bool] RANGE[0..1] = IS_SMALLER int(128) #8.T4
  0014 JMPNZ #9.T3 [bool] RANGE[0..1] BB2
  ...

Main changes are:
1. SR opcode covers new path in function zend_jit_long_math_helper().
2. BW_AND and BW_OR opcodes are supported. See macro LONG_OP.
3. Function zend_jit_concat_helper() is added to support ASSIGN_OP
opcode. Speficically, CONCAT and FAST_CONCAT is supported for statements
"$out .= ...".
4. New path is covered in function zend_jit_cmp_long_long() by
IS_SMALLER opcode.
5. New path is covered in macros ZVAL_PTR_DTOR and ZVAL_DTOR_FUNC when
leaving.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant