]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-optimization/110434 - avoid <retval> ={v} {CLOBBER} from NRV
authorRichard Biener <rguenther@suse.de>
Wed, 28 Jun 2023 09:27:45 +0000 (11:27 +0200)
committerRichard Biener <rguenther@suse.de>
Wed, 28 Jun 2023 13:52:16 +0000 (15:52 +0200)
When NRV replaces a local variable with <retval> it also replaces
occurences in clobbers.  This leads to <retval> being clobbered
before the return of it which is strictly invalid but harmless in
practice since there's no pass after NRV which would remove
earlier stores.

The following fixes this nevertheless.

PR tree-optimization/110434
* tree-nrv.cc (pass_nrv::execute): Remove CLOBBERs of
VAR we replace with <retval>.

gcc/tree-nrv.cc

index ff47439647c2a3ddd920a221d1e22a1a838a1ea3..99c4e21a842b38966a20a2eac41034db0a931b78 100644 (file)
@@ -264,7 +264,17 @@ pass_nrv::execute (function *fun)
              data.modified = 0;
              walk_gimple_op (stmt, finalize_nrv_r, &wi);
              if (data.modified)
-               update_stmt (stmt);
+               {
+                 /* If this is a CLOBBER of VAR, remove it.  */
+                 if (gimple_clobber_p (stmt))
+                   {
+                     unlink_stmt_vdef (stmt);
+                     gsi_remove (&gsi, true);
+                     release_defs (stmt);
+                     continue;
+                   }
+                 update_stmt (stmt);
+               }
              gsi_next (&gsi);
            }
        }