diff mbox

[v2] PR48344: Fix unrecognizable insn error when gcc

Message ID 56A000D9.4080902@linux.vnet.ibm.com
State New
Headers show

Commit Message

Kelvin Nilsen Jan. 20, 2016, 9:49 p.m. UTC
This patch has bootstrapped and tested on powerpc64le-unknown-linux-gnu 
with no regressions.  Is this ok for the trunk?

See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=48344 for the original 
problem report.  The error resulted because gcc's processing of 
command-line options within gcc initialization code originally preceded 
the processing of target-specific configuration hooks.

In the unpatched gcc implementation, the Pmode (pointer mode) variable 
has not been initialized at the time the -fstack-limit-register 
command-line option is processed.  As a consequence, the stack-limiting 
register is not assigned a proper mode.  Thus, rtl instructions that 
make use of this stack-limiting register have an unspecified mode, and 
are therefore not matched by any known instructions.

The fix represented in this patch is to move the invocation of 
process_options () from within the implementation of do_compile () to 
immediately preceding the invocation of handle_common_deferred_options 
() (inside toplev::main ()).

gcc/ChangeLog:

2016-01-14  Kelvin Nilsen <kelvin@gcc.gnu.org>

     * toplev.c (do_compile): remove invocation of process_options ()
         from within do_compile ()
     (toplev::main): insert invocation of process_options () before
         invocation of handle_common_deferred_options ().

gcc/testsuite/ChangeLog:

2016-01-14  Kelvin Nilsen <kelvin@gcc.gnu.org>

     * gcc.target/powerpc/pr48344-1.c: New test.

Comments

Bernd Schmidt Jan. 20, 2016, 11:51 p.m. UTC | #1
On 01/20/2016 10:49 PM, Kelvin Nilsen wrote:

>      * toplev.c (do_compile): remove invocation of process_options ()
>          from within do_compile ()
>      (toplev::main): insert invocation of process_options () before
>          invocation of handle_common_deferred_options ().

The ChangeLog seems badly formatted, but it could have been eaten by 
your mailer. You might want to include it as part of the attachment to 
avoid whitespace damage.

As for the patch itself, it makes me a little nervous - it's hard to 
judge whether this could have unintended consequences where something 
relies on the existing ordering. I'd much rather postpone the generation 
of stack_limit_rtx until rtl initialization time. Maybe this needs to be 
per-function anyway, can Pmode change with attribute target?


Bernd
Jeff Law Jan. 21, 2016, 2:45 a.m. UTC | #2
On 01/20/2016 04:51 PM, Bernd Schmidt wrote:
>
>
> On 01/20/2016 10:49 PM, Kelvin Nilsen wrote:
>
>>      * toplev.c (do_compile): remove invocation of process_options ()
>>          from within do_compile ()
>>      (toplev::main): insert invocation of process_options () before
>>          invocation of handle_common_deferred_options ().
>
> The ChangeLog seems badly formatted, but it could have been eaten by
> your mailer. You might want to include it as part of the attachment to
> avoid whitespace damage.
>
> As for the patch itself, it makes me a little nervous - it's hard to
> judge whether this could have unintended consequences where something
> relies on the existing ordering. I'd much rather postpone the generation
> of stack_limit_rtx until rtl initialization time. Maybe this needs to be
> per-function anyway, can Pmode change with attribute target?
I couldn't ever get past my own nervousness about this patch either. 
If there isn't a need for stack_limit_rtx early, then delaying that 
initialization seems wiser.

jeff
diff mbox

Patch

Index: gcc/testsuite/gcc.target/powerpc/pr48344-1.c
===================================================================
--- gcc/testsuite/gcc.target/powerpc/pr48344-1.c	(revision 0)
+++ gcc/testsuite/gcc.target/powerpc/pr48344-1.c	(revision 232633)
@@ -0,0 +1,9 @@ 
+/* { dg-do compile } */
+/* { dg-options "-fstack-limit-register=r2" } */
+void foo ()
+{
+  int N = 2;
+  int slots[N];
+
+}
+
Index: gcc/toplev.c
===================================================================
--- gcc/toplev.c	(revision 232135)
+++ gcc/toplev.c	(working copy)
@@ -1938,8 +1938,6 @@  standard_type_bitsize (int bitsize)
 static void
 do_compile ()
 {
-  process_options ();
-
   /* Don't do any more if an error has already occurred.  */
   if (!seen_error ())
     {
@@ -2072,6 +2070,11 @@  toplev::main (int argc, char **argv)
 		  save_decoded_options, save_decoded_options_count,
 		  UNKNOWN_LOCATION, global_dc);
 
+  /* process_options() must execute before handle_common_deferred_options()
+     because handle_common_deferred_options() makes use of variables
+     initialized by process_options() (e.g. Pmode) */
+  process_options ();
+
   handle_common_deferred_options ();
 
   init_local_tick ();