public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
* [Bug rtl-optimization/53117] New: missed-optimization: worse code for 'x <= 0' compared to 'x < 0' @ 2012-04-25 14:21 vermaelen.wouter at gmail dot com 2012-04-25 14:26 ` [Bug rtl-optimization/53117] " jakub at gcc dot gnu.org ` (3 more replies) 0 siblings, 4 replies; 5+ messages in thread From: vermaelen.wouter at gmail dot com @ 2012-04-25 14:21 UTC (permalink / raw) To: gcc-bugs http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53117 Bug #: 53117 Summary: missed-optimization: worse code for 'x <= 0' compared to 'x < 0' Classification: Unclassified Product: gcc Version: 4.8.0 Status: UNCONFIRMED Severity: minor Priority: P3 Component: rtl-optimization AssignedTo: unassigned@gcc.gnu.org ReportedBy: vermaelen.wouter@gmail.com void f1(int* p) { p[1] -= 5; if (p[1] < 0) p[2] += 3; } void f2(int* p) { p[1] -= 5; if (p[1] <= 0) p[2] += 3; } The only difference between f1() and f2() is the comparison ('<' vs '<='). On x86_64 (and x86) gcc revision trunk@186808 generates more efficient code for f1() than for f2(). Here's the assembler output when compiled with -Os (but -O2 and -O3) show a similar difference: 0000000000000000 <_Z2f1Pi>: 0: 83 6f 04 05 subl $0x5,0x4(%rdi) 4: 79 04 jns a <_Z2f1Pi+0xa> 6: 83 47 08 03 addl $0x3,0x8(%rdi) a: c3 retq 000000000000000b <_Z2f2Pi>: b: 8b 47 04 mov 0x4(%rdi),%eax e: 83 e8 05 sub $0x5,%eax 11: 85 c0 test %eax,%eax 13: 89 47 04 mov %eax,0x4(%rdi) 16: 7f 04 jg 1c <_Z2f2Pi+0x11> 18: 83 47 08 03 addl $0x3,0x8(%rdi) 1c: c3 retq gcc-4.6.1 generates the less efficient variant for both functions. ^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug rtl-optimization/53117] missed-optimization: worse code for 'x <= 0' compared to 'x < 0' 2012-04-25 14:21 [Bug rtl-optimization/53117] New: missed-optimization: worse code for 'x <= 0' compared to 'x < 0' vermaelen.wouter at gmail dot com @ 2012-04-25 14:26 ` jakub at gcc dot gnu.org 2012-04-25 14:28 ` [Bug target/53117] " rguenth at gcc dot gnu.org ` (2 subsequent siblings) 3 siblings, 0 replies; 5+ messages in thread From: jakub at gcc dot gnu.org @ 2012-04-25 14:26 UTC (permalink / raw) To: gcc-bugs http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53117 Jakub Jelinek <jakub at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |jakub at gcc dot gnu.org --- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> 2012-04-25 14:25:51 UTC --- So, what are you proposing? Testing of flags after the subtraction from memory can't be used in the first case... ^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug target/53117] missed-optimization: worse code for 'x <= 0' compared to 'x < 0' 2012-04-25 14:21 [Bug rtl-optimization/53117] New: missed-optimization: worse code for 'x <= 0' compared to 'x < 0' vermaelen.wouter at gmail dot com 2012-04-25 14:26 ` [Bug rtl-optimization/53117] " jakub at gcc dot gnu.org @ 2012-04-25 14:28 ` rguenth at gcc dot gnu.org 2012-04-25 15:31 ` vermaelen.wouter at gmail dot com 2021-12-15 1:43 ` pinskia at gcc dot gnu.org 3 siblings, 0 replies; 5+ messages in thread From: rguenth at gcc dot gnu.org @ 2012-04-25 14:28 UTC (permalink / raw) To: gcc-bugs http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53117 Richard Guenther <rguenth at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Target| |x86_64-*-* Status|UNCONFIRMED |NEW Last reconfirmed| |2012-04-25 Component|rtl-optimization |target Ever Confirmed|0 |1 --- Comment #2 from Richard Guenther <rguenth at gcc dot gnu.org> 2012-04-25 14:28:09 UTC --- Confirmed. ^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug target/53117] missed-optimization: worse code for 'x <= 0' compared to 'x < 0' 2012-04-25 14:21 [Bug rtl-optimization/53117] New: missed-optimization: worse code for 'x <= 0' compared to 'x < 0' vermaelen.wouter at gmail dot com 2012-04-25 14:26 ` [Bug rtl-optimization/53117] " jakub at gcc dot gnu.org 2012-04-25 14:28 ` [Bug target/53117] " rguenth at gcc dot gnu.org @ 2012-04-25 15:31 ` vermaelen.wouter at gmail dot com 2021-12-15 1:43 ` pinskia at gcc dot gnu.org 3 siblings, 0 replies; 5+ messages in thread From: vermaelen.wouter at gmail dot com @ 2012-04-25 15:31 UTC (permalink / raw) To: gcc-bugs http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53117 --- Comment #3 from Wouter Vermaelen <vermaelen.wouter at gmail dot com> 2012-04-25 15:30:42 UTC --- @Jakub: At first I was puzzled by your comment. But after some investigation I found out that this 'optimization' is indeed not possible when the subtraction would underflow. So you can close this bug report as invalid. (OTOH signed overflow is anyway undefined behavior in C). ^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug target/53117] missed-optimization: worse code for 'x <= 0' compared to 'x < 0' 2012-04-25 14:21 [Bug rtl-optimization/53117] New: missed-optimization: worse code for 'x <= 0' compared to 'x < 0' vermaelen.wouter at gmail dot com ` (2 preceding siblings ...) 2012-04-25 15:31 ` vermaelen.wouter at gmail dot com @ 2021-12-15 1:43 ` pinskia at gcc dot gnu.org 3 siblings, 0 replies; 5+ messages in thread From: pinskia at gcc dot gnu.org @ 2021-12-15 1:43 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53117 Andrew Pinski <pinskia at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Severity|minor |enhancement ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2021-12-15 1:43 UTC | newest] Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2012-04-25 14:21 [Bug rtl-optimization/53117] New: missed-optimization: worse code for 'x <= 0' compared to 'x < 0' vermaelen.wouter at gmail dot com 2012-04-25 14:26 ` [Bug rtl-optimization/53117] " jakub at gcc dot gnu.org 2012-04-25 14:28 ` [Bug target/53117] " rguenth at gcc dot gnu.org 2012-04-25 15:31 ` vermaelen.wouter at gmail dot com 2021-12-15 1:43 ` pinskia 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).