Skip to content

JITTed code duplication problem #10896

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
wxue1 opened this issue Mar 21, 2023 · 2 comments
Closed

JITTed code duplication problem #10896

wxue1 opened this issue Mar 21, 2023 · 2 comments

Comments

@wxue1
Copy link
Contributor

wxue1 commented Mar 21, 2023

Description

The following code:

<?php
function add($x){
    return $x + 1;
}

$x = 0;
for($i = 0; $i < 1000; $i++) {
    if($i % 10 == 0) {
        $x = add($x);
    }
    if($i % 8 == 0) {
        $x = add($x);
    }
}
echo("x=$x\n");
?>

Duplicated JITTed code in this case:

---- TRACE 2 start (side trace 1/7) $main() /home/wxue/php-src/t2.php:12
0013 INIT_FCALL 1 112 string("add")
     >init add
0014 SEND_VAR CV0($x) 1 ; op1(int)
0015 V2 = DO_UCALL
     >enter add
0001  T1 = ADD CV0($x) int(1) ; op1(int)
0002  RETURN T1 ; op1(int)
     <back /home/wxue/php-src/t2.php
0016 ASSIGN CV0($x) V2 ; op1(int) op2(int)
0017 PRE_INC CV1($i) ; op1(int)
---- TRACE 2 stop (link to 1)

---- TRACE 3 start (side trace 1/4) $main() /home/wxue/php-src/t2.php:9
0006 INIT_FCALL 1 112 string("add")
     >init add
0007 SEND_VAR CV0($x) 1 ; op1(int)
0008 V2 = DO_UCALL
     >enter add
0001  T1 = ADD CV0($x) int(1) ; op1(int)
0002  RETURN T1 ; op1(int)
     <back /home/wxue/php-src/t2.php
0009 ASSIGN CV0($x) V2 ; op1(int) op2(int)
0010 T3 = MOD CV1($i) int(8) ; op1(int)
0011 T2 = IS_EQUAL T3 int(0) ; op1(int)
0012 ;JMPZ T2 0017
0017 PRE_INC CV1($i) ; op1(int)
---- TRACE 3 stop (link to 1)

But I expected the add function to be JITTed only once.

PHP Version

PHP 8.1.4

Operating System

Ubuntu 20.04

@wxue1
Copy link
Contributor Author

wxue1 commented Mar 21, 2023

I create a PR to reduce the duplication. #10897

@iluuu1994
Copy link
Member

Thank you @wxue1! As you've already opened a PR I'm closing this issue, we generally don't keep a separate issue open anymore when providing a PR. I've copied your description so that we don't loose any context.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants