Bug 42445 - LTO performance: -march=native isn't saved in COLLECT_GCC_OPTIONS
Summary: LTO performance: -march=native isn't saved in COLLECT_GCC_OPTIONS
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: driver (show other bugs)
Version: 4.5.0
: P3 normal
Target Milestone: 4.6.0
Assignee: Not yet assigned to anyone
URL: http://gcc.gnu.org/ml/gcc-patches/201...
Keywords:
Depends on:
Blocks:
 
Reported: 2009-12-20 22:16 UTC by H.J. Lu
Modified: 2011-01-07 20:36 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description H.J. Lu 2009-12-20 22:16:07 UTC
On Linux/ia32, I got

[hjl@gnu-29 gcc]$ ./xgcc -B./ -S -march=native x.i -v
Reading specs from ./specs
COLLECT_GCC=./xgcc
COLLECT_LTO_WRAPPER=./lto-wrapper
Target: i686-pc-linux-gnu
Configured with: ../src-trunk/configure --enable-clocale=gnu --with-system-zlib --enable-shared --with-demangler-in-ld -with-plugin-ld=ld.gold --enable-gold
Thread model: posix
gcc version 4.5.0 20091220 (experimental) [trunk revision 155368] (GCC) 
COLLECT_GCC_OPTIONS='-B./' '-S'  '-v'
 ./cc1 -fpreprocessed x.i -march=nocona -mcx16 -msahf --param l1-cache-size=16 --param l1-cache-line-size=64 --param l2-cache-size=2048 -mtune=nocona -quiet -dumpbase x.i -auxbase x -version -o x.s
GNU C (GCC) version 4.5.0 20091220 (experimental) [trunk revision 155368] (i686-pc-linux-gnu)
	compiled by GNU C version 4.5.0 20091220 (experimental) [trunk revision 155368], GMP version 4.2.4, MPFR version 2.4.1, MPC version 0.8
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
GNU C (GCC) version 4.5.0 20091220 (experimental) [trunk revision 155368] (i686-pc-linux-gnu)
	compiled by GNU C version 4.5.0 20091220 (experimental) [trunk revision 155368], GMP version 4.2.4, MPFR version 2.4.1, MPC version 0.8
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
Compiler executable checksum: 02fd4faf11d3fb405ccd44e93f31b44f
COMPILER_PATH=./
LIBRARY_PATH=./:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-B./' '-S'  '-v'
[hjl@gnu-29 gcc]$ ./xgcc -B./ -S -march=i686 x.i -v
Reading specs from ./specs
COLLECT_GCC=./xgcc
COLLECT_LTO_WRAPPER=./lto-wrapper
Target: i686-pc-linux-gnu
Configured with: ../src-trunk/configure --enable-clocale=gnu --with-system-zlib --enable-shared --with-demangler-in-ld -with-plugin-ld=ld.gold --enable-gold
Thread model: posix
gcc version 4.5.0 20091220 (experimental) [trunk revision 155368] (GCC) 
COLLECT_GCC_OPTIONS='-B./' '-S' '-march=i686' '-v'
 ./cc1 -fpreprocessed x.i -quiet -dumpbase x.i -march=i686 -auxbase x -version -o x.s
GNU C (GCC) version 4.5.0 20091220 (experimental) [trunk revision 155368] (i686-pc-linux-gnu)
	compiled by GNU C version 4.5.0 20091220 (experimental) [trunk revision 155368], GMP version 4.2.4, MPFR version 2.4.1, MPC version 0.8
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
GNU C (GCC) version 4.5.0 20091220 (experimental) [trunk revision 155368] (i686-pc-linux-gnu)
	compiled by GNU C version 4.5.0 20091220 (experimental) [trunk revision 155368], GMP version 4.2.4, MPFR version 2.4.1, MPC version 0.8
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
Compiler executable checksum: 02fd4faf11d3fb405ccd44e93f31b44f
COMPILER_PATH=./
LIBRARY_PATH=./:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-B./' '-S' '-march=i686' '-v'
[hjl@gnu-29 gcc]$
Comment 1 Dmitry Gorbachev 2011-01-06 14:44:00 UTC
This bug causes <http://gcc.gnu.org/ml/gcc-help/2010-11/msg00291.html>.
Comment 2 H.J. Lu 2011-01-06 15:03:29 UTC
Joseph, can the new driver framework fix it?
Comment 3 joseph@codesourcery.com 2011-01-06 16:02:11 UTC
I know nothing about what the issue is supposed to be here or what is or 
is not supposed to be in COLLECT_GCC_OPTIONS or how COLLECT_GCC_OPTIONS is 
used.
Comment 4 H.J. Lu 2011-01-06 16:34:30 UTC
(In reply to comment #3)
> I know nothing about what the issue is supposed to be here or what is or 
> is not supposed to be in COLLECT_GCC_OPTIONS or how COLLECT_GCC_OPTIONS is 
> used.

We have several issues:

1. COLLECT_GCC_OPTIONS is used by LTO.
2. GCC driver knows -march=native.
3. Compilers, cc1/cc1plus, ... don't know -march=native.

GCC driver translates -march=native to something cc1/cc1plus
knows. Since -march=native isn't saved in COLLECT_GCC_OPTIONS,
LTO doesn't work with -march=native.  If -march=native handling
is moved from GCC driver to cc1/cc1plus, this issue can be solved
very easily.
Comment 5 joseph@codesourcery.com 2011-01-06 16:47:48 UTC
On Thu, 6 Jan 2011, hjl.tools at gmail dot com wrote:

> GCC driver translates -march=native to something cc1/cc1plus
> knows. Since -march=native isn't saved in COLLECT_GCC_OPTIONS,
> LTO doesn't work with -march=native.  If -march=native handling
> is moved from GCC driver to cc1/cc1plus, this issue can be solved
> very easily.

It's deliberate that -march=native is in the driver so that the output of 
"gcc -v" shows the particular options it chose.  Maybe COLLECT_GCC_OPTIONS 
should be saving the options that were generated from -march=native in the 
driver.
Comment 6 Joost VandeVondele 2011-01-06 17:50:16 UTC
This actually seems an important bug to solve, as -march=native users will otherwise have a bad experience with LTO.
Comment 7 H.J. Lu 2011-01-06 21:16:13 UTC
A patch is posted at

http://gcc.gnu.org/ml/gcc-patches/2011-01/msg00324.html
Comment 8 hjl@gcc.gnu.org 2011-01-07 20:35:08 UTC
Author: hjl
Date: Fri Jan  7 20:35:05 2011
New Revision: 168583

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=168583
Log:
Keep -m[arch|tune]=native in COLLECT_GCC_OPTIONS.

2011-01-07  H.J. Lu  <hongjiu.lu@intel.com>

	PR driver/42445
	* gcc.c (%>S): New.
	(SWITCH_KEEP_FOR_GCC): Likewise.
	(set_collect_gcc_options): Check SWITCH_KEEP_FOR_GCC.
	(do_spec_1): Handle "%>".

	* config/i386/i386.h (CC1_CPU_SPEC): Replace "%<" with "%>".

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/config/i386/i386.h
    trunk/gcc/gcc.c
Comment 9 H.J. Lu 2011-01-07 20:36:54 UTC
Fixed for 4.6.  No plan for backport.