public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Respect user align for local variable
@ 2020-03-30 10:31 Kito Cheng
  2020-03-30 11:20 ` Jakub Jelinek
  0 siblings, 1 reply; 3+ messages in thread
From: Kito Cheng @ 2020-03-30 10:31 UTC (permalink / raw)
  To: gcc-patches, kito.cheng, jakub, pinskia; +Cc: Kito Cheng

gcc/ChangeLog

	* cfgexpand.c (align_local_variable): Check DECL_USER_ALIGN.
---
 gcc/cfgexpand.c | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/gcc/cfgexpand.c b/gcc/cfgexpand.c
index a7ec77d5c85..19a020b4b97 100644
--- a/gcc/cfgexpand.c
+++ b/gcc/cfgexpand.c
@@ -369,13 +369,19 @@ align_local_variable (tree decl, bool really_expand)
     align = TYPE_ALIGN (TREE_TYPE (decl));
   else
     {
-      align = LOCAL_DECL_ALIGNMENT (decl);
-      /* Don't change DECL_ALIGN when called from estimated_stack_frame_size.
-	 That is done before IPA and could bump alignment based on host
-	 backend even for offloaded code which wants different
-	 LOCAL_DECL_ALIGNMENT.  */
-      if (really_expand)
-	SET_DECL_ALIGN (decl, align);
+      if (DECL_USER_ALIGN (decl))
+	align = DECL_ALIGN (decl);
+      else
+	{
+	  align = LOCAL_DECL_ALIGNMENT (decl);
+	  /* Don't change DECL_ALIGN when called from
+	     estimated_stack_frame_size.
+	     That is done before IPA and could bump alignment based on host
+	     backend even for offloaded code which wants different
+	     LOCAL_DECL_ALIGNMENT.  */
+	  if (really_expand)
+	    SET_DECL_ALIGN (decl, align);
+	}
     }
   return align / BITS_PER_UNIT;
 }
-- 
2.25.2


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

* Re: [PATCH] Respect user align for local variable
  2020-03-30 10:31 [PATCH] Respect user align for local variable Kito Cheng
@ 2020-03-30 11:20 ` Jakub Jelinek
  2020-03-30 12:37   ` Kito Cheng
  0 siblings, 1 reply; 3+ messages in thread
From: Jakub Jelinek @ 2020-03-30 11:20 UTC (permalink / raw)
  To: Kito Cheng; +Cc: gcc-patches, kito.cheng, jakub, pinskia

On Mon, Mar 30, 2020 at 06:31:27PM +0800, Kito Cheng wrote:
> gcc/ChangeLog
> 
> 	* cfgexpand.c (align_local_variable): Check DECL_USER_ALIGN.

Why?  LOCAL_DECL_ALIGNMENT surely shouldn't decrease alignment of decls
with DECL_USER_ALIGN vars (but do you have evidence that it does),
but it is just fine to increase alignment of vars with explicit alignment
requirements if the compiler thinks it is beneficial.  Larger alignment
still satisfies the user requirement...

	Jakub


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

* Re: [PATCH] Respect user align for local variable
  2020-03-30 11:20 ` Jakub Jelinek
@ 2020-03-30 12:37   ` Kito Cheng
  0 siblings, 0 replies; 3+ messages in thread
From: Kito Cheng @ 2020-03-30 12:37 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: GCC Patches, Kito Cheng, jakub, Andrew Pinski

Hi Jakub:

Thanks for your correction, I read the doc for the aligned attribute
again[1], it's minimum alignment not restricted alignment, I thought
it should honor to the alignment attribute, Richard Biener
suggested[2] should put an assertion here to make sure never decrease
alignment here, so I'll send another patch for add assertion.

[1] https://gcc.gnu.org/onlinedocs/gcc/Common-Type-Attributes.html#Common-Type-Attributes
[2] https://gcc.gnu.org/pipermail/gcc-patches/2020-March/542808.html

On Mon, Mar 30, 2020 at 7:21 PM Jakub Jelinek <jakub@redhat.com> wrote:
>
> On Mon, Mar 30, 2020 at 06:31:27PM +0800, Kito Cheng wrote:
> > gcc/ChangeLog
> >
> >       * cfgexpand.c (align_local_variable): Check DECL_USER_ALIGN.
>
> Why?  LOCAL_DECL_ALIGNMENT surely shouldn't decrease alignment of decls
> with DECL_USER_ALIGN vars (but do you have evidence that it does),
> but it is just fine to increase alignment of vars with explicit alignment
> requirements if the compiler thinks it is beneficial.  Larger alignment
> still satisfies the user requirement...
>
>         Jakub
>

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

end of thread, other threads:[~2020-03-30 12:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-30 10:31 [PATCH] Respect user align for local variable Kito Cheng
2020-03-30 11:20 ` Jakub Jelinek
2020-03-30 12:37   ` Kito Cheng

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).