Consider the function "int m27(int x) { return x*27; }". When I compile it with "-O2 -march=pentium4", GCC-3.3 does the multiplication with an `imul' instruction, but when I compile the same func with "-O2 -march=pentium3" it turns the multiplication into 3 simple instructions: lea - sub - lea. My point here is that on pentium4 the imul instructions are more expensive than on pentium3, so if GCC replaces them with leas/subs/etc. for pentium3, it should even harder do so for pentium4. I tested the speed of both generated codes on pentium4 and really the lea - sub - lea variant is considerably faster. So it seems that -march=pentium3 generates better code for pentium4 than -march=pentium4 (at least concerning the multiplications by a constant).
Can you give the full asm output of the test, as I cannot reproduce your results, I get only two lea: tin:~/src/gnu/gcctest>gcc -V3.3 -O2 pr11008.c -S -o - -fomit-frame-pointer .file "pr11008.c" .text .p2align 4,,15 .globl m27 .type m27, @function m27: movl 4(%esp), %eax leal (%eax,%eax,2), %eax leal (%eax,%eax,8), %eax ret .size m27, .-m27 .ident "GCC: (GNU) 3.3 20021216 (experimental)" tin:~/src/gnu/gcctest>more pr11008.c int m27(int x) { return x*27; }
I forgot to post the pentium4 result: tin:~/src/gnu/gcctest>gcc -V3.3 -O2 pr11008.c -S -o - -fomit-frame-pointer -mcpu= pentium4 .file "pr11008.c" .text .globl m27 .type m27, @function m27: movl 4(%esp), %eax leal (%eax,%eax,2), %eax leal (%eax,%eax,8), %eax ret .size m27, .-m27 .ident "GCC: (GNU) 3.3 20021216 (experimental)" Also I cannot even get an imul to be produced.
Subject: improper multiply optimization for pentium4 Sorry, I meant 29, not 27 Please replace the constant 27 with 29 in the sample function. __________________________________ Do you Yahoo!? Yahoo! Calendar - Free online calendar with sync to Outlook(TM). http://calendar.yahoo.com
Feed back recieved but I can only produce on the mainline (20030528) imull with -march=k6 and -march=k8. Looks like the mainline was fixed because on "3.3 20021216 (experimental)" with -march=pentium4, I get the imull as reported.
I see this also on 3.2.3, 3.3.1 (20030526).
Since pentium4 option did not exists before 3.1 and 3.1 produced an imull, I am closing this bug as it is fixed on the mainline (20030529). There should be a testcase for this bug though.
Test case submitted: <http://gcc.gnu.org/ml/gcc-patches/2003-05/msg02335.html>
Closing even though the test case has not went in.
Subject: Bug 11008 CVSROOT: /cvs/gcc Module name: gcc Changes by: pinskia@gcc.gnu.org 2003-07-16 18:23:32 Modified files: gcc/testsuite : ChangeLog Added files: gcc/testsuite/gcc.dg: i386-pentium4-no-mull.c Log message: 2003-07-16 Andrew Pinski <pinskia@physics.uc.edu> PR target/11008 * gcc.dg/i386-pentium4-not-mull.c: New. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.2886&r2=1.2887 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/i386-pentium4-no-mull.c.diff?cvsroot=gcc&r1=NONE&r2=1.1