Opened 17 years ago

Closed 17 years ago

Last modified 14 years ago

#815 closed defect (invalid)

Strange compiler flags (-O4 etc.) with enabled runtime CPU detection

Reported by: the_unknown@… Owned by: diego@…
Priority: normal Component: build system
Version: HEAD Severity: minor
Keywords: Cc: reimar
Blocked By: Blocking:
Reproduced by developer: no Analyzed by developer: no

Description

The configure script sets strange compiler flags when configuring with enabled CPU detection, e.g. how it is done by portage in gentoo without custom CFLAGS (USE="-custom-cflags").
In particular, -O4 "optimization" and different architectures in -march and -mtune are set.

Here is an example of make output:
i686-pc-linux-gnu-gcc <some includes etc.> -O4 -march=i486 -mtune=i686 -pipe -ffast-math -fomit-frame-pointer <tons of includes> -c -o mplayer.o mplayer.c

Distro: gentoo
gcc version 4.1.2 (Gentoo 4.1.2)
$ as --version
GNU assembler 2.17
$ cat /proc/cpuinfo
processor : 0
vendor_id : AuthenticAMD
cpu family : 15
model : 47
model name : AMD Athlon(tm) 64 Processor 3500+
stepping : 2
cpu MHz : 1000.000
cache size : 512 KB
fdiv_bug : no
hlt_bug : no
f00f_bug : no
coma_bug : no
fpu : yes
fpu_exception : yes
cpuid level : 1
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 syscall nx mmxext fxsr_opt lm 3dnowext 3dnow pni lahf_lm ts fid vid ttp tm stc
bogomips : 2001.22
clflush size : 64

Attachments (3)

configure.log (111.4 KB ) - added by the_unknown@… 17 years ago.
configure.log
config.h (44.0 KB ) - added by the_unknown@… 17 years ago.
config.h
config.mak (15.8 KB ) - added by the_unknown@… 17 years ago.
config.mak

Download all attachments as: .zip

Change History (13)

by the_unknown@…, 17 years ago

Attachment: configure.log added

configure.log

comment:1 by the_unknown@…, 17 years ago

by the_unknown@…, 17 years ago

Attachment: config.h added

config.h

comment:2 by the_unknown@…, 17 years ago

by the_unknown@…, 17 years ago

Attachment: config.mak added

config.mak

comment:3 by the_unknown@…, 17 years ago

comment:4 by reimar, 17 years ago

Cc: Reimar.Doeffinger@… added

Huh? What is your problem with those flags? They are exactly as intended.

comment:5 by the_unknown@…, 17 years ago

If the wrong flags are set intentionaly, than it's ok
But at least -O4 looks like a typo for me, since gcc supports only -O, -O0, -O1, -O2, -O3 and -Os flags for optimization.

comment:6 by reimar, 17 years ago

Resolution: invalid
Status: newclosed

There are projects that use -O99. Not sure if it ever did something else than -O3, but no reason to change something that works perfectly fine.
As for -march and -mtune, read the documentation. -march changes which instructions are used (thus -march=i486 makes sure the binary also runs on i486) while mtune optimizes this 486-compatible code to run as good as possible on more recent systems.

comment:7 by the_unknown@…, 17 years ago

There are projects that use -O99

Yes, I know, there is a popular belief that larger values do even better optimization, but it is nothing more than -O3.

And for -march and -mtune, according to documentation -march implies -mtune, so they are just redundant, and setting them intentionally to different arches doesn't make any sence.

These are only a few cosmetic things, actually I was just surprised to see -O4 in mplayer :)

comment:8 by diego@…, 17 years ago

(In reply to comment #7)

There are projects that use -O99

Yes, I know, there is a popular belief that larger values do even better
optimization, but it is nothing more than -O3.

It might be more in the future.. Linux kernel uses -O9 for that reason IIRC.

comment:9 by xake@…, 14 years ago

(In reply to comment #8)

It might be more in the future.. Linux kernel uses -O9 for that reason IIRC.

From where did you get that funny idea?

~/devel/kernel/linux-2.6 $ grep O9 Makefile
~/devel/kernel/linux-2.6 $ grep O2 Makefile
HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
HOSTCXXFLAGS = -O2
KBUILD_CFLAGS += -O2

Even from the the kernel config:
CONFIG_CC_OPTIMIZE_FOR_SIZE:
Enabling this option will pass "-Os" instead of "-O2" to gccresulting in a smaller kernel.

That said -O3 is known to carry flags (-ftree-vectorize) that may even break code with some GCC versions (at least on 4.4.x) on some architectures (x86_32).

comment:10 by diego@…, 14 years ago

(In reply to comment #9)

(In reply to comment #8)

It might be more in the future.. Linux kernel uses -O9 for that reason IIRC.

From where did you get that funny idea?

3 years after writing this I do indeed wonder where I got the funny idea. The last thing I remember is the kernel using -O4.

Note: See TracTickets for help on using tickets.