public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-5709] middle-end/103271 - avoid VLA init of register
@ 2021-12-02 12:35 Richard Biener
  0 siblings, 0 replies; only message in thread
From: Richard Biener @ 2021-12-02 12:35 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:06b8cdc8d7339ac44802044ef148dd86874333d8

commit r12-5709-g06b8cdc8d7339ac44802044ef148dd86874333d8
Author: Richard Biener <rguenther@suse.de>
Date:   Thu Dec 2 12:23:22 2021 +0100

    middle-end/103271 - avoid VLA init of register
    
    This avoids using VLA types to initalize a register with
    -ftrivial-auto-var-init in some cases.
    
    2021-12-02  Richard Biener  <rguenther@suse.de>
    
            PR middle-end/103271
            * internal-fn.c (expand_DEFERRED_INIT): When the base
            of the LHS is a decl with matching constant size use
            that as the initialization target instead of an
            eventual VLA typed one.

Diff:
---
 gcc/internal-fn.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/gcc/internal-fn.c b/gcc/internal-fn.c
index 6ac3460d538..08f94b7a17a 100644
--- a/gcc/internal-fn.c
+++ b/gcc/internal-fn.c
@@ -3050,6 +3050,23 @@ expand_DEFERRED_INIT (internal_fn, gcall *stmt)
 	lhs_base = TREE_OPERAND (lhs_base, 0);
       reg_lhs = (mem_ref_refers_to_non_mem_p (lhs_base)
 		 || non_mem_decl_p (lhs_base));
+      /* If this expands to a register and the underlying decl is wrapped in
+	 a MEM_REF that just serves as an access type change expose the decl
+	 if it is of correct size.  This avoids a situation as in PR103271
+	 if the target does not support a direct move to the registers mode.  */
+      if (reg_lhs
+	  && TREE_CODE (lhs_base) == MEM_REF
+	  && TREE_CODE (TREE_OPERAND (lhs_base, 0)) == ADDR_EXPR
+	  && DECL_P (TREE_OPERAND (TREE_OPERAND (lhs_base, 0), 0))
+	  && integer_zerop (TREE_OPERAND (lhs_base, 1))
+	  && tree_fits_uhwi_p (var_size)
+	  && tree_int_cst_equal
+	       (var_size,
+		DECL_SIZE_UNIT (TREE_OPERAND (TREE_OPERAND (lhs_base, 0), 0))))
+	{
+	  lhs = TREE_OPERAND (TREE_OPERAND (lhs_base, 0), 0);
+	  var_type = TREE_TYPE (lhs);
+	}
     }
 
   if (!reg_lhs)


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

only message in thread, other threads:[~2021-12-02 12:35 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-02 12:35 [gcc r12-5709] middle-end/103271 - avoid VLA init of register 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).