Add "native" as a valid option value for -march= on i386 (PR driver/83193).

Message ID f6ef8fc4-43b4-8e1a-34ef-3379ea4d69c7@suse.cz
State New
Headers show
Series
  • Add "native" as a valid option value for -march= on i386 (PR driver/83193).
Related show

Commit Message

Martin Liška Feb. 20, 2018, 1:24 p.m.
Hi.

Following patch adds "native" as a possible option for -march value on i386 target.
I have similar patches for other targets. Would it be possible to install the
patch in current stage?

Before:
$ ./xgcc -B. -march=abcdef /tmp/empty.c
cc1: error: bad value (‘abcdef’) for ‘-march=’ switch
cc1: note: valid arguments to ‘-march=’ switch are: nocona core2 nehalem corei7 westmere sandybridge corei7-avx ivybridge core-avx-i haswell core-avx2 broadwell skylake skylake-avx512 cannonlake icelake bonnell atom silvermont slm knl knm x86-64 eden-x2 nano nano-1000 nano-2000 nano-3000 nano-x2 eden-x4 nano-x4 k8 k8-sse3 opteron opteron-sse3 athlon64 athlon64-sse3 athlon-fx amdfam10 barcelona bdver1 bdver2 bdver3 bdver4 znver1 btver1 btver2

After:
$ ./xgcc -B. -march=abcdef /tmp/empty.c
cc1: error: bad value (‘abcdef’) for ‘-march=’ switch
cc1: note: valid arguments to ‘-march=’ switch are: nocona core2 nehalem corei7 westmere sandybridge corei7-avx ivybridge core-avx-i haswell core-avx2 broadwell skylake skylake-avx512 cannonlake icelake bonnell atom silvermont slm knl knm x86-64 eden-x2 nano nano-1000 nano-2000 nano-3000 nano-x2 eden-x4 nano-x4 k8 k8-sse3 opteron opteron-sse3 athlon64 athlon64-sse3 athlon-fx amdfam10 barcelona bdver1 bdver2 bdver3 bdver4 znver1 btver1 btver2 native

$ ./xgcc -B. -march=native2 /tmp/empty.c
cc1: error: bad value (‘native2’) for ‘-march=’ switch
cc1: note: valid arguments to ‘-march=’ switch are: nocona core2 nehalem corei7 westmere sandybridge corei7-avx ivybridge core-avx-i haswell core-avx2 broadwell skylake skylake-avx512 cannonlake icelake bonnell atom silvermont slm knl knm x86-64 eden-x2 nano nano-1000 nano-2000 nano-3000 nano-x2 eden-x4 nano-x4 k8 k8-sse3 opteron opteron-sse3 athlon64 athlon64-sse3 athlon-fx amdfam10 barcelona bdver1 bdver2 bdver3 bdver4 znver1 btver1 btver2 native; did you mean ‘native’?

Ready for trunk after tests?
Thanks
Martin

gcc/ChangeLog:

2018-02-20  Martin Liska  <mliska@suse.cz>

	PR driver/83193
	* config/i386/i386.c (ix86_option_override_internal):
	Add "native" as a possible value.
---
 gcc/config/i386/i386.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Richard Sandiford Feb. 20, 2018, 3:58 p.m. | #1
Martin Liška <mliska@suse.cz> writes:
> Hi.

>

> Following patch adds "native" as a possible option for -march value on

> i386 target.  I have similar patches for other targets. Would it be

> possible to install the patch in current stage?


[...]

> diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c

> index d54e7301e84..361d4df2663 100644

> --- a/gcc/config/i386/i386.c

> +++ b/gcc/config/i386/i386.c

> @@ -4193,6 +4193,9 @@ ix86_option_override_internal (bool main_args_p,

>  		|| ((processor_alias_table[i].flags & PTA_64BIT) != 0)))

>  	  candidates.safe_push (processor_alias_table[i].name);

>  

> +      /* Add also "native" as possible value.  */

> +      candidates.safe_push ("native");

> +

>        char *s;

>        const char *hint

>  	= candidates_list_and_hint (opts->x_ix86_arch_string, s, candidates);


We should probably only do this if the driver supports -march=native.
I think for x86 that means HAVE_LOCAL_CPU_DETECT.

Thanks,
Richard
Jakub Jelinek Feb. 20, 2018, 4:06 p.m. | #2
On Tue, Feb 20, 2018 at 03:58:07PM +0000, Richard Sandiford wrote:
> Martin Liška <mliska@suse.cz> writes:

> > Hi.

> >

> > Following patch adds "native" as a possible option for -march value on

> > i386 target.  I have similar patches for other targets. Would it be

> > possible to install the patch in current stage?

> 

> [...]

> 

> > diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c

> > index d54e7301e84..361d4df2663 100644

> > --- a/gcc/config/i386/i386.c

> > +++ b/gcc/config/i386/i386.c

> > @@ -4193,6 +4193,9 @@ ix86_option_override_internal (bool main_args_p,

> >  		|| ((processor_alias_table[i].flags & PTA_64BIT) != 0)))

> >  	  candidates.safe_push (processor_alias_table[i].name);

> >  

> > +      /* Add also "native" as possible value.  */

> > +      candidates.safe_push ("native");

> > +

> >        char *s;

> >        const char *hint

> >  	= candidates_list_and_hint (opts->x_ix86_arch_string, s, candidates);

> 

> We should probably only do this if the driver supports -march=native.

> I think for x86 that means HAVE_LOCAL_CPU_DETECT.


Isn't the option available always?  It just doesn't do anything if
/* If we are compiling with GCC where %EBX register is fixed, then the
   driver will just ignore -march and -mtune "native" target and will leave
   to the newly built compiler to generate code for its default target.  */

	Jakub
Richard Sandiford Feb. 20, 2018, 4:19 p.m. | #3
Jakub Jelinek <jakub@redhat.com> writes:
> On Tue, Feb 20, 2018 at 03:58:07PM +0000, Richard Sandiford wrote:

>> Martin Liška <mliska@suse.cz> writes:

>> > Hi.

>> >

>> > Following patch adds "native" as a possible option for -march value on

>> > i386 target.  I have similar patches for other targets. Would it be

>> > possible to install the patch in current stage?

>> 

>> [...]

>> 

>> > diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c

>> > index d54e7301e84..361d4df2663 100644

>> > --- a/gcc/config/i386/i386.c

>> > +++ b/gcc/config/i386/i386.c

>> > @@ -4193,6 +4193,9 @@ ix86_option_override_internal (bool main_args_p,

>> >  		|| ((processor_alias_table[i].flags & PTA_64BIT) != 0)))

>> >  	  candidates.safe_push (processor_alias_table[i].name);

>> >  

>> > +      /* Add also "native" as possible value.  */

>> > +      candidates.safe_push ("native");

>> > +

>> >        char *s;

>> >        const char *hint

>> >  	= candidates_list_and_hint (opts->x_ix86_arch_string, s, candidates);

>> 

>> We should probably only do this if the driver supports -march=native.

>> I think for x86 that means HAVE_LOCAL_CPU_DETECT.

>

> Isn't the option available always?  It just doesn't do anything if

> /* If we are compiling with GCC where %EBX register is fixed, then the

>    driver will just ignore -march and -mtune "native" target and will leave

>    to the newly built compiler to generate code for its default target.  */


It's only available for x86 hosts:

/* -march=native handling only makes sense with compiler running on
   an x86 or x86_64 chip.  If changing this condition, also change
   the condition in driver-i386.c.  */
#if defined(__i386__) || defined(__x86_64__)
/* In driver-i386.c.  */
extern const char *host_detect_local_cpu (int argc, const char **argv);
#define EXTRA_SPEC_FUNCTIONS \
  { "local_cpu_detect", host_detect_local_cpu },
#define HAVE_LOCAL_CPU_DETECT
#endif

Non-native hosts are obviously a niche case for x86, but it still
seems better to be consistent.

Richard
Martin Liška Feb. 20, 2018, 4:26 p.m. | #4
On 02/20/2018 05:19 PM, Richard Sandiford wrote:
> Jakub Jelinek <jakub@redhat.com> writes:

>> On Tue, Feb 20, 2018 at 03:58:07PM +0000, Richard Sandiford wrote:

>>> Martin Liška <mliska@suse.cz> writes:

>>>> Hi.

>>>>

>>>> Following patch adds "native" as a possible option for -march value on

>>>> i386 target.  I have similar patches for other targets. Would it be

>>>> possible to install the patch in current stage?

>>>

>>> [...]

>>>

>>>> diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c

>>>> index d54e7301e84..361d4df2663 100644

>>>> --- a/gcc/config/i386/i386.c

>>>> +++ b/gcc/config/i386/i386.c

>>>> @@ -4193,6 +4193,9 @@ ix86_option_override_internal (bool main_args_p,

>>>>  		|| ((processor_alias_table[i].flags & PTA_64BIT) != 0)))

>>>>  	  candidates.safe_push (processor_alias_table[i].name);

>>>>  

>>>> +      /* Add also "native" as possible value.  */

>>>> +      candidates.safe_push ("native");

>>>> +

>>>>        char *s;

>>>>        const char *hint

>>>>  	= candidates_list_and_hint (opts->x_ix86_arch_string, s, candidates);

>>>

>>> We should probably only do this if the driver supports -march=native.

>>> I think for x86 that means HAVE_LOCAL_CPU_DETECT.

>>

>> Isn't the option available always?  It just doesn't do anything if

>> /* If we are compiling with GCC where %EBX register is fixed, then the

>>    driver will just ignore -march and -mtune "native" target and will leave

>>    to the newly built compiler to generate code for its default target.  */

> 

> It's only available for x86 hosts:

> 

> /* -march=native handling only makes sense with compiler running on

>    an x86 or x86_64 chip.  If changing this condition, also change

>    the condition in driver-i386.c.  */

> #if defined(__i386__) || defined(__x86_64__)

> /* In driver-i386.c.  */

> extern const char *host_detect_local_cpu (int argc, const char **argv);

> #define EXTRA_SPEC_FUNCTIONS \

>   { "local_cpu_detect", host_detect_local_cpu },

> #define HAVE_LOCAL_CPU_DETECT

> #endif

> 

> Non-native hosts are obviously a niche case for x86, but it still

> seems better to be consistent.

> 

> Richard

> 


So would it enough to wrap 'candidates.safe_push ("native");' by
#ifdef HAVE_LOCAL_CPU_DETECT
?

Thanks,
Martin
Martin Liška Feb. 21, 2018, 7:33 a.m. | #5
On 02/20/2018 05:26 PM, Martin Liška wrote:
> On 02/20/2018 05:19 PM, Richard Sandiford wrote:

>> Jakub Jelinek <jakub@redhat.com> writes:

>>> On Tue, Feb 20, 2018 at 03:58:07PM +0000, Richard Sandiford wrote:

>>>> Martin Liška <mliska@suse.cz> writes:

>>>>> Hi.

>>>>>

>>>>> Following patch adds "native" as a possible option for -march value on

>>>>> i386 target.  I have similar patches for other targets. Would it be

>>>>> possible to install the patch in current stage?

>>>>

>>>> [...]

>>>>

>>>>> diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c

>>>>> index d54e7301e84..361d4df2663 100644

>>>>> --- a/gcc/config/i386/i386.c

>>>>> +++ b/gcc/config/i386/i386.c

>>>>> @@ -4193,6 +4193,9 @@ ix86_option_override_internal (bool main_args_p,

>>>>>  		|| ((processor_alias_table[i].flags & PTA_64BIT) != 0)))

>>>>>  	  candidates.safe_push (processor_alias_table[i].name);

>>>>>  

>>>>> +      /* Add also "native" as possible value.  */

>>>>> +      candidates.safe_push ("native");

>>>>> +

>>>>>        char *s;

>>>>>        const char *hint

>>>>>  	= candidates_list_and_hint (opts->x_ix86_arch_string, s, candidates);

>>>>

>>>> We should probably only do this if the driver supports -march=native.

>>>> I think for x86 that means HAVE_LOCAL_CPU_DETECT.

>>>

>>> Isn't the option available always?  It just doesn't do anything if

>>> /* If we are compiling with GCC where %EBX register is fixed, then the

>>>    driver will just ignore -march and -mtune "native" target and will leave

>>>    to the newly built compiler to generate code for its default target.  */

>>

>> It's only available for x86 hosts:

>>

>> /* -march=native handling only makes sense with compiler running on

>>    an x86 or x86_64 chip.  If changing this condition, also change

>>    the condition in driver-i386.c.  */

>> #if defined(__i386__) || defined(__x86_64__)

>> /* In driver-i386.c.  */

>> extern const char *host_detect_local_cpu (int argc, const char **argv);

>> #define EXTRA_SPEC_FUNCTIONS \

>>   { "local_cpu_detect", host_detect_local_cpu },

>> #define HAVE_LOCAL_CPU_DETECT

>> #endif

>>

>> Non-native hosts are obviously a niche case for x86, but it still

>> seems better to be consistent.

>>

>> Richard

>>

> 

> So would it enough to wrap 'candidates.safe_push ("native");' by

> #ifdef HAVE_LOCAL_CPU_DETECT

> ?

> 

> Thanks,

> Martin

> 


There's updated version of the patch I've just tested.

Martin
From 8f1783a9017ec06c578fd644e46168ec5763d5ca Mon Sep 17 00:00:00 2001
From: marxin <mliska@suse.cz>

Date: Tue, 20 Feb 2018 14:21:05 +0100
Subject: [PATCH 3/3] Add "native" as a valid option value for -march= on i386
 (PR driver/83193).

gcc/ChangeLog:

2018-02-20  Martin Liska  <mliska@suse.cz>

	PR driver/83193
	* config/i386/i386.c (ix86_option_override_internal):
	Add "native" as a possible value.
---
 gcc/config/i386/i386.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
index d54e7301e84..9f2c5218ae5 100644
--- a/gcc/config/i386/i386.c
+++ b/gcc/config/i386/i386.c
@@ -4193,6 +4193,11 @@ ix86_option_override_internal (bool main_args_p,
 		|| ((processor_alias_table[i].flags & PTA_64BIT) != 0)))
 	  candidates.safe_push (processor_alias_table[i].name);
 
+#ifdef HAVE_LOCAL_CPU_DETECT
+      /* Add also "native" as possible value.  */
+      candidates.safe_push ("native");
+#endif
+
       char *s;
       const char *hint
 	= candidates_list_and_hint (opts->x_ix86_arch_string, s, candidates);
-- 
2.16.1
Jakub Jelinek Feb. 21, 2018, 2:08 p.m. | #6
On Wed, Feb 21, 2018 at 08:33:21AM +0100, Martin Liška wrote:
> >From 8f1783a9017ec06c578fd644e46168ec5763d5ca Mon Sep 17 00:00:00 2001

> From: marxin <mliska@suse.cz>

> Date: Tue, 20 Feb 2018 14:21:05 +0100

> Subject: [PATCH 3/3] Add "native" as a valid option value for -march= on i386

>  (PR driver/83193).

> 

> gcc/ChangeLog:

> 

> 2018-02-20  Martin Liska  <mliska@suse.cz>

> 

> 	PR driver/83193

> 	* config/i386/i386.c (ix86_option_override_internal):

> 	Add "native" as a possible value.

> ---

>  gcc/config/i386/i386.c | 5 +++++

>  1 file changed, 5 insertions(+)

> 

> diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c

> index d54e7301e84..9f2c5218ae5 100644

> --- a/gcc/config/i386/i386.c

> +++ b/gcc/config/i386/i386.c

> @@ -4193,6 +4193,11 @@ ix86_option_override_internal (bool main_args_p,

>  		|| ((processor_alias_table[i].flags & PTA_64BIT) != 0)))

>  	  candidates.safe_push (processor_alias_table[i].name);

>  

> +#ifdef HAVE_LOCAL_CPU_DETECT

> +      /* Add also "native" as possible value.  */

> +      candidates.safe_push ("native");

> +#endif


This just adds "native" as possible value for -march, but shouldn't it be
also for -mtune, i.e. around line 4268?

> +

>        char *s;

>        const char *hint

>  	= candidates_list_and_hint (opts->x_ix86_arch_string, s, candidates);

> -- 

> 2.16.1

> 



	Jakub
Martin Liška Feb. 21, 2018, 2:19 p.m. | #7
On 02/21/2018 03:08 PM, Jakub Jelinek wrote:
> This just adds "native" as possible value for -march, but shouldn't it be

> also for -mtune, i.e. around line 4268?


Thanks for note. There's updated version.

Is it ok now?
Thanks,
Martin
From 980016be748b8f6a917f497d256c62a054bdece8 Mon Sep 17 00:00:00 2001
From: marxin <mliska@suse.cz>

Date: Tue, 20 Feb 2018 14:21:05 +0100
Subject: [PATCH] Add "native" as a valid option value for -march= on i386 (PR
 driver/83193).

gcc/ChangeLog:

2018-02-20  Martin Liska  <mliska@suse.cz>

	PR driver/83193
	* config/i386/i386.c (ix86_option_override_internal):
	Add "native" as a possible value for -march and -mtune.
---
 gcc/config/i386/i386.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
index d54e7301e84..18d9084fd30 100644
--- a/gcc/config/i386/i386.c
+++ b/gcc/config/i386/i386.c
@@ -4193,6 +4193,11 @@ ix86_option_override_internal (bool main_args_p,
 		|| ((processor_alias_table[i].flags & PTA_64BIT) != 0)))
 	  candidates.safe_push (processor_alias_table[i].name);
 
+#ifdef HAVE_LOCAL_CPU_DETECT
+      /* Add also "native" as possible value.  */
+      candidates.safe_push ("native");
+#endif
+
       char *s;
       const char *hint
 	= candidates_list_and_hint (opts->x_ix86_arch_string, s, candidates);
@@ -4265,6 +4270,11 @@ ix86_option_override_internal (bool main_args_p,
 	    || ((processor_alias_table[i].flags & PTA_64BIT) != 0))
 	  candidates.safe_push (processor_alias_table[i].name);
 
+#ifdef HAVE_LOCAL_CPU_DETECT
+      /* Add also "native" as possible value.  */
+      candidates.safe_push ("native");
+#endif
+
       char *s;
       const char *hint
 	= candidates_list_and_hint (opts->x_ix86_tune_string, s, candidates);
-- 
2.16.1
Jakub Jelinek Feb. 21, 2018, 2:23 p.m. | #8
On Wed, Feb 21, 2018 at 03:19:22PM +0100, Martin Liška wrote:
> On 02/21/2018 03:08 PM, Jakub Jelinek wrote:

> > This just adds "native" as possible value for -march, but shouldn't it be

> > also for -mtune, i.e. around line 4268?

> 

> Thanks for note. There's updated version.

> 

> Is it ok now?

> Thanks,

> Martin


> >From 980016be748b8f6a917f497d256c62a054bdece8 Mon Sep 17 00:00:00 2001

> From: marxin <mliska@suse.cz>

> Date: Tue, 20 Feb 2018 14:21:05 +0100

> Subject: [PATCH] Add "native" as a valid option value for -march= on i386 (PR

>  driver/83193).

> 

> gcc/ChangeLog:

> 

> 2018-02-20  Martin Liska  <mliska@suse.cz>

> 

> 	PR driver/83193

> 	* config/i386/i386.c (ix86_option_override_internal):

> 	Add "native" as a possible value for -march and -mtune.


Ok, thanks.

> ---

>  gcc/config/i386/i386.c | 10 ++++++++++

>  1 file changed, 10 insertions(+)

> 

> diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c

> index d54e7301e84..18d9084fd30 100644

> --- a/gcc/config/i386/i386.c

> +++ b/gcc/config/i386/i386.c

> @@ -4193,6 +4193,11 @@ ix86_option_override_internal (bool main_args_p,

>  		|| ((processor_alias_table[i].flags & PTA_64BIT) != 0)))

>  	  candidates.safe_push (processor_alias_table[i].name);

>  

> +#ifdef HAVE_LOCAL_CPU_DETECT

> +      /* Add also "native" as possible value.  */

> +      candidates.safe_push ("native");

> +#endif

> +

>        char *s;

>        const char *hint

>  	= candidates_list_and_hint (opts->x_ix86_arch_string, s, candidates);

> @@ -4265,6 +4270,11 @@ ix86_option_override_internal (bool main_args_p,

>  	    || ((processor_alias_table[i].flags & PTA_64BIT) != 0))

>  	  candidates.safe_push (processor_alias_table[i].name);

>  

> +#ifdef HAVE_LOCAL_CPU_DETECT

> +      /* Add also "native" as possible value.  */

> +      candidates.safe_push ("native");

> +#endif

> +

>        char *s;

>        const char *hint

>  	= candidates_list_and_hint (opts->x_ix86_tune_string, s, candidates);

> -- 

> 2.16.1

> 



	Jakub

Patch

diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
index d54e7301e84..361d4df2663 100644
--- a/gcc/config/i386/i386.c
+++ b/gcc/config/i386/i386.c
@@ -4193,6 +4193,9 @@  ix86_option_override_internal (bool main_args_p,
 		|| ((processor_alias_table[i].flags & PTA_64BIT) != 0)))
 	  candidates.safe_push (processor_alias_table[i].name);
 
+      /* Add also "native" as possible value.  */
+      candidates.safe_push ("native");
+
       char *s;
       const char *hint
 	= candidates_list_and_hint (opts->x_ix86_arch_string, s, candidates);