mirror of
https://github.com/php/php-src.git
synced 2026-03-24 00:02:20 +01:00
The aim of this PR is twofold:
- Reduce the number of highly similar TMP|VAR handlers
- Avoid ZVAL_DEREF in most of these cases
This is achieved by guaranteeing that all zend_compile_expr() calls, as well as
all other compile calls with BP_VAR_{R,IS}, will result in a TMP variable. This
implies that the result will not contain an IS_INDIRECT or IS_REFERENCE value,
which was mostly already the case, with two exceptions:
- Calls to return-by-reference functions. Because return-by-reference functions
are quite rare, this is solved by delegating the DEREF to the RETURN_BY_REF
handler, which will examine the stack to check whether the caller expects a
VAR or TMP to understand whether the DEREF is needed. Internal functions will
also need to adjust by calling the zend_return_unwrap_ref() function.
- By-reference assignments, including both $a = &$b, as well as $a = [&$b]. When
the result of these expressions is used in a BP_VAR_R context, the reference
is unwrapped via a ZEND_QM_ASSIGN opcode beforehand. This is exceptionally
rare.
Closes GH-20628
89 lines
1.7 KiB
PHP
89 lines
1.7 KiB
PHP
--TEST--
|
|
Pipe operator optimizes away most callables
|
|
--INI--
|
|
opcache.enable=1
|
|
opcache.enable_cli=1
|
|
opcache.opt_debug_level=0x20000
|
|
--EXTENSIONS--
|
|
opcache
|
|
--FILE--
|
|
<?php
|
|
|
|
function _test1(int $a): int {
|
|
return $a + 1;
|
|
}
|
|
|
|
class Other {
|
|
public function foo(int $a): int {
|
|
return $a * 2;
|
|
}
|
|
|
|
public static function bar(int $a): int {
|
|
return $a -1;
|
|
}
|
|
}
|
|
|
|
$o = new Other();
|
|
|
|
$res1 = 5
|
|
|> _test1(...)
|
|
|> $o->foo(...)
|
|
|> Other::bar(...)
|
|
;
|
|
|
|
var_dump($res1);
|
|
?>
|
|
--EXPECTF--
|
|
$_main:
|
|
; (lines=17, args=0, vars=2, tmps=%d)
|
|
; (after optimizer)
|
|
; %s:1-27
|
|
0000 T2 = NEW 0 string("Other")
|
|
0001 DO_FCALL
|
|
0002 ASSIGN CV0($o) T2
|
|
0003 INIT_FCALL 1 %d string("_test1")
|
|
0004 SEND_VAL int(5) 1
|
|
0005 T2 = DO_UCALL
|
|
0006 INIT_METHOD_CALL 1 CV0($o) string("foo")
|
|
0007 SEND_VAL_EX T2 1
|
|
0008 T2 = DO_FCALL
|
|
0009 INIT_STATIC_METHOD_CALL 1 string("Other") string("bar")
|
|
0010 SEND_VAL T2 1
|
|
0011 T2 = DO_UCALL
|
|
0012 ASSIGN CV1($res1) T2
|
|
0013 INIT_FCALL 1 %d string("var_dump")
|
|
0014 SEND_VAR CV1($res1) 1
|
|
0015 DO_ICALL
|
|
0016 RETURN int(1)
|
|
LIVE RANGES:
|
|
2: 0001 - 0002 (new)
|
|
2: 0009 - 0010 (tmp/var)
|
|
|
|
_test1:
|
|
; (lines=4, args=1, vars=1, tmps=%d)
|
|
; (after optimizer)
|
|
; %s:3-5
|
|
0000 CV0($a) = RECV 1
|
|
0001 T1 = ADD CV0($a) int(1)
|
|
0002 VERIFY_RETURN_TYPE T1
|
|
0003 RETURN T1
|
|
|
|
Other::foo:
|
|
; (lines=4, args=1, vars=1, tmps=%d)
|
|
; (after optimizer)
|
|
; %s:8-10
|
|
0000 CV0($a) = RECV 1
|
|
0001 T1 = ADD CV0($a) CV0($a)
|
|
0002 VERIFY_RETURN_TYPE T1
|
|
0003 RETURN T1
|
|
|
|
Other::bar:
|
|
; (lines=4, args=1, vars=1, tmps=%d)
|
|
; (after optimizer)
|
|
; %s:12-14
|
|
0000 CV0($a) = RECV 1
|
|
0001 T1 = SUB CV0($a) int(1)
|
|
0002 VERIFY_RETURN_TYPE T1
|
|
0003 RETURN T1
|
|
int(11)
|