Re: [PATCH, rs6000] Follow-on fix for PR target/80210: ICE in extract_insn

2017-12-14 Thread Peter Bergner
On 10/2/17 12:10 PM, Segher Boessenkool wrote:
> On Mon, Oct 02, 2017 at 12:00:55PM -0500, Peter Bergner wrote:
>> On 9/29/17 5:31 PM, Segher Boessenkool wrote:
>>> Looks great to me, please commit.  But hold off until Monday please, it
>>> will interfere with testing otherwise.
>>
>> Ok, committed now (Monday).  I'd also like to back port this to the
>> GCC 7 and 6 release branches, where the earlier fix was also back
>> ported to.  Ok there after a week or so of burn in on trunk?
> 
> Certainly.  Thanks!

It seems I forgot to back port this fix, so it's had a lot of burn in
time! :-)  I re-regtested the patch on powerpc64le-linux, powerpc64-linux
and powerpc-linux on both release branches and there were no regressions,
so I went ahead and committed it.  Thanks.

Peter



Re: [PATCH, rs6000] Follow-on fix for PR target/80210: ICE in extract_insn

2017-10-02 Thread Segher Boessenkool
On Mon, Oct 02, 2017 at 12:00:55PM -0500, Peter Bergner wrote:
> On 9/29/17 5:31 PM, Segher Boessenkool wrote:
> >> +/* PowerPC 64-bit LE requires at least ISA 2.07.  */
> >> +const char *default_cpu = ((!TARGET_POWERPC64)
> >> +   ? "powerpc"
> >> +   : ((BYTES_BIG_ENDIAN)
> >> +  ? "powerpc64"
> >> +  : "powerpc64le"));
> > 
> > Please remove the parens around !TARGET_POWERPC64 and BYTES_BIG_ENDIAN
> > while you're at it (one of the copies you removed had that already :-) )
> 
> Done.
> 
> 
> > Looks great to me, please commit.  But hold off until Monday please, it
> > will interfere with testing otherwise.
> 
> Ok, committed now (Monday).  I'd also like to back port this to the
> GCC 7 and 6 release branches, where the earlier fix was also back
> ported to.  Ok there after a week or so of burn in on trunk?

Certainly.  Thanks!


Segher


Re: [PATCH, rs6000] Follow-on fix for PR target/80210: ICE in extract_insn

2017-10-02 Thread Peter Bergner
On 9/29/17 5:31 PM, Segher Boessenkool wrote:
>> +  /* PowerPC 64-bit LE requires at least ISA 2.07.  */
>> +  const char *default_cpu = ((!TARGET_POWERPC64)
>> + ? "powerpc"
>> + : ((BYTES_BIG_ENDIAN)
>> +? "powerpc64"
>> +: "powerpc64le"));
> 
> Please remove the parens around !TARGET_POWERPC64 and BYTES_BIG_ENDIAN
> while you're at it (one of the copies you removed had that already :-) )

Done.


> Looks great to me, please commit.  But hold off until Monday please, it
> will interfere with testing otherwise.

Ok, committed now (Monday).  I'd also like to back port this to the
GCC 7 and 6 release branches, where the earlier fix was also back
ported to.  Ok there after a week or so of burn in on trunk?

Thanks.

Peter




Re: [PATCH, rs6000] Follow-on fix for PR target/80210: ICE in extract_insn

2017-09-29 Thread Segher Boessenkool
Hi Peter,

On Thu, Sep 28, 2017 at 09:26:00PM -0500, Peter Bergner wrote:
> This patch fixes two new issues exposed (but not caused) by the original 
> test case added for PR80210 as well as a modified version of that test case.

[ .. snip ... ]

This all seems correct (but it is so complex that it is hard to be sure;
well it is _less_ complex now!)

> +   /* PowerPC 64-bit LE requires at least ISA 2.07.  */
> +   const char *default_cpu = ((!TARGET_POWERPC64)
> +  ? "powerpc"
> +  : ((BYTES_BIG_ENDIAN)
> + ? "powerpc64"
> + : "powerpc64le"));

Please remove the parens around !TARGET_POWERPC64 and BYTES_BIG_ENDIAN
while you're at it (one of the copies you removed had that already :-) )

Looks great to me, please commit.  But hold off until Monday please, it
will interfere with testing otherwise.

Thanks!


Segher


[PATCH, rs6000] Follow-on fix for PR target/80210: ICE in extract_insn

2017-09-28 Thread Peter Bergner
This patch fixes two new issues exposed (but not caused) by the original 
test case added for PR80210 as well as a modified version of that test case.

The first problem is that the test case pr80210.c ICEs on 32-bit compiles
that do not pass either an explicit or implicit -mcpu=...  option.
I did not see this during my testing, because my powerpc-linux builds were
done on a 64-bit system and I built my compiler using the --with-cpu=default32
configure option which hid the ICE.

This problem is due to a mismatch between TARGET_DEFAULT, which contains
MASK_PPC_GPOPT and the ISA flags for the default "powerpc64"/"powerpc" cpu,
which does not contain MASK_PPC_GPOPT and how rs6000_option_override_internal()
decides which one to use.  The failure scenario is, early on we call
init_all_optabs() which setups up a table which describes which patterns
that generate some HW insns are "valid".  Before we call init_all_optabs(),
rs6000_option_override_internal() gets called with the global_init_p arg
set to "true" and we basically set rs6000_isa_flags to TARGET_DEFAULT.
We also execute the following code because we didn't pass in a -mcpu=
option, so rs6000_cpu_index gets set to "powerpc64"/"powerpc"'s index
into the cpu table.

  if (!have_cpu)
{
  /* PowerPC 64-bit LE requires at least ISA 2.07.  */
  const char *default_cpu = (!TARGET_POWERPC64
 ? "powerpc"
 : (BYTES_BIG_ENDIAN
? "powerpc64"
: "powerpc64le"));

  rs6000_cpu_index = cpu_index = rs6000_cpu_name_lookup (default_cpu);
}

With this, init_all_optabs() thinks we can generate (as it should) a HW sqrt,
so it enables generating its pattern.

Later, after we've scanned the entire file, we go to expand our function
into RTL and we reset our compiler options and we end up calling
rs6000_option_override_internal() again, but this time with the global_init_p
arg now set to false and we encounter this code:

  struct cl_target_option *main_target_opt
= ((global_init_p || target_option_default_node == NULL)
   ? NULL : TREE_TARGET_OPTION (target_option_default_node));

This ends up setting main_target_opt to a non-NULL value, then:

  ...
  else if (main_target_opt != NULL && main_target_opt->x_rs6000_cpu_index >= 0)
{
  rs6000_cpu_index = cpu_index = main_target_opt->x_rs6000_cpu_index;
  have_cpu = true;
}

This causes us to use the saved rs6000_cpu_index value and act as if the
user passed it in, so we restore the rs6000_isa_flags from the saved
default cpu rather than the TARGET_DEFAULT flags.  Since the default
cpus don't include the MASK_PPC_GPOPT flag, we eventually ICE.

This patch fixes the pr80210.c ICE by correctly setting the rs6000_cpu_index
value which in turn makes us use the correct rs6000_isa_flags value.
I also fixed the setting of the rs6000_tune_index value that was also
being set incorrectly sometimes, but of course, it doesn't lead to an
ICE, just wrong scheduling.

The second problem was exposed by compiling the pr80210.c test case, but
with the #pragma moved to the beginning of the file.  In this case, we
should disable the generating of the HW sqrt pattern in the optabs.
The ICE showed that we were still generating the HQ sqrt pattern when
we shouldn't have.  This problem is basically the dual of the other
problem, in that we are not correctly saving and restoring the optab
values.  The problem here is that rs6000_pragma_target_parse () did not
call rs6000_activate_target_options () which ends up resetting the
optabs values associated with the rs6000_isa_flags value.

This passed bootstrap and regtesting on powerpc64le-linux as well as
on powerpc64-linux and running the test suite in both 32-bit and 64-bit
modes.  Ok for trunk?

Peter


gcc/
PR target/80210
* config/rs6000/rs6000.c (rs6000_option_override_internal): Rewrite
function to not use the have_cpu variable.  Do not set cpu_index,
rs6000_cpu_index or rs6000_tune_index if we end up using TARGET_DEFAULT
or the default cpu.
(rs6000_valid_attribute_p): Remove duplicate initializations of
old_optimize and func_optimize.
(rs6000_pragma_target_parse): Call rs6000_activate_target_options ().
(rs6000_activate_target_options): Make global.
* config/rs6000/rs6000-protos.h (rs6000_activate_target_options): Add
prototype.

gcc/testsuite/
PR target/80210
* gcc.target/powerpc/pr80210-2.c: New test.

Index: gcc/config/rs6000/rs6000.c
===
--- gcc/config/rs6000/rs6000.c  (revision 253232)
+++ gcc/config/rs6000/rs6000.c  (working copy)
@@ -3992,14 +3992,10 @@ static bool
 rs6000_option_override_internal (bool global_init_p)
 {
   bool ret = true;
-  bool have_cpu = false;
-
-  /* The default cpu requested at configure