public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH][vs] tree-optimization/110434 - avoid <retval> ={v} {CLOBBER} from NRV
@ 2023-06-28 13:54 Richard Biener
  0 siblings, 0 replies; only message in thread
From: Richard Biener @ 2023-06-28 13:54 UTC (permalink / raw)
  To: gcc-patches

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.

Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed.

	PR tree-optimization/110434
	* tree-nrv.cc (pass_nrv::execute): Remove CLOBBERs of
	VAR we replace with <retval>.
---
 gcc/tree-nrv.cc | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/gcc/tree-nrv.cc b/gcc/tree-nrv.cc
index ff47439647c..99c4e21a842 100644
--- a/gcc/tree-nrv.cc
+++ b/gcc/tree-nrv.cc
@@ -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);
 	    }
 	}
-- 
2.35.3

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-06-28 13:54 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-28 13:54 [PATCH][vs] tree-optimization/110434 - avoid <retval> ={v} {CLOBBER} from NRV Richard Biener

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).