public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/105276] New: [12 Regression]  executed once loop not optimized anymore
@ 2022-04-14 13:47 denis.campredon at gmail dot com
  2022-04-19  8:29 ` [Bug tree-optimization/105276] " rguenth at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: denis.campredon at gmail dot com @ 2022-04-14 13:47 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105276

            Bug ID: 105276
           Summary: [12 Regression]  executed once loop not optimized
                    anymore
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: denis.campredon at gmail dot com
  Target Milestone: ---

bool foo(unsigned i) {
    bool result = true;
    while (i) {
        i = i % 3;
        i = i - (i==2 ? 2 : i ? 1 : 0);
        result = !result;
    }
    return result;
}
--------------
compiled with g++ 11.2 and -O2 it produces:

-----------------
foo(unsigned int):
        test    edi, edi
        sete    al
        ret
----------------

With current trunk and -02 lots of instructions are generated, the loop is
still present, about 30 instructions are produced.


Also, when compiled with -Os trunk produces loopless assembly:
------------------
foo(unsigned int):
        mov     dl, 1
        test    edi, edi
        je      .L1
        xor     edx, edx
.L1:
        mov     eax, edx
        ret
-------------------
Whereas using -Os and g++ 11.2 it uses one less register:
------------------
foo(unsigned int):
        mov     al, 1
        test    edi, edi
        je      .L4
        xor     eax, eax
.L4:
        ret

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

end of thread, other threads:[~2022-04-25 14:27 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-14 13:47 [Bug c/105276] New: [12 Regression] executed once loop not optimized anymore denis.campredon at gmail dot com
2022-04-19  8:29 ` [Bug tree-optimization/105276] " rguenth at gcc dot gnu.org
2022-04-20 15:38 ` jakub at gcc dot gnu.org
2022-04-21 15:46 ` amacleod at redhat dot com
2022-04-25 13:59 ` cvs-commit at gcc dot gnu.org
2022-04-25 14:27 ` amacleod at redhat dot com

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).