diff mbox

[ARM] : PR67745: Fix function alignment after __attribute__ 2/2

Message ID 560A90F2.5010708@st.com
State New
Headers show

Commit Message

Christian Bruel Sept. 29, 2015, 1:24 p.m. UTC
This patch uses FUNCTION_BOUNDARY instead of DECL_ALIGN to check the max
align when optimizing for size in assemble_start_function.
This is necessary for ARM that can switch the max code alignment
directives between modes.

No regressions for ARM
Testing on-going for x86

Christian

Comments

Christian Bruel Sept. 29, 2015, 1:43 p.m. UTC | #1
On 09/29/2015 03:24 PM, Christian Bruel wrote:
> This patch uses FUNCTION_BOUNDARY instead of DECL_ALIGN to check the max
> align when optimizing for size in assemble_start_function.
> This is necessary for ARM that can switch the max code alignment
> directives between modes.
> 
s/max/min
Jeff Law Sept. 30, 2015, 7:02 p.m. UTC | #2
On 09/29/2015 07:24 AM, Christian Bruel wrote:
> This patch uses FUNCTION_BOUNDARY instead of DECL_ALIGN to check the max
> align when optimizing for size in assemble_start_function.
> This is necessary for ARM that can switch the max code alignment
> directives between modes.
>
> No regressions for ARM
> Testing on-going for x86
>
> Christian
>
>
> align2.patch
>
>
> 2015-09-29  Christian Bruel<christian.bruel@st.com>
>
> 	PR target/67745
> 	* gcc/varasm.c (assemble_start_function): Use current's function align.
Does this override alignment information that might be attached to the 
DECL?   Does that, in effect, override any alignment information that 
the developer may have put on the decl?  If so, then it seems like a bad 
idea, even with -Os.

Am I missing something here?

jeff
Christian Bruel Oct. 1, 2015, 7:12 a.m. UTC | #3
On 09/30/2015 09:02 PM, Jeff Law wrote:
> On 09/29/2015 07:24 AM, Christian Bruel wrote:
>> This patch uses FUNCTION_BOUNDARY instead of DECL_ALIGN to check the max
>> align when optimizing for size in assemble_start_function.
>> This is necessary for ARM that can switch the max code alignment
>> directives between modes.
>>
>> No regressions for ARM
>> Testing on-going for x86
>>
>> Christian
>>
>>
>> align2.patch
>>
>>
>> 2015-09-29  Christian Bruel<christian.bruel@st.com>
>>
>> 	PR target/67745
>> 	* gcc/varasm.c (assemble_start_function): Use current's function align.
> Does this override alignment information that might be attached to the 
> DECL?  

Yes. Well, in the backend, for architectural (ABI) defined alignment,
FUNCTION_BOUNDARY is used instead of DECL_ALIGN. And DECL_ALIGN is set
with FUNCTION_BOUNDARY (make_node_stat) so they are accidentally
equivalent if FUNCTION_BOUNDARY does not get changed due to switchable
target.

 Does that, in effect, override any alignment information that
> the developer may have put on the decl?  If so, then it seems like a bad 
> idea, even with -Os.

No it doesn't affect user alignments, that are carried thru
align_functions_log, that prevails over the DECL_ALIGN.
I played with various configurations of -falign-functions=x,
__attribute__((aligned(x))), optimization levels for arm and x86 and was
happy with them.

> 
> Am I missing something here?

Your comment makes me think about the direction I've taken to replace
DECL_ALIGN by FUNCTION_BOUNDARY, and the problem might not be user align
vs DECL_ALIGN: I stepped upon Jan's patch for a fortran regression.

2015-03-05  Jan Hubicka  <hubicka@ucw.cz>

	PR ipa/65334
	* cgraph.h (symtab_node): Add definition_alignment,

My patch was tested only for languages=c/c++. I'm going to give it a try
with Fortran.
If this is not satisfactory I'll have to think about updating DECL_ALIGN
after the function's attribute are processed and keep using it in
assemble_start_function.

Come back later

thanks,
diff mbox

Patch

2015-09-29  Christian Bruel  <christian.bruel@st.com>

	PR target/67745
	* gcc/varasm.c (assemble_start_function): Use current's function align.

Index: gcc/varasm.c
===================================================================
--- gcc/varasm.c	(revision 228229)
+++ gcc/varasm.c	(working copy)
@@ -1729,7 +1729,7 @@  assemble_start_function (tree decl, cons
   if (CONSTANT_POOL_BEFORE_FUNCTION)
     output_constant_pool (fnname, decl);
 
-  align = symtab_node::get (decl)->definition_alignment ();
+  align = FUNCTION_BOUNDARY;
 
   /* Make sure the not and cold text (code) sections are properly
      aligned.  This is necessary here in the case where the function
@@ -1774,12 +1774,15 @@  assemble_start_function (tree decl, cons
       ASM_OUTPUT_ALIGN (asm_out_file, align);
     }
 
+  /* align_functions_log cannot exceed current function's ABI when
+     optimizing for size  */
+  if (optimize_function_for_size_p (cfun))
+    align_functions_log = MIN (align_functions_log, align);
+
   /* Handle a user-specified function alignment.
      Note that we still need to align to DECL_ALIGN, as above,
      because ASM_OUTPUT_MAX_SKIP_ALIGN might not do any alignment at all.  */
-  if (! DECL_USER_ALIGN (decl)
-      && align_functions_log > align
-      && optimize_function_for_speed_p (cfun))
+  if (! DECL_USER_ALIGN (decl) && align_functions_log > align)
     {
 #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
       ASM_OUTPUT_MAX_SKIP_ALIGN (asm_out_file,