public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/32593] New: Missed optimization of 'y = constant - x' operation
@ 2007-07-02 18:47 astrange at ithinksw dot com
2007-07-02 18:48 ` [Bug tree-optimization/32593] " astrange at ithinksw dot com
` (7 more replies)
0 siblings, 8 replies; 9+ messages in thread
From: astrange at ithinksw dot com @ 2007-07-02 18:47 UTC (permalink / raw)
To: gcc-bugs
> /usr/local/gcc43/bin/g++ -v
Using built-in specs.
Target: i386-apple-darwin8.10.1
Configured with: ../gcc/configure --prefix=/usr/local/gcc43 --disable-multilib
--with-arch=pentium-m --with-tune=nocona --enable-target-optspace
--disable-bootstrap --with-gmp=/sw --with-system-zlib
--enable-languages=c,c++,objc,obj-c++
Thread model: posix
gcc version 4.3.0 20070702 (experimental)
> /usr/local/gcc43/bin/gcc -Os -fno-pic -fomit-frame-pointer -S sub.c
"i= 7 - ff_h264_norm_shift[x>>(CABAC_BITS-1)];" generates:
movl $7, %ecx
subl %eax, %ecx
sall %cl, %edx
It would be better if it generated:
negl %eax
addl $7, %eax
sall %al, %edx
which would leave a register free (which helps if this function is inlined);
this is safe since eax isn't used again later.
You can do this by transforming 'y = constant - x' into 'y = -x + constant'.
It looks like gcc actually does the reverse; if I change the source to match
the best output, it generates the same thing.
--
Summary: Missed optimization of 'y = constant - x' operation
Product: gcc
Version: 4.3.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: astrange at ithinksw dot com
GCC build triplet: i386-apple-darwin8.10.1
GCC host triplet: i386-apple-darwin8.10.1
GCC target triplet: i386-apple-darwin8.10.1
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32593
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug tree-optimization/32593] Missed optimization of 'y = constant - x' operation
2007-07-02 18:47 [Bug tree-optimization/32593] New: Missed optimization of 'y = constant - x' operation astrange at ithinksw dot com
@ 2007-07-02 18:48 ` astrange at ithinksw dot com
2007-07-02 19:06 ` [Bug target/32593] " pinskia at gcc dot gnu dot org
` (6 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: astrange at ithinksw dot com @ 2007-07-02 18:48 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from astrange at ithinksw dot com 2007-07-02 18:47 -------
Created an attachment (id=13827)
--> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=13827&action=view)
testcase
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32593
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug target/32593] Missed optimization of 'y = constant - x' operation
2007-07-02 18:47 [Bug tree-optimization/32593] New: Missed optimization of 'y = constant - x' operation astrange at ithinksw dot com
2007-07-02 18:48 ` [Bug tree-optimization/32593] " astrange at ithinksw dot com
@ 2007-07-02 19:06 ` pinskia at gcc dot gnu dot org
2008-02-16 18:17 ` astrange at ithinksw dot com
` (5 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2007-07-02 19:06 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from pinskia at gcc dot gnu dot org 2007-07-02 19:06 -------
This is a target issue (or a semi generic one for 2-operand targets).
--
pinskia at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Component|tree-optimization |target
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32593
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug target/32593] Missed optimization of 'y = constant - x' operation
2007-07-02 18:47 [Bug tree-optimization/32593] New: Missed optimization of 'y = constant - x' operation astrange at ithinksw dot com
2007-07-02 18:48 ` [Bug tree-optimization/32593] " astrange at ithinksw dot com
2007-07-02 19:06 ` [Bug target/32593] " pinskia at gcc dot gnu dot org
@ 2008-02-16 18:17 ` astrange at ithinksw dot com
2008-02-16 20:19 ` astrange at ithinksw dot com
` (4 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: astrange at ithinksw dot com @ 2008-02-16 18:17 UTC (permalink / raw)
To: gcc-bugs
------- Comment #3 from astrange at ithinksw dot com 2008-02-16 18:16 -------
Also, 'x >> 32 - y' can be transformed into 'x >> -y', since x86 only uses the
lowest 5 bits. I'm not sure about other targets.
Messing with the backend doesn't seem very popular these days. I guess I should
figure out how those parts work.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32593
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug target/32593] Missed optimization of 'y = constant - x' operation
2007-07-02 18:47 [Bug tree-optimization/32593] New: Missed optimization of 'y = constant - x' operation astrange at ithinksw dot com
` (2 preceding siblings ...)
2008-02-16 18:17 ` astrange at ithinksw dot com
@ 2008-02-16 20:19 ` astrange at ithinksw dot com
2008-12-17 22:11 ` astrange at ithinksw dot com
` (3 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: astrange at ithinksw dot com @ 2008-02-16 20:19 UTC (permalink / raw)
To: gcc-bugs
--
astrange at ithinksw dot com changed:
What |Removed |Added
----------------------------------------------------------------------------
Severity|normal |enhancement
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32593
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug target/32593] Missed optimization of 'y = constant - x' operation
2007-07-02 18:47 [Bug tree-optimization/32593] New: Missed optimization of 'y = constant - x' operation astrange at ithinksw dot com
` (3 preceding siblings ...)
2008-02-16 20:19 ` astrange at ithinksw dot com
@ 2008-12-17 22:11 ` astrange at ithinksw dot com
2009-11-07 9:35 ` bonzini at gnu dot org
` (2 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: astrange at ithinksw dot com @ 2008-12-17 22:11 UTC (permalink / raw)
To: gcc-bugs
------- Comment #4 from astrange at ithinksw dot com 2008-12-17 22:10 -------
Causes silly code on i386 with this:
void pred8x8l_vertical_add_c(unsigned char *pix, const short *block, int
stride){
int i;
for(i=0; i<8; i++){
int j;
for (j=0; j<8; j++){
pix[j] = pix[j-stride] + block[j];
}
pix+= stride;
block+= 8;
}
}
where it calculates and then spills each of [0-7] - stride to the stack,
instead of just being able to keep -stride in a register and incrementing it.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32593
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug target/32593] Missed optimization of 'y = constant - x' operation
2007-07-02 18:47 [Bug tree-optimization/32593] New: Missed optimization of 'y = constant - x' operation astrange at ithinksw dot com
` (4 preceding siblings ...)
2008-12-17 22:11 ` astrange at ithinksw dot com
@ 2009-11-07 9:35 ` bonzini at gnu dot org
2009-11-07 14:36 ` rguenth at gcc dot gnu dot org
2009-11-07 14:44 ` rguenth at gcc dot gnu dot org
7 siblings, 0 replies; 9+ messages in thread
From: bonzini at gnu dot org @ 2009-11-07 9:35 UTC (permalink / raw)
To: gcc-bugs
------- Comment #5 from bonzini at gnu dot org 2009-11-07 09:35 -------
Confirmed, the code for -O2 -funroll-loops includes things such as
movzwl 2(%eax), %esi
movl $1, -44(%ebp)
subl %ecx, -44(%ebp)
movl -44(%ebp), %edi
movzbl (%edx,%edi), %ebx
addl %ebx, %esi
movl %esi, %ebx
movb %bl, 1(%edx)
...
movl -44(%ebp), %ebx
movzwl 2(%esi), %edi
movzbl (%edx,%ebx), %ebx
addl %ebx, %edi
movl %edi, %ebx
movb %bl, 1(%edx)
The unrolling is done on the tree level, so it's CSE who'd need to know this.
--
bonzini at gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Ever Confirmed|0 |1
Keywords| |ra
Known to work| |4.5.0
Last reconfirmed|0000-00-00 00:00:00 |2009-11-07 09:35:37
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32593
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug target/32593] Missed optimization of 'y = constant - x' operation
2007-07-02 18:47 [Bug tree-optimization/32593] New: Missed optimization of 'y = constant - x' operation astrange at ithinksw dot com
` (5 preceding siblings ...)
2009-11-07 9:35 ` bonzini at gnu dot org
@ 2009-11-07 14:36 ` rguenth at gcc dot gnu dot org
2009-11-07 14:44 ` rguenth at gcc dot gnu dot org
7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2009-11-07 14:36 UTC (permalink / raw)
To: gcc-bugs
------- Comment #6 from rguenth at gcc dot gnu dot org 2009-11-07 14:35 -------
On the tree level we see (after FRE):
D.1996_50 = pix_1 + 1;
D.1997_51 = 1 - stride_11(D);
D.1998_52 = (unsigned int) D.1997_51;
D.1999_53 = pix_1 + D.1998_52;
D.2000_54 = *D.1999_53;
D.2003_57 = block_2 + 2;
D.2004_58 = *D.2003_57;
D.2005_59 = (unsigned char) D.2004_58;
D.2006_60 = D.2000_54 + D.2005_59;
*D.1996_50 = D.2006_60;
etc.
which again also shows the weakness of POINTER_PLUS_EXPR and the
conversions it causes for the offset operand. IVOPTs cannot cope
with it and PRE/LIM make a mess out of the code as well.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32593
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug target/32593] Missed optimization of 'y = constant - x' operation
2007-07-02 18:47 [Bug tree-optimization/32593] New: Missed optimization of 'y = constant - x' operation astrange at ithinksw dot com
` (6 preceding siblings ...)
2009-11-07 14:36 ` rguenth at gcc dot gnu dot org
@ 2009-11-07 14:44 ` rguenth at gcc dot gnu dot org
7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2009-11-07 14:44 UTC (permalink / raw)
To: gcc-bugs
------- Comment #7 from rguenth at gcc dot gnu dot org 2009-11-07 14:44 -------
Oh, there's no loop. Then it's the not implemented strength-reduction on
scalar code that is the issue. In theory strength-reduction can be
integrated into our global value-numbering / PRE code, but nobody has done
that.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32593
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2009-11-07 14:44 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-07-02 18:47 [Bug tree-optimization/32593] New: Missed optimization of 'y = constant - x' operation astrange at ithinksw dot com
2007-07-02 18:48 ` [Bug tree-optimization/32593] " astrange at ithinksw dot com
2007-07-02 19:06 ` [Bug target/32593] " pinskia at gcc dot gnu dot org
2008-02-16 18:17 ` astrange at ithinksw dot com
2008-02-16 20:19 ` astrange at ithinksw dot com
2008-12-17 22:11 ` astrange at ithinksw dot com
2009-11-07 9:35 ` bonzini at gnu dot org
2009-11-07 14:36 ` rguenth at gcc dot gnu dot org
2009-11-07 14:44 ` rguenth at gcc dot 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).