public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
[parent not found: <20230628102150.620743857B8E@sourceware.org>]
* [PATCH] tree-optimization/110434 - avoid <retval> ={v} {CLOBBER} from NRV
@ 2023-06-28 10:21 Richard Biener
  0 siblings, 0 replies; 5+ messages in thread
From: Richard Biener @ 2023-06-28 10:21 UTC (permalink / raw)
  To: gcc-patches; +Cc: Jakub Jelinek

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, OK?

Thanks,
Richard.

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

diff --git a/gcc/tree-nrv.cc b/gcc/tree-nrv.cc
index ff47439647c..466b491e4e7 100644
--- a/gcc/tree-nrv.cc
+++ b/gcc/tree-nrv.cc
@@ -256,6 +256,14 @@ pass_nrv::execute (function *fun)
 	      gsi_remove (&gsi, true);
 	      release_defs (stmt);
 	    }
+	  /* If this is a CLOBBER of VAR, remove it.  */
+	  else if (gimple_clobber_p (stmt)
+		   && gimple_assign_lhs (stmt) == found)
+	    {
+	      unlink_stmt_vdef (stmt);
+	      gsi_remove (&gsi, true);
+	      release_defs (stmt);
+	    }
 	  else
 	    {
 	      struct walk_stmt_info wi;
-- 
2.35.3

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-06-28 14:19 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20230628102159.84C093858412@sourceware.org>
2023-06-28 14:19 ` [PATCH] tree-optimization/110434 - avoid <retval> ={v} {CLOBBER} from NRV Jeff Law
     [not found] <20230628102150.620743857B8E@sourceware.org>
2023-06-28 10:37 ` Jakub Jelinek
2023-06-28 12:32   ` Richard Biener
2023-06-28 12:38     ` Jakub Jelinek
2023-06-28 10:21 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).