public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug rtl-optimization/58195] New: Missed optimization opportunity when returning a conditional
@ 2013-08-19 19:24 warp at iki dot fi
  2014-03-11 13:28 ` [Bug rtl-optimization/58195] " bisqwit at iki dot fi
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: warp at iki dot fi @ 2013-08-19 19:24 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 58195
           Summary: Missed optimization opportunity when returning a
                    conditional
           Product: gcc
           Version: 4.7.2
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: rtl-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: warp at iki dot fi

When compiling the following function:

int a(int input)
{
    return input == 0 ? 0 : -input;
}

gcc is unable to see that the conditional and returning 0 can be optimized
away, producing:

        movl    %edi, %edx
        xorl    %eax, %eax
        negl    %edx
        testl   %edi, %edi
        cmovne  %edx, %eax
        ret

For the record, I found out the above when I was testing what gcc would do with
this function:

int a(int input)
{
    int value = 0;
    for(int n = input; n != 0; ++n)
        ++value;
    return value;
}

gcc is able to optimize that into the same asm code as above, but no further
(not even if the conditional is written explicitly, as written in the first
function above.)


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

end of thread, other threads:[~2022-11-19 23:24 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-08-19 19:24 [Bug rtl-optimization/58195] New: Missed optimization opportunity when returning a conditional warp at iki dot fi
2014-03-11 13:28 ` [Bug rtl-optimization/58195] " bisqwit at iki dot fi
2014-03-11 13:32 ` [Bug tree-optimization/58195] " rguenth at gcc dot gnu.org
2014-03-11 13:44 ` glisse at gcc dot gnu.org
2020-04-10  9:24 ` bisqwit at iki dot fi
2021-05-24  7:14 ` pinskia at gcc dot gnu.org
2021-06-05  1:28 ` pinskia at gcc dot gnu.org
2021-11-17  9:56 ` pinskia at gcc dot gnu.org
2022-11-19 23:24 ` 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).