Skip to content

JITTed code duplication problem #10896

Closed
Closed

Description

@wxue1

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

Activity

  1. wxue1 commented on Mar 21, 2023

    @wxue1
    Author

    I create a PR to reduce the duplication. #10897

  2. iluuu1994 commented on Mar 21, 2023

    @iluuu1994
    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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions