public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug rtl-optimization/47299] New: Widening multiply optimization generates bad code
@ 2011-01-14 21:34 uweigand at gcc dot gnu.org
2011-01-14 22:22 ` [Bug rtl-optimization/47299] " rguenther at suse dot de
` (7 more replies)
0 siblings, 8 replies; 9+ messages in thread
From: uweigand at gcc dot gnu.org @ 2011-01-14 21:34 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47299
Summary: Widening multiply optimization generates bad code
Product: gcc
Version: 4.5.0
Status: UNCONFIRMED
Keywords: wrong-code
Severity: normal
Priority: P3
Component: rtl-optimization
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: uweigand@gcc.gnu.org
CC: bernds@codesourcery.com, rguenther@suse.de
Building the following test case with current mainline on i386:
unsigned short test (unsigned char val) __attribute__ ((noinline));
unsigned short
test (unsigned char val)
{
return val * 255;
}
int
main(int argc, char**argv)
{
printf ("test(val=40) = %x\n", test(0x40));
return 0;
}
We get the following (correct) output with -O0:
test(val=40) = 3fc0
and the following incorrect output with -O2:
test(val=40) = ffc0
The problem appears to be related to this piece of code in expand_expr_real2,
case WIDEN_MULT_EXPR:
expand_operands (treeop0, treeop1, NULL_RTX, &op0, &op1,
EXPAND_NORMAL);
temp = expand_widening_mult (mode, op0, op1, target,
unsignedp, this_optab);
expand_operands will expand the constant 255 into QImode and return a
(const_int -1) for op1. Passing this constant into expand_widening_mult then
apparently generates a simple negation operation in HImode instead (via
expand_const_mult) ...
It seems this code came in here:
http://gcc.gnu.org/ml/gcc-patches/2010-04/msg01327.html
Any suggestions how this ought to be handled?
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug rtl-optimization/47299] Widening multiply optimization generates bad code
2011-01-14 21:34 [Bug rtl-optimization/47299] New: Widening multiply optimization generates bad code uweigand at gcc dot gnu.org
@ 2011-01-14 22:22 ` rguenther at suse dot de
2011-01-16 4:10 ` doko at ubuntu dot com
` (6 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: rguenther at suse dot de @ 2011-01-14 22:22 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47299
--- Comment #1 from rguenther at suse dot de <rguenther at suse dot de> 2011-01-14 21:49:32 UTC ---
On Fri, 14 Jan 2011, uweigand at gcc dot gnu.org wrote:
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47299
>
> Summary: Widening multiply optimization generates bad code
> Product: gcc
> Version: 4.5.0
> Status: UNCONFIRMED
> Keywords: wrong-code
> Severity: normal
> Priority: P3
> Component: rtl-optimization
> AssignedTo: unassigned@gcc.gnu.org
> ReportedBy: uweigand@gcc.gnu.org
> CC: bernds@codesourcery.com, rguenther@suse.de
>
>
> Building the following test case with current mainline on i386:
>
> unsigned short test (unsigned char val) __attribute__ ((noinline));
>
> unsigned short
> test (unsigned char val)
> {
> return val * 255;
> }
>
> int
> main(int argc, char**argv)
> {
> printf ("test(val=40) = %x\n", test(0x40));
> return 0;
> }
>
> We get the following (correct) output with -O0:
> test(val=40) = 3fc0
>
> and the following incorrect output with -O2:
> test(val=40) = ffc0
>
> The problem appears to be related to this piece of code in expand_expr_real2,
> case WIDEN_MULT_EXPR:
>
> expand_operands (treeop0, treeop1, NULL_RTX, &op0, &op1,
> EXPAND_NORMAL);
> temp = expand_widening_mult (mode, op0, op1, target,
> unsignedp, this_optab);
>
> expand_operands will expand the constant 255 into QImode and return a
> (const_int -1) for op1. Passing this constant into expand_widening_mult then
> apparently generates a simple negation operation in HImode instead (via
> expand_const_mult) ...
>
> It seems this code came in here:
> http://gcc.gnu.org/ml/gcc-patches/2010-04/msg01327.html
> Any suggestions how this ought to be handled?
I think we need to pass the narrow mode explicitly.
Richard.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug rtl-optimization/47299] Widening multiply optimization generates bad code
2011-01-14 21:34 [Bug rtl-optimization/47299] New: Widening multiply optimization generates bad code uweigand at gcc dot gnu.org
2011-01-14 22:22 ` [Bug rtl-optimization/47299] " rguenther at suse dot de
@ 2011-01-16 4:10 ` doko at ubuntu dot com
2011-01-16 15:58 ` [Bug rtl-optimization/47299] [4.6 Regression] " hjl.tools at gmail dot com
` (5 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: doko at ubuntu dot com @ 2011-01-16 4:10 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47299
Matthias Klose <doko at ubuntu dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |doko at ubuntu dot com
--- Comment #2 from Matthias Klose <doko at ubuntu dot com> 2011-01-16 03:51:05 UTC ---
4.5/4.6 regression
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug rtl-optimization/47299] [4.6 Regression] Widening multiply optimization generates bad code
2011-01-14 21:34 [Bug rtl-optimization/47299] New: Widening multiply optimization generates bad code uweigand at gcc dot gnu.org
2011-01-14 22:22 ` [Bug rtl-optimization/47299] " rguenther at suse dot de
2011-01-16 4:10 ` doko at ubuntu dot com
@ 2011-01-16 15:58 ` hjl.tools at gmail dot com
2011-01-16 16:40 ` jakub at gcc dot gnu.org
` (4 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: hjl.tools at gmail dot com @ 2011-01-16 15:58 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47299
H.J. Lu <hjl.tools at gmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Last reconfirmed| |2011.01.16 15:53:38
Version|4.5.0 |4.6.0
Target Milestone|--- |4.6.0
Summary|Widening multiply |[4.6 Regression] Widening
|optimization generates bad |multiply optimization
|code |generates bad code
Ever Confirmed|0 |1
--- Comment #3 from H.J. Lu <hjl.tools at gmail dot com> 2011-01-16 15:53:38 UTC ---
It is a 4.6 regression. 4.5 branch is OK.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug rtl-optimization/47299] [4.6 Regression] Widening multiply optimization generates bad code
2011-01-14 21:34 [Bug rtl-optimization/47299] New: Widening multiply optimization generates bad code uweigand at gcc dot gnu.org
` (2 preceding siblings ...)
2011-01-16 15:58 ` [Bug rtl-optimization/47299] [4.6 Regression] " hjl.tools at gmail dot com
@ 2011-01-16 16:40 ` jakub at gcc dot gnu.org
2011-01-17 11:32 ` jakub at gcc dot gnu.org
` (3 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: jakub at gcc dot gnu.org @ 2011-01-16 16:40 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47299
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Priority|P3 |P1
CC| |jakub at gcc dot gnu.org
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug rtl-optimization/47299] [4.6 Regression] Widening multiply optimization generates bad code
2011-01-14 21:34 [Bug rtl-optimization/47299] New: Widening multiply optimization generates bad code uweigand at gcc dot gnu.org
` (3 preceding siblings ...)
2011-01-16 16:40 ` jakub at gcc dot gnu.org
@ 2011-01-17 11:32 ` jakub at gcc dot gnu.org
2011-01-17 23:52 ` doko at ubuntu dot com
` (2 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: jakub at gcc dot gnu.org @ 2011-01-17 11:32 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47299
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |ASSIGNED
AssignedTo|unassigned at gcc dot |jakub at gcc dot gnu.org
|gnu.org |
--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> 2011-01-17 11:25:00 UTC ---
Created attachment 22994
--> http://gcc.gnu.org/bugzilla/attachment.cgi?id=22994
gcc46-pr47299.patch
Untested fix.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug rtl-optimization/47299] [4.6 Regression] Widening multiply optimization generates bad code
2011-01-14 21:34 [Bug rtl-optimization/47299] New: Widening multiply optimization generates bad code uweigand at gcc dot gnu.org
` (4 preceding siblings ...)
2011-01-17 11:32 ` jakub at gcc dot gnu.org
@ 2011-01-17 23:52 ` doko at ubuntu dot com
2011-01-18 8:59 ` jakub at gcc dot gnu.org
2011-01-18 9:05 ` jakub at gcc dot gnu.org
7 siblings, 0 replies; 9+ messages in thread
From: doko at ubuntu dot com @ 2011-01-17 23:52 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47299
--- Comment #5 from Matthias Klose <doko at ubuntu dot com> 2011-01-17 23:05:35 UTC ---
a biarch build for yesterday's trunk on i686 with the proposed patch applied
succeeds and doesn't show any regressions.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug rtl-optimization/47299] [4.6 Regression] Widening multiply optimization generates bad code
2011-01-14 21:34 [Bug rtl-optimization/47299] New: Widening multiply optimization generates bad code uweigand at gcc dot gnu.org
` (5 preceding siblings ...)
2011-01-17 23:52 ` doko at ubuntu dot com
@ 2011-01-18 8:59 ` jakub at gcc dot gnu.org
2011-01-18 9:05 ` jakub at gcc dot gnu.org
7 siblings, 0 replies; 9+ messages in thread
From: jakub at gcc dot gnu.org @ 2011-01-18 8:59 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47299
--- Comment #6 from Jakub Jelinek <jakub at gcc dot gnu.org> 2011-01-18 07:45:17 UTC ---
Author: jakub
Date: Tue Jan 18 07:45:12 2011
New Revision: 168944
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=168944
Log:
PR rtl-optimization/47299
* expr.c (expand_expr_real_2) <case WIDEN_MULT_EXPR>: Don't use
subtarget. Use normal multiplication if both operands are
constants.
* expmed.c (expand_widening_mult): Don't try to optimize constant
multiplication if op0 has VOIDmode. Convert op1 constant to mode
before using it.
* gcc.c-torture/execute/pr47299.c: New test.
Added:
trunk/gcc/testsuite/gcc.c-torture/execute/pr47299.c
Modified:
trunk/gcc/ChangeLog
trunk/gcc/expmed.c
trunk/gcc/expr.c
trunk/gcc/testsuite/ChangeLog
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug rtl-optimization/47299] [4.6 Regression] Widening multiply optimization generates bad code
2011-01-14 21:34 [Bug rtl-optimization/47299] New: Widening multiply optimization generates bad code uweigand at gcc dot gnu.org
` (6 preceding siblings ...)
2011-01-18 8:59 ` jakub at gcc dot gnu.org
@ 2011-01-18 9:05 ` jakub at gcc dot gnu.org
7 siblings, 0 replies; 9+ messages in thread
From: jakub at gcc dot gnu.org @ 2011-01-18 9:05 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47299
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution| |FIXED
--- Comment #7 from Jakub Jelinek <jakub at gcc dot gnu.org> 2011-01-18 08:15:02 UTC ---
Fixed.
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2011-01-18 8:15 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-01-14 21:34 [Bug rtl-optimization/47299] New: Widening multiply optimization generates bad code uweigand at gcc dot gnu.org
2011-01-14 22:22 ` [Bug rtl-optimization/47299] " rguenther at suse dot de
2011-01-16 4:10 ` doko at ubuntu dot com
2011-01-16 15:58 ` [Bug rtl-optimization/47299] [4.6 Regression] " hjl.tools at gmail dot com
2011-01-16 16:40 ` jakub at gcc dot gnu.org
2011-01-17 11:32 ` jakub at gcc dot gnu.org
2011-01-17 23:52 ` doko at ubuntu dot com
2011-01-18 8:59 ` jakub at gcc dot gnu.org
2011-01-18 9:05 ` jakub at gcc dot gnu.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).