Bug 11008 - improper multiply optimization for pentium4
Summary: improper multiply optimization for pentium4
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 3.3
: P2 minor
Target Milestone: 3.4.0
Assignee: Andrew Pinski
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-05-28 03:18 UTC by Luchezar Belev
Modified: 2003-08-08 04:40 UTC (History)
1 user (show)

See Also:
Host: (dont know what `Host triplet' means)
Target: (dont know what `Target triplet' means)
Build: (dont know what `Build triplet' means)
Known to work:
Known to fail:
Last reconfirmed: 2003-05-29 15:17:25


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Luchezar Belev 2003-05-28 03:18:04 UTC
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).
Comment 1 Andrew Pinski 2003-05-28 03:43:23 UTC
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; }
Comment 2 Andrew Pinski 2003-05-28 03:47:02 UTC
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.
Comment 3 Luchezar Belev 2003-05-28 19:21:56 UTC
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
Comment 4 Andrew Pinski 2003-05-28 19:33:42 UTC
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.
Comment 5 Andrew Pinski 2003-05-29 03:18:46 UTC
I see this also on 3.2.3, 3.3.1 (20030526).
Comment 6 Andrew Pinski 2003-05-29 15:16:54 UTC
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.
Comment 7 Andrew Pinski 2003-05-29 15:29:44 UTC
Test case submitted: <http://gcc.gnu.org/ml/gcc-patches/2003-05/msg02335.html>
Comment 8 Andrew Pinski 2003-05-29 16:49:45 UTC
Closing even though the test case has not went in.
Comment 9 GCC Commits 2003-07-16 18:23:35 UTC
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