Skip to content

Commit f1fd08c

Browse files
committed
Added few Optimizer tests
1 parent 3b8f9d9 commit f1fd08c

File tree

6 files changed

+193
-0
lines changed

6 files changed

+193
-0
lines changed

ext/opcache/tests/opt/dce_001.phpt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
--TEST--
2+
DCE 001: Remove dead computation after constants propagation
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.optimization_level=-1
7+
opcache.opt_debug_level=0x20000
8+
--SKIPIF--
9+
<?php require_once('skipif.inc'); ?>
10+
--FILE--
11+
<?php
12+
function foo(string $s1, string $s2, string $s3, string $s4) {
13+
$x = ($s1 . $s2) . ($s3 . $s4);
14+
$x = 0;
15+
return $x;
16+
}
17+
?>
18+
--EXPECTF--
19+
$_main: ; (lines=1, args=0, vars=0, tmps=0)
20+
; (after optimizer)
21+
; %sdce_001.php:1-8
22+
L0: RETURN int(1)
23+
24+
foo: ; (lines=5, args=4, vars=4, tmps=3)
25+
; (after optimizer)
26+
; %sdce_001.php:2-6
27+
L0: CV0($s1) = RECV 1
28+
L1: CV1($s2) = RECV 2
29+
L2: CV2($s3) = RECV 3
30+
L3: CV3($s4) = RECV 4
31+
L4: RETURN int(0)

ext/opcache/tests/opt/dce_002.phpt

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
--TEST--
2+
DCE 002: func_get_args() disables deletion of assignments to parameter variables
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.optimization_level=-1
7+
opcache.opt_debug_level=0x20000
8+
--SKIPIF--
9+
<?php require_once('skipif.inc'); ?>
10+
--FILE--
11+
<?php
12+
function foo(int $a) {
13+
$a = 10;
14+
$b = 20;
15+
$x = func_get_args();
16+
$a = 30;
17+
$b = 40;
18+
return $x;
19+
}
20+
?>
21+
--EXPECTF--
22+
$_main: ; (lines=1, args=0, vars=0, tmps=0)
23+
; (after optimizer)
24+
; %sdce_002.php:1-11
25+
L0: RETURN int(1)
26+
27+
foo: ; (lines=5, args=1, vars=2, tmps=1)
28+
; (after optimizer)
29+
; %sdce_002.php:2-9
30+
L0: CV0($a) = RECV 1
31+
L1: CV0($a) = QM_ASSIGN int(10)
32+
L2: CV1($x) = FUNC_GET_ARGS
33+
L3: CV0($a) = QM_ASSIGN int(30)
34+
L4: RETURN CV1($x)

ext/opcache/tests/opt/dce_003.phpt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
--TEST--
2+
DCE 003: Assignment elimination (without FREE)
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.optimization_level=-1
7+
opcache.opt_debug_level=0x20000
8+
--SKIPIF--
9+
<?php require_once('skipif.inc'); ?>
10+
--FILE--
11+
<?php
12+
function foo($a) {
13+
$b = $a += 3;
14+
return $a;
15+
}
16+
?>
17+
--EXPECTF--
18+
$_main: ; (lines=1, args=0, vars=0, tmps=0)
19+
; (after optimizer)
20+
; %sdce_003.php:1-7
21+
L0: RETURN int(1)
22+
23+
foo: ; (lines=3, args=1, vars=1, tmps=1)
24+
; (after optimizer)
25+
; %sdce_003.php:2-5
26+
L0: CV0($a) = RECV 1
27+
L1: ASSIGN_ADD CV0($a) int(3)
28+
L2: RETURN CV0($a)

ext/opcache/tests/opt/dce_004.phpt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
--TEST--
2+
DCE 004: Elimination of assignment to escaping arrays
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.optimization_level=-1
7+
opcache.opt_debug_level=0x20000
8+
--SKIPIF--
9+
<?php require_once('skipif.inc'); ?>
10+
--FILE--
11+
<?php
12+
function foo(int $x, int $y) {
13+
$a = [$x];
14+
$a[1] = $y;
15+
$a = $y;
16+
return $a;
17+
}
18+
--EXPECTF--
19+
$_main: ; (lines=1, args=0, vars=0, tmps=0)
20+
; (after optimizer)
21+
; %sdce_004.php:1-8
22+
L0: RETURN int(1)
23+
24+
foo: ; (lines=4, args=2, vars=3, tmps=1)
25+
; (after optimizer)
26+
; %sdce_004.php:2-7
27+
L0: CV0($x) = RECV 1
28+
L1: CV1($y) = RECV 2
29+
L2: CV2($a) = QM_ASSIGN CV1($y)
30+
L3: RETURN CV2($a)

ext/opcache/tests/opt/dce_005.phpt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
--TEST--
2+
DCE 005: Elimination of assignment to escaping objects (can't remove NEW yet)
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.optimization_level=-1
7+
opcache.opt_debug_level=0x20000
8+
--SKIPIF--
9+
<?php require_once('skipif.inc'); ?>
10+
--FILE--
11+
<?php
12+
class A {
13+
}
14+
function foo(int $x) {
15+
$a = new A;
16+
$a->foo = $x;
17+
}
18+
--EXPECTF--
19+
$_main: ; (lines=1, args=0, vars=0, tmps=0)
20+
; (after optimizer)
21+
; %sdce_005.php:1-8
22+
L0: RETURN int(1)
23+
24+
foo: ; (lines=5, args=1, vars=1, tmps=1)
25+
; (after optimizer)
26+
; %sdce_005.php:4-7
27+
L0: CV0($x) = RECV 1
28+
L1: V1 = NEW 0 string("A")
29+
L2: DO_FCALL
30+
L3: FREE V1
31+
L4: RETURN null

ext/opcache/tests/opt/dce_006.phpt

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
--TEST--
2+
DCE 006: Objects with destructors don't escape
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.optimization_level=-1
7+
opcache.opt_debug_level=0x20000
8+
--SKIPIF--
9+
<?php require_once('skipif.inc'); ?>
10+
--FILE--
11+
<?php
12+
class A {
13+
function __destruct() {}
14+
}
15+
function foo(int $x) {
16+
$a = new A;
17+
$a->foo = $x;
18+
}
19+
--EXPECTF--
20+
$_main: ; (lines=1, args=0, vars=0, tmps=0)
21+
; (after optimizer)
22+
; %sdce_006.php:1-9
23+
L0: RETURN int(1)
24+
25+
foo: ; (lines=7, args=1, vars=2, tmps=1)
26+
; (after optimizer)
27+
; %sdce_006.php:5-8
28+
L0: CV0($x) = RECV 1
29+
L1: V2 = NEW 0 string("A")
30+
L2: DO_FCALL
31+
L3: CV1($a) = QM_ASSIGN V2
32+
L4: ASSIGN_OBJ CV1($a) string("foo")
33+
L5: OP_DATA CV0($x)
34+
L6: RETURN null
35+
36+
A::__destruct: ; (lines=1, args=0, vars=0, tmps=0)
37+
; (after optimizer)
38+
; %sdce_006.php:3-3
39+
L0: RETURN null

0 commit comments

Comments
 (0)