public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug rtl-optimization/34522]  New: bad code for long long multiply when only low bits are needed
@ 2007-12-18 16:49 bonzini at gnu dot org
  2007-12-18 16:50 ` [Bug rtl-optimization/34522] " bonzini at gnu dot org
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: bonzini at gnu dot org @ 2007-12-18 16:49 UTC (permalink / raw)
  To: gcc-bugs

For

int test(long long a, long long b)
{
        return a * b;
}

GCC generates a widening multiply, and cannot remove the DImode operations
until after register allocation.  This causes unnecessary splits.

This could be fixed on the tree level by folding to (int)a * (int)b, or
alternatively in expand.

expand_expr is called with

 <mult_expr 0x2aaaae9032c0
    type <integer_type 0x2aaaae937840 long long int DI>
    arg 0 <parm_decl 0x2aaaae92d2d0 b type <integer_type 0x2aaaae937840 long
long int>>
    arg 1 <parm_decl 0x2aaaae92d240 a type <integer_type 0x2aaaae937840 long
long int>>>

and tmode SImode, still enough info to choose a better multiply.  However,
tmode is not passed on to expand_mult.


-- 
           Summary: bad code for long long multiply when only low bits are
                    needed
           Product: gcc
           Version: 4.3.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: normal
          Priority: P3
         Component: rtl-optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: bonzini at gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34522


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug rtl-optimization/34522] bad code for long long multiply when only low bits are needed
  2007-12-18 16:49 [Bug rtl-optimization/34522] New: bad code for long long multiply when only low bits are needed bonzini at gnu dot org
@ 2007-12-18 16:50 ` bonzini at gnu dot org
  2007-12-18 16:59 ` [Bug rtl-optimization/34522] inefficient " bonzini at gnu dot org
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: bonzini at gnu dot org @ 2007-12-18 16:50 UTC (permalink / raw)
  To: gcc-bugs



-- 

bonzini at gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
   Last reconfirmed|0000-00-00 00:00:00         |2007-12-18 16:49:58
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34522


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug rtl-optimization/34522] inefficient code for long long multiply when only low bits are needed
  2007-12-18 16:49 [Bug rtl-optimization/34522] New: bad code for long long multiply when only low bits are needed bonzini at gnu dot org
  2007-12-18 16:50 ` [Bug rtl-optimization/34522] " bonzini at gnu dot org
@ 2007-12-18 16:59 ` bonzini at gnu dot org
  2007-12-19  9:08 ` jakub at gcc dot gnu dot org
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: bonzini at gnu dot org @ 2007-12-18 16:59 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from bonzini at gnu dot org  2007-12-18 16:58 -------
Prototype untested patch.  Produces

        movl    12(%esp), %eax
        imull   4(%esp), %eax
        ret

on the testcase.

Index: expr.c
===================================================================
--- expr.c      (revision 130928)
+++ expr.c      (working copy)
@@ -8642,7 +8642,8 @@ expand_expr_real_1 (tree exp, rtx target
        }
       expand_operands (TREE_OPERAND (exp, 0), TREE_OPERAND (exp, 1),
                       subtarget, &op0, &op1, 0);
-      return REDUCE_BIT_FIELD (expand_mult (mode, op0, op1, target,
unsignedp));
+      return REDUCE_BIT_FIELD (expand_mult (tmode != VOIDmode ? tmode : mode,
+                                            op0, op1, target, unsignedp));

     case TRUNC_DIV_EXPR:
     case FLOOR_DIV_EXPR:


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34522


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug rtl-optimization/34522] inefficient code for long long multiply when only low bits are needed
  2007-12-18 16:49 [Bug rtl-optimization/34522] New: bad code for long long multiply when only low bits are needed bonzini at gnu dot org
  2007-12-18 16:50 ` [Bug rtl-optimization/34522] " bonzini at gnu dot org
  2007-12-18 16:59 ` [Bug rtl-optimization/34522] inefficient " bonzini at gnu dot org
@ 2007-12-19  9:08 ` jakub at gcc dot gnu dot org
  2007-12-19  9:37 ` bonzini at gnu dot org
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: jakub at gcc dot gnu dot org @ 2007-12-19  9:08 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from jakub at gcc dot gnu dot org  2007-12-19 09:08 -------
Shouldn't tmode be only used if GET_MODE_CLASS (tmode) == MODE_INT
&& GET_MODE_CLASS (mode) == MODE_INT && GET_MODE_BITSIZE (tmode) <
GET_MODE_BITSIZE (mode), to make sure we optimize only narrow, never widen, and
that float etc. multiplication is not affected?


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34522


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug rtl-optimization/34522] inefficient code for long long multiply when only low bits are needed
  2007-12-18 16:49 [Bug rtl-optimization/34522] New: bad code for long long multiply when only low bits are needed bonzini at gnu dot org
                   ` (2 preceding siblings ...)
  2007-12-19  9:08 ` jakub at gcc dot gnu dot org
@ 2007-12-19  9:37 ` bonzini at gnu dot org
  2008-02-21 15:42 ` ubizjak at gmail dot com
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: bonzini at gnu dot org @ 2007-12-19  9:37 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from bonzini at gnu dot org  2007-12-19 09:37 -------
Makes a lot of sense.  I made the patch only to test that it would not crash,
or something like that.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34522


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug rtl-optimization/34522] inefficient code for long long multiply when only low bits are needed
  2007-12-18 16:49 [Bug rtl-optimization/34522] New: bad code for long long multiply when only low bits are needed bonzini at gnu dot org
                   ` (3 preceding siblings ...)
  2007-12-19  9:37 ` bonzini at gnu dot org
@ 2008-02-21 15:42 ` ubizjak at gmail dot com
  2008-02-21 15:53 ` bonzini at gnu dot org
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: ubizjak at gmail dot com @ 2008-02-21 15:42 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from ubizjak at gmail dot com  2008-02-21 15:41 -------
(In reply to comment #1)
> Prototype untested patch.  Produces

Paolo, do you plan to test your patch and submit it to gcc-patches@ ?


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34522


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug rtl-optimization/34522] inefficient code for long long multiply when only low bits are needed
  2007-12-18 16:49 [Bug rtl-optimization/34522] New: bad code for long long multiply when only low bits are needed bonzini at gnu dot org
                   ` (4 preceding siblings ...)
  2008-02-21 15:42 ` ubizjak at gmail dot com
@ 2008-02-21 15:53 ` bonzini at gnu dot org
  2008-03-12  9:01 ` bonzini at gnu dot org
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: bonzini at gnu dot org @ 2008-02-21 15:53 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from bonzini at gnu dot org  2008-02-21 15:52 -------
I want to clear 17236 first (and Jakub's tweaks are needed anyway).

Feel free to beat me to it.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34522


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug rtl-optimization/34522] inefficient code for long long multiply when only low bits are needed
  2007-12-18 16:49 [Bug rtl-optimization/34522] New: bad code for long long multiply when only low bits are needed bonzini at gnu dot org
                   ` (5 preceding siblings ...)
  2008-02-21 15:53 ` bonzini at gnu dot org
@ 2008-03-12  9:01 ` bonzini at gnu dot org
  2008-03-12 12:52 ` bonzini at gnu dot org
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: bonzini at gnu dot org @ 2008-03-12  9:01 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from bonzini at gnu dot org  2008-03-12 09:00 -------
testing


-- 

bonzini at gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |bonzini at gnu dot org
                   |dot org                     |
             Status|NEW                         |ASSIGNED
   Last reconfirmed|2007-12-18 16:49:58         |2008-03-12 09:00:32
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34522


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug rtl-optimization/34522] inefficient code for long long multiply when only low bits are needed
  2007-12-18 16:49 [Bug rtl-optimization/34522] New: bad code for long long multiply when only low bits are needed bonzini at gnu dot org
                   ` (6 preceding siblings ...)
  2008-03-12  9:01 ` bonzini at gnu dot org
@ 2008-03-12 12:52 ` bonzini at gnu dot org
  2008-03-12 12:57 ` bonzini at gnu dot org
  2008-03-12 15:34 ` bonzini at gnu dot org
  9 siblings, 0 replies; 11+ messages in thread
From: bonzini at gnu dot org @ 2008-03-12 12:52 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from bonzini at gnu dot org  2008-03-12 12:50 -------
The expand patch does not bootstrap, even with the tweaks Jakub suggested.

I'm also hesitant to fold it on the tree level because it's actually undefined
code unless -fwrapv.  For example if a = b = 65536LL,

 (int) a * (int) b = undefined
 (int) (a * b) = (int) (1LL << 32) = 0


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34522


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug rtl-optimization/34522] inefficient code for long long multiply when only low bits are needed
  2007-12-18 16:49 [Bug rtl-optimization/34522] New: bad code for long long multiply when only low bits are needed bonzini at gnu dot org
                   ` (7 preceding siblings ...)
  2008-03-12 12:52 ` bonzini at gnu dot org
@ 2008-03-12 12:57 ` bonzini at gnu dot org
  2008-03-12 15:34 ` bonzini at gnu dot org
  9 siblings, 0 replies; 11+ messages in thread
From: bonzini at gnu dot org @ 2008-03-12 12:57 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #8 from bonzini at gnu dot org  2008-03-12 12:56 -------
Hmm maybe I can go through an unsigned type.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34522


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug rtl-optimization/34522] inefficient code for long long multiply when only low bits are needed
  2007-12-18 16:49 [Bug rtl-optimization/34522] New: bad code for long long multiply when only low bits are needed bonzini at gnu dot org
                   ` (8 preceding siblings ...)
  2008-03-12 12:57 ` bonzini at gnu dot org
@ 2008-03-12 15:34 ` bonzini at gnu dot org
  9 siblings, 0 replies; 11+ messages in thread
From: bonzini at gnu dot org @ 2008-03-12 15:34 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #9 from bonzini at gnu dot org  2008-03-12 15:34 -------
fixed in 4.4


-- 

bonzini at gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
      Known to work|                            |4.4.0
         Resolution|                            |FIXED


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34522


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2008-03-12 15:34 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-12-18 16:49 [Bug rtl-optimization/34522] New: bad code for long long multiply when only low bits are needed bonzini at gnu dot org
2007-12-18 16:50 ` [Bug rtl-optimization/34522] " bonzini at gnu dot org
2007-12-18 16:59 ` [Bug rtl-optimization/34522] inefficient " bonzini at gnu dot org
2007-12-19  9:08 ` jakub at gcc dot gnu dot org
2007-12-19  9:37 ` bonzini at gnu dot org
2008-02-21 15:42 ` ubizjak at gmail dot com
2008-02-21 15:53 ` bonzini at gnu dot org
2008-03-12  9:01 ` bonzini at gnu dot org
2008-03-12 12:52 ` bonzini at gnu dot org
2008-03-12 12:57 ` bonzini at gnu dot org
2008-03-12 15:34 ` bonzini at gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).