Bug 44046 - Intel Core i5 M520 CPU detected as atom with -march=native
Summary: Intel Core i5 M520 CPU detected as atom with -march=native
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 4.5.0
: P3 normal
Target Milestone: 4.5.1
Assignee: Not yet assigned to anyone
URL: http://gcc.gnu.org/ml/gcc-patches/201...
Keywords:
Depends on:
Blocks:
 
Reported: 2010-05-09 04:47 UTC by Ryan Hill
Modified: 2010-11-01 13:22 UTC (History)
4 users (show)

See Also:
Host: x86_64-pc-linux-gnu
Target: x86_64-pc-linux-gnu
Build: x86_64-pc-linux-gnu
Known to work: 4.5.1 4.6.0
Known to fail:
Last reconfirmed: 2010-05-09 14:43:11


Attachments
/proc/cpuinfo (551 bytes, text/plain)
2010-05-09 04:48 UTC, Ryan Hill
Details
gcc45-PR44046-core2.patch (716 bytes, patch)
2010-05-09 18:39 UTC, Ryan Hill
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ryan Hill 2010-05-09 04:47:32 UTC
We have a user that is getting illegal instruction errors while building xulrunner.

/var/tmp/portage/net-libs/xulrunner-1.9.2.3-r1/work/mozilla-1.9.2/dist/bin/xpidl -m typelib -w -I. -I../../dist/idl -e _xpidlgen/nsIConsoleListener.xpt -d .deps/nsIConsoleListener.pp nsIConsoleListener.idl
make[4]: *** [_xpidlgen/nsIConsoleListener.xpt] Illegal instruction

It turns out that using -march=native with his Core i5 processor results in -march=atom being used, specifically:

gcc version 4.5.0 (Gentoo 4.5.0 p1.0) 
COLLECT_GCC_OPTIONS= '-v' '-o' 'test'
 /usr/libexec/gcc/x86_64-pc-linux-gnu/4.5.0/cc1 -quiet -v test.c
-D_FORTIFY_SOURCE=2 -march=atom -mcx16 -msahf -maes -mpclmul -mpopcnt -msse4.2
--param l1-cache-size=32 --param l1-cache-line-size=64 --param
l2-cache-size=3072 -mtune=core2 -quiet -dumpbase test.c -auxbase test -version
-o /tmp/ccmAagyo.s

I believe the issue is that this processor doesn't support mmovbe, which -march=atom enables (the error doesn't occur w/ -march=atom -mno-movbe).  Am I right in guessing that it should instead be using -march=core2 + a bunch of -m flags?

I will attach his /proc/cpuinfo.  Let me know what other info you need.

http://bugs.gentoo.org/317513
Comment 1 Ryan Hill 2010-05-09 04:48:02 UTC
Created attachment 20610 [details]
/proc/cpuinfo
Comment 2 Uroš Bizjak 2010-05-09 07:25:45 UTC
From config/driver-i386.c

    [...]
    case PROCESSOR_PENTIUMPRO:
      if (model == 28)
	cpu = "atom";
      else if (model >= 28 && l2sizekb < 2048)
	/* Assume it's a small core if there's less than 2MB cache */
	cpu = "atom";
      else if (has_longmode)
	cpu = "core2";

And from cpuid:

cpu family	: 6
model		: 37
cache size	: 3072 KB

driver detects --param l2-cache-size=3072 and -march=atom ... WTF ?

Can you please step through the driver with debugger and determine _exact_ values of model and l2sizekb in the above source? It is around line 540 in gcc/config/i386/driver-i386.c.
Comment 3 H.J. Lu 2010-05-09 14:43:11 UTC
A patch is posted at

http://gcc.gnu.org/ml/gcc-patches/2010-05/msg00606.html
Comment 4 hjl@gcc.gnu.org 2010-05-09 14:50:06 UTC
Subject: Bug 44046

Author: hjl
Date: Sun May  9 14:49:53 2010
New Revision: 159202

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=159202
Log:
Properly detect Atom, Core 2 and Core i7.

2010-05-09  H.J. Lu  <hongjiu.lu@intel.com>

	PR target/44046
	* config/i386/driver-i386.c (host_detect_local_cpu): Properly
	detect Atom, Core 2 and Core i7.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/config/i386/driver-i386.c

Comment 5 hjl@gcc.gnu.org 2010-05-09 14:53:12 UTC
Subject: Bug 44046

Author: hjl
Date: Sun May  9 14:53:00 2010
New Revision: 159203

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=159203
Log:
Properly detect Atom, Core 2 and Core i7.

2010-05-09  H.J. Lu  <hongjiu.lu@intel.com>

	Backport from mainline
	2010-05-09  H.J. Lu  <hongjiu.lu@intel.com>

	PR target/44046
	* config/i386/driver-i386.c (host_detect_local_cpu): Properly
	detect Atom, Core 2 and Core i7.

Modified:
    branches/gcc-4_5-branch/gcc/ChangeLog
    branches/gcc-4_5-branch/gcc/config/i386/driver-i386.c

Comment 6 Ryan Hill 2010-05-09 18:39:04 UTC
Created attachment 20614 [details]
gcc45-PR44046-core2.patch
Comment 7 Ryan Hill 2010-05-09 18:44:39 UTC
sorry, wrong bugzilla. ;)
Comment 8 H.J. Lu 2010-05-10 03:52:58 UTC
Fixed. No need to change gcc 4.4.
Comment 9 Jakub Jelinek 2010-08-11 18:44:45 UTC
Apparently some KVM versions claim to be GenuineIntel family 6 model 6 with lm, but not ssse3, see
https://bugzilla.redhat.com/show_bug.cgi?id=620562
Perhaps the has_longmode -> core2 test should be restored...
Comment 10 H.J. Lu 2010-08-11 19:12:20 UTC
(In reply to comment #9)
> Apparently some KVM versions claim to be GenuineIntel family 6 model 6 with lm,
> but not ssse3, see
> https://bugzilla.redhat.com/show_bug.cgi?id=620562
> Perhaps the has_longmode -> core2 test should be restored...
> 

There are no such processors from Intel. If you look at SSE3 and LM, it
sounds like Nocona. But it also has family 6 and model 6. It looks like
Pentium-M. If we pass -march=core2, it will generate SSSE3, which isn't
supported. The bug is in KVM. It should never make up fake Intel processors.
Comment 11 H.J. Lu 2010-08-11 20:31:16 UTC
Maybe we can improve the unknown processor support:

1. For 32bit, use i686 + -mSSEx.
2. For 64bit, use x86_64 + -mSSEx.
Comment 12 Dzianis Kahanovich 2010-11-01 13:22:26 UTC
This patch produced regression, described (and more) in Bug 45359