php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #79888 Incorrect execution with JIT enabled
Submitted: 2020-07-23 09:34 UTC Modified: 2020-07-29 13:31 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: stefan dot kaeser at diva-e dot com Assigned: dmitry (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 8.0.0alpha3 OS: Ubuntu 18.04
Private report: No CVE-ID: None
 [2020-07-23 09:34 UTC] stefan dot kaeser at diva-e dot com
Description:
------------
I have a very basic script for getting the ammount of PrimeNumbers by doing cascaded loops. It's mainly for testing execution times of differen programming languages.

When enabling the JIT options, the final result of the script shows an incorrect result.

Test was with Alpha3 of Php8, but could not choose that version in Dropdown yet.

--------
skaeser@whiplash:~/code/php$ time php7.4 TestPrime.php 
Testing Primes until: 250000
Primect: 22044

real	0m56,470s
user	0m56,456s
sys	0m0,009s
skaeser@whiplash:~/code/php$ time php8.0 TestPrime.php 
Testing Primes until: 250000
Primect: 22044

real	0m43,745s
user	0m43,733s
sys	0m0,008s
skaeser@whiplash:~/code/php$ time php8.0 -d opcache.enable_cli=1 -d opcache.jit_buffer_size=50000000 -d opcache.jit=1235 TestPrime.php 
Testing Primes until: 250000
Primect: 124998

real	0m0,023s
user	0m0,014s
sys	0m0,009s

 

Test script:
---------------
<?php
$max = 250000;
$cnt = 0;
echo "Testing Primes until: " . $max . "\n";
for ($i = 2; $i <= $max; $i++)
{
        if (testPrime($i)) $cnt++;
}
echo "Primect: {$cnt}\n";

function testPrime(int $a): bool
{
        if ($a < 2) 
        {
                return false;
        }
        else if ($a == 2) 
        {
                return true;
        }
        for ($j = 2; $j < $a; $j++)
        {
                if (($a % $j) == 0) 
                {
                        return false;
                }
        }
        return true;
}


Expected result:
----------------
Testing Primes until: 250000
Primect: 22044

Actual result:
--------------
Only with JIT enabled:

Testing Primes until: 250000
Primect: 124998


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-07-23 10:58 UTC] nikic@php.net
-Status: Open +Status: Verified
 [2020-07-23 10:58 UTC] nikic@php.net
Setting $max = 10000 to reduce runtime, with opcache.jit=1205 I get the incorrect result 5000 and with tracing JIT I get SIGFPE.
 [2020-07-23 11:49 UTC] carusogabriel@php.net
-PHP Version: 8.0.0alpha2 +PHP Version: 8.0.0alpha3
 [2020-07-29 13:31 UTC] dmitry@php.net
-Status: Verified +Status: Assigned -Assigned To: +Assigned To: dmitry
 [2020-07-29 14:33 UTC] dmitry@php.net
Automatic comment on behalf of dmitry@zend.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=02fae1fc537cd256233a5c0f51207a68fe2bd3d8
Log: Fixed bug #79888 (Incorrect execution with JIT enabled)
 [2020-07-29 14:33 UTC] dmitry@php.net
-Status: Assigned +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Oct 14 09:01:27 2024 UTC