|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #79353 bad optimizing "Null Coalescing Assignment"
Submitted: 2020-03-08 02:46 UTC Modified: 2020-03-10 10:44 UTC
From: bugreports at gmail dot com Assigned: nikic (profile)
Status: Assigned Package: opcache
PHP Version: 7.4Git-2020-03-08 (Git) OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: bugreports at gmail dot com
New email:
PHP Version: OS:


 [2020-03-08 02:46 UTC] bugreports at gmail dot com
with opcache other than "Null coalescing operator" the "Null Coalescing Assignment" is not completly optimized out

function a()
 $test = $test ?? TRUE;
 return $test;

function b()
 $test ??= TRUE;
 return $test;

runtime difference with 50000000 calls:
a(): 3.1884
b(): 3.3666

function name:  a
number of ops:  2
   5     0*       COALESCE                                         ~1      !0
   6     1*       RETURN                                                   <true>

function name:  b
number of ops:  3
  11     0*       COALESCE                                         ~1      !0
         1*       ASSIGN                                           $2      !0, <true>
  12     2*       RETURN                                                   !0


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2020-03-09 14:34 UTC]
-Assigned To: +Assigned To: nikic
 [2020-03-09 14:34 UTC]
I think we mainly need to add pi node placement for coalesce.
 [2020-03-09 15:21 UTC]

Pi node placement turned out to be more complicated than anticipated, because it did not pass our existing profitability heuristic.
 [2020-03-10 10:29 UTC] bugreports at gmail dot com
as i understand that it will be part of PHP8 and not optimized for 7.4?
 [2020-03-10 10:44 UTC]
Yes, this is only for master, as the change is non-trivial.

I'm also keeping this issue open, because we should still try to remove the COALESCE itself.
 [2022-12-22 09:43 UTC] melindaetinw81 at gmail dot com
I'll be sure to keep an eye on this thread. 

PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Sun Jan 29 09:03:44 2023 UTC