public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "tobi at gcc dot gnu dot org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/24568] New: Missed optimization: trivialization of silly code Date: Fri, 28 Oct 2005 16:15:00 -0000 [thread overview] Message-ID: <bug-24568-8513@http.gcc.gnu.org/bugzilla/> (raw) xgcc (GCC) 4.1.0 20051020 (experimental) can't optimize the following code (from <http://thedailywtf.com>): int convertToMinutes(long milliDiff) { int negative = 0; int minutesDiff = -1; if (milliDiff < 0) { negative = 1; milliDiff = -milliDiff; // Make positive (is easier) } if (milliDiff == 0) // Watch out for exceptional value 0 minutesDiff = 0; else minutesDiff = (int) (milliDiff / 1000) / 60; if (negative) minutesDiff = -minutesDiff; // Make it negative again return minutesDiff; } The code should simplify to int convertToMinutes (long i) { return i / 60000; } But the final tree dump contains the complete logic even in the case of high optimization levels. An interesting peculiarity from the assembly: .file "milli.c" .text .p2align 4,,15 .globl convertToMinutes .type convertToMinutes, @function convertToMinutes: pushl %ebp movl %esp, %ebp subl $8, %esp movl %esi, 4(%esp) movl 8(%ebp), %esi movl %ebx, (%esp) xorl %ebx, %ebx testl %esi, %esi js .L12 ;;;;; jump from here .L4: xorl %ecx, %ecx testl %esi, %esi je .L7 movl $1172812403, %eax imull %esi movl %esi, %eax sarl $31, %eax movl %edx, %ecx sarl $14, %ecx subl %eax, %ecx .L7: testl %ebx, %ebx je .L8 negl %ecx .L8: movl (%esp), %ebx movl %ecx, %eax movl 4(%esp), %esi movl %ebp, %esp popl %ebp ret .p2align 4,,7 .L12: ;;;;;;;;;;; all the way down here, probably out of the prefetch buffer negl %esi movl $1, %ebx jmp .L4 .size convertToMinutes, .-convertToMinutes .ident "GCC: (GNU) 4.1.0 20051020 (experimental)" .section .note.GNU-stack,"",@progbits -- Summary: Missed optimization: trivialization of silly code Product: gcc Version: 4.1.0 Status: UNCONFIRMED Keywords: missed-optimization Severity: normal Priority: P2 Component: tree-optimization AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: tobi at gcc dot gnu dot org GCC target triplet: i686-pc-linux http://gcc.gnu.org/bugzilla/show_bug.cgi?id=24568
next reply other threads:[~2005-10-28 16:15 UTC|newest] Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top 2005-10-28 16:15 tobi at gcc dot gnu dot org [this message] 2005-10-28 18:01 ` [Bug tree-optimization/24568] " pinskia at gcc dot gnu dot org 2005-10-28 18:06 ` pinskia at gcc dot gnu dot org 2005-10-28 18:10 ` pinskia at gcc dot gnu dot org 2005-10-28 18:11 ` pinskia at gcc dot gnu dot org 2005-10-28 18:15 ` pinskia at gcc dot gnu dot org 2005-10-28 18:18 ` pinskia at gcc dot gnu dot org 2005-10-28 18:20 ` [Bug tree-optimization/24568] [meta-bugs] " pinskia at gcc dot gnu dot org 2005-10-28 18:21 ` pinskia at gcc dot gnu dot org 2007-03-29 12:29 ` [Bug tree-optimization/24568] [meta-bug] " steven at gcc dot gnu dot org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-24568-8513@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).