Re: [PATCH] Fix up -march=native handling under KVM (PR target/61570)

2014-06-24 Thread H.J. Lu
On Mon, Jun 23, 2014 at 11:51 PM, Uros Bizjak  wrote:
> On Mon, Jun 23, 2014 at 6:29 PM, H.J. Lu  wrote:
>
> > --- gcc/config/i386/driver-i386.c.jj2014-05-14 14:45:54.0 
> > +0200
> > +++ gcc/config/i386/driver-i386.c   2014-06-20 18:59:57.805006358 
> > +0200
> > @@ -745,6 +745,11 @@ const char *host_detect_local_cpu (int a
> > /* Assume Core 2.  */
> > cpu = "core2";
> > }
> > + else if (has_longmode)
> > +   /* Perhaps some emulator?  Assume x86-64, otherwise gcc
> > +  -march=native would be unusable for 64-bit 
> > compilations,
> > +  as all the CPUs below are 32-bit only.  */
> > +   cpu = "x86-64";
> >   else if (has_sse3)
> > /* It is Core Duo.  */
> > cpu = "pentium-m";
> >
> > Jakub
>
> host_detect_local_cpu guesses the cpu based on the real processors.
> It doesn't work with emulators due to some conflicts.  This isn't the
> only only place which has the same issue.   I prefer something like
> this.

 I'm fine with your patch too.  Let's wait what Uros (or other i?86
 maintainers) pick up.
>>>
>>> This looks OK to me.
>>>
>>> Thanks,
>>> Uros.
>>
>> This is what I checked in.
>
> This version was NOT approved. Please revert it ASAP and proceed with
> approved version.
>
> Uros.

I reverted my change.  Sorry for my misunderstanding.

-- 
H.J.


Re: [PATCH] Fix up -march=native handling under KVM (PR target/61570)

2014-06-23 Thread Uros Bizjak
On Mon, Jun 23, 2014 at 6:29 PM, H.J. Lu  wrote:

 > --- gcc/config/i386/driver-i386.c.jj2014-05-14 14:45:54.0 
 > +0200
 > +++ gcc/config/i386/driver-i386.c   2014-06-20 18:59:57.805006358 
 > +0200
 > @@ -745,6 +745,11 @@ const char *host_detect_local_cpu (int a
 > /* Assume Core 2.  */
 > cpu = "core2";
 > }
 > + else if (has_longmode)
 > +   /* Perhaps some emulator?  Assume x86-64, otherwise gcc
 > +  -march=native would be unusable for 64-bit 
 > compilations,
 > +  as all the CPUs below are 32-bit only.  */
 > +   cpu = "x86-64";
 >   else if (has_sse3)
 > /* It is Core Duo.  */
 > cpu = "pentium-m";
 >
 > Jakub

 host_detect_local_cpu guesses the cpu based on the real processors.
 It doesn't work with emulators due to some conflicts.  This isn't the
 only only place which has the same issue.   I prefer something like
 this.
>>>
>>> I'm fine with your patch too.  Let's wait what Uros (or other i?86
>>> maintainers) pick up.
>>
>> This looks OK to me.
>>
>> Thanks,
>> Uros.
>
> This is what I checked in.

This version was NOT approved. Please revert it ASAP and proceed with
approved version.

Uros.


Re: [PATCH] Fix up -march=native handling under KVM (PR target/61570)

2014-06-23 Thread H.J. Lu
On Sun, Jun 22, 2014 at 11:23 AM, Uros Bizjak  wrote:
> On Sat, Jun 21, 2014 at 8:07 PM, Jakub Jelinek  wrote:
>
>>> > --- gcc/config/i386/driver-i386.c.jj2014-05-14 14:45:54.0 
>>> > +0200
>>> > +++ gcc/config/i386/driver-i386.c   2014-06-20 18:59:57.805006358 
>>> > +0200
>>> > @@ -745,6 +745,11 @@ const char *host_detect_local_cpu (int a
>>> > /* Assume Core 2.  */
>>> > cpu = "core2";
>>> > }
>>> > + else if (has_longmode)
>>> > +   /* Perhaps some emulator?  Assume x86-64, otherwise gcc
>>> > +  -march=native would be unusable for 64-bit 
>>> > compilations,
>>> > +  as all the CPUs below are 32-bit only.  */
>>> > +   cpu = "x86-64";
>>> >   else if (has_sse3)
>>> > /* It is Core Duo.  */
>>> > cpu = "pentium-m";
>>> >
>>> > Jakub
>>>
>>> host_detect_local_cpu guesses the cpu based on the real processors.
>>> It doesn't work with emulators due to some conflicts.  This isn't the
>>> only only place which has the same issue.   I prefer something like
>>> this.
>>
>> I'm fine with your patch too.  Let's wait what Uros (or other i?86
>> maintainers) pick up.
>
> This looks OK to me.
>
> Thanks,
> Uros.

This is what I checked in.

Thanks.

-- 
H.J.
---
Index: ChangeLog
===
--- ChangeLog (revision 211900)
+++ ChangeLog (working copy)
@@ -1,3 +1,9 @@
+2014-06-23  H.J. Lu  
+
+ PR target/61570
+ * config/i386/driver-i386.c (host_detect_local_cpu): Set arch
+ to x86-64 if a 32-bit processor supports SSE2 and 64-bit.
+
 2014-06-23  James Greenhalgh  

  * config/aarch64/aarch64.md (addsi3_aarch64): Set "simd" attr to
Index: config/i386/driver-i386.c
===
--- config/i386/driver-i386.c (revision 211900)
+++ config/i386/driver-i386.c (working copy)
@@ -415,6 +415,7 @@ const char *host_detect_local_cpu (int a
   bool arch;

   unsigned int l2sizekb = 0;
+  unsigned int arch_64bit = 1;

   if (argc < 1)
 return NULL;
@@ -656,11 +657,14 @@ const char *host_detect_local_cpu (int a
 {
 case PROCESSOR_I386:
   /* Default.  */
+  arch_64bit = 0;
   break;
 case PROCESSOR_I486:
+  arch_64bit = 0;
   cpu = "i486";
   break;
 case PROCESSOR_PENTIUM:
+  arch_64bit = 0;
   if (arch && has_mmx)
  cpu = "pentium-mmx";
   else
@@ -745,21 +749,25 @@ const char *host_detect_local_cpu (int a
 /* Assume Core 2.  */
 cpu = "core2";
  }
-  else if (has_sse3)
- /* It is Core Duo.  */
- cpu = "pentium-m";
-  else if (has_sse2)
- /* It is Pentium M.  */
- cpu = "pentium-m";
-  else if (has_sse)
- /* It is Pentium III.  */
- cpu = "pentium3";
-  else if (has_mmx)
- /* It is Pentium II.  */
- cpu = "pentium2";
   else
- /* Default to Pentium Pro.  */
- cpu = "pentiumpro";
+ {
+  arch_64bit = 0;
+  if (has_sse3)
+/* It is Core Duo.  */
+cpu = "pentium-m";
+  else if (has_sse2)
+/* It is Pentium M.  */
+cpu = "pentium-m";
+  else if (has_sse)
+/* It is Pentium III.  */
+cpu = "pentium3";
+  else if (has_mmx)
+/* It is Pentium II.  */
+cpu = "pentium2";
+  else
+/* Default to Pentium Pro.  */
+cpu = "pentiumpro";
+ }
 }
   else
 /* For -mtune, we default to -mtune=generic.  */
@@ -773,21 +781,30 @@ const char *host_detect_local_cpu (int a
   if (has_longmode)
 cpu = "nocona";
   else
-cpu = "prescott";
+{
+  cpu = "prescott";
+  arch_64bit = 0;
+}
  }
   else
- cpu = "pentium4";
+ {
+  cpu = "pentium4";
+  arch_64bit = 0;
+ }
   break;
 case PROCESSOR_GEODE:
+  arch_64bit = 0;
   cpu = "geode";
   break;
 case PROCESSOR_K6:
+  arch_64bit = 0;
   if (arch && has_3dnow)
  cpu = "k6-3";
   else
  cpu = "k6";
   break;
 case PROCESSOR_ATHLON:
+  arch_64bit = 0;
   if (arch && has_sse)
  cpu = "athlon-4";
   else
@@ -896,6 +913,10 @@ const char *host_detect_local_cpu (int a
   const char *xsavec = has_xsavec ? " -mxsavec" : " -mno-xsavec";
   const char *xsaves = has_xsaves ? " -mxsaves" : " -mno-xsaves";

+  /* Assume x86-64 if a 32-bit processor supports SSE2 and 64-bit.  */
+  if (arch_64bit == 0 && has_sse2 && has_longmode)
+ cpu = "x86-64";
+
   options = concat (options, mmx, mmx3dnow, sse, sse2, sse3, ssse3,
  sse4a, cx16, sahf, movbe, aes, sha, pclmul,
  popcnt, abm, lwp, fma, fma4, xop, bmi, bmi2,


Re: [PATCH] Fix up -march=native handling under KVM (PR target/61570)

2014-06-22 Thread Uros Bizjak
On Sat, Jun 21, 2014 at 8:07 PM, Jakub Jelinek  wrote:

>> > --- gcc/config/i386/driver-i386.c.jj2014-05-14 14:45:54.0 +0200
>> > +++ gcc/config/i386/driver-i386.c   2014-06-20 18:59:57.805006358 +0200
>> > @@ -745,6 +745,11 @@ const char *host_detect_local_cpu (int a
>> > /* Assume Core 2.  */
>> > cpu = "core2";
>> > }
>> > + else if (has_longmode)
>> > +   /* Perhaps some emulator?  Assume x86-64, otherwise gcc
>> > +  -march=native would be unusable for 64-bit compilations,
>> > +  as all the CPUs below are 32-bit only.  */
>> > +   cpu = "x86-64";
>> >   else if (has_sse3)
>> > /* It is Core Duo.  */
>> > cpu = "pentium-m";
>> >
>> > Jakub
>>
>> host_detect_local_cpu guesses the cpu based on the real processors.
>> It doesn't work with emulators due to some conflicts.  This isn't the
>> only only place which has the same issue.   I prefer something like
>> this.
>
> I'm fine with your patch too.  Let's wait what Uros (or other i?86
> maintainers) pick up.

This looks OK to me.

Thanks,
Uros.


Re: [PATCH] Fix up -march=native handling under KVM (PR target/61570)

2014-06-21 Thread Jakub Jelinek
On Fri, Jun 20, 2014 at 03:22:52PM -0700, H.J. Lu wrote:
> On Fri, Jun 20, 2014 at 2:42 PM, Jakub Jelinek  wrote:
> > --- gcc/config/i386/driver-i386.c.jj2014-05-14 14:45:54.0 +0200
> > +++ gcc/config/i386/driver-i386.c   2014-06-20 18:59:57.805006358 +0200
> > @@ -745,6 +745,11 @@ const char *host_detect_local_cpu (int a
> > /* Assume Core 2.  */
> > cpu = "core2";
> > }
> > + else if (has_longmode)
> > +   /* Perhaps some emulator?  Assume x86-64, otherwise gcc
> > +  -march=native would be unusable for 64-bit compilations,
> > +  as all the CPUs below are 32-bit only.  */
> > +   cpu = "x86-64";
> >   else if (has_sse3)
> > /* It is Core Duo.  */
> > cpu = "pentium-m";
> >
> > Jakub
> 
> host_detect_local_cpu guesses the cpu based on the real processors.
> It doesn't work with emulators due to some conflicts.  This isn't the
> only only place which has the same issue.   I prefer something like
> this.

I'm fine with your patch too.  Let's wait what Uros (or other i?86
maintainers) pick up.

Jakub


Re: [PATCH] Fix up -march=native handling under KVM (PR target/61570)

2014-06-20 Thread H.J. Lu
On Fri, Jun 20, 2014 at 2:42 PM, Jakub Jelinek  wrote:
> Hi!
>
> As mentioned in the PR, some? KVM versions disable some CPU flags,
> supposedly so that it can be migrated to any other x86-64 hw.
> Thus, it announces only sse2 and lm, but already not sse3, ssse3
> nor 3dnow, and (unfortunately) identifies itself as GenuineIntel
> family 6 model 13.  There is no 64-bit CPU that actually is the lowest
> common denominator of x86-64 CPUs (AMDs had 3dNOW etc., Intel first
> x86-64 CPUs had already SSSE3).
>
> This patch just makes sure we can use -march=native -m64 on such hosts,
> without that gcc complains that the selected CPU doesn't support 64-bit
> mode, because -march=native gives -march=pentium-m.
>
> Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux,
> ok for trunk/4.9?
>
> 2014-06-20  Jakub Jelinek  
>
> PR target/61570
> * config/i386/driver-i386.c (host_detect_local_cpu): For unknown
> model family 6 CPU with has_longmode never use a CPU without
> 64-bit support.
>
> --- gcc/config/i386/driver-i386.c.jj2014-05-14 14:45:54.0 +0200
> +++ gcc/config/i386/driver-i386.c   2014-06-20 18:59:57.805006358 +0200
> @@ -745,6 +745,11 @@ const char *host_detect_local_cpu (int a
> /* Assume Core 2.  */
> cpu = "core2";
> }
> + else if (has_longmode)
> +   /* Perhaps some emulator?  Assume x86-64, otherwise gcc
> +  -march=native would be unusable for 64-bit compilations,
> +  as all the CPUs below are 32-bit only.  */
> +   cpu = "x86-64";
>   else if (has_sse3)
> /* It is Core Duo.  */
> cpu = "pentium-m";
>
> Jakub

host_detect_local_cpu guesses the cpu based on the real processors.
It doesn't work with emulators due to some conflicts.  This isn't the
only only place which has the same issue.   I prefer something like
this.

-- 
H.J.
---
diff --git a/gcc/config/i386/driver-i386.c b/gcc/config/i386/driver-i386.c
index 3e8a995..2aada71 100644
--- a/gcc/config/i386/driver-i386.c
+++ b/gcc/config/i386/driver-i386.c
@@ -415,6 +415,7 @@ const char *host_detect_local_cpu (int argc, const
char **argv)
   bool arch;

   unsigned int l2sizekb = 0;
+  unsigned int arch_64bit = 1;

   if (argc < 1)
 return NULL;
@@ -656,11 +657,14 @@ const char *host_detect_local_cpu (int argc,
const char **argv)
 {
 case PROCESSOR_I386:
   /* Default.  */
+  arch_64bit = 0;
   break;
 case PROCESSOR_I486:
+  arch_64bit = 0;
   cpu = "i486";
   break;
 case PROCESSOR_PENTIUM:
+  arch_64bit = 0;
   if (arch && has_mmx)
  cpu = "pentium-mmx";
   else
@@ -745,21 +749,25 @@ const char *host_detect_local_cpu (int argc,
const char **argv)
 /* Assume Core 2.  */
 cpu = "core2";
  }
-  else if (has_sse3)
- /* It is Core Duo.  */
- cpu = "pentium-m";
-  else if (has_sse2)
- /* It is Pentium M.  */
- cpu = "pentium-m";
-  else if (has_sse)
- /* It is Pentium III.  */
- cpu = "pentium3";
-  else if (has_mmx)
- /* It is Pentium II.  */
- cpu = "pentium2";
   else
- /* Default to Pentium Pro.  */
- cpu = "pentiumpro";
+ {
+  arch_64bit = 0;
+  if (has_sse3)
+/* It is Core Duo.  */
+cpu = "pentium-m";
+  else if (has_sse2)
+/* It is Pentium M.  */
+cpu = "pentium-m";
+  else if (has_sse)
+/* It is Pentium III.  */
+cpu = "pentium3";
+  else if (has_mmx)
+/* It is Pentium II.  */
+cpu = "pentium2";
+  else
+/* Default to Pentium Pro.  */
+cpu = "pentiumpro";
+ }
 }
   else
 /* For -mtune, we default to -mtune=generic.  */
@@ -773,21 +781,30 @@ const char *host_detect_local_cpu (int argc,
const char **argv)
   if (has_longmode)
 cpu = "nocona";
   else
-cpu = "prescott";
+{
+  cpu = "prescott";
+  arch_64bit = 0;
+}
  }
   else
- cpu = "pentium4";
+ {
+  cpu = "pentium4";
+  arch_64bit = 0;
+ }
   break;
 case PROCESSOR_GEODE:
+  arch_64bit = 0;
   cpu = "geode";
   break;
 case PROCESSOR_K6:
+  arch_64bit = 0;
   if (arch && has_3dnow)
  cpu = "k6-3";
   else
  cpu = "k6";
   break;
 case PROCESSOR_ATHLON:
+  arch_64bit = 0;
   if (arch && has_sse)
  cpu = "athlon-4";
   else
@@ -896,6 +913,9 @@ const char *host_detect_local_cpu (int argc, const
char **argv)
   const char *xsavec = has_xsavec ? " -mxsavec" : " -mno-xsavec";
   const char *xsaves = has_xsaves ? " -mxsaves" : " -mno-xsaves";

+  if (arch_64bit == 0 && has_sse2 && has_longmode)
+ cpu = "x86-64";
+
   options = concat (options, mmx, mmx3dnow, sse, sse2, sse3, ssse3,
  sse4a, cx16, sahf, movbe, aes, sha, pclmul,
  popcnt, abm, lwp, fma, fma4, xop, bmi, bmi2,