public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/103457] New: boolean operations on bit-fields are not merged
@ 2021-11-28 19:58 roland.illig at gmx dot de
  2021-11-28 22:27 ` [Bug tree-optimization/103457] " pinskia at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: roland.illig at gmx dot de @ 2021-11-28 19:58 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 103457
           Summary: boolean operations on bit-fields are not merged
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: roland.illig at gmx dot de
  Target Milestone: ---

~~~c
#include <stdbool.h>

typedef struct GNodeFlagsS {
        bool remake:1;
        bool childMade:1;
        bool force:1;
        bool doneWait:1;
        bool doneOrder:1;
        bool fromDepend:1;
        bool doneAllsrc:1;
        bool cycle:1;
        bool doneCycle:1;
} GNodeFlags;

bool
GNodeFlags_IsNone(GNodeFlags flags)
{
        return !flags.remake
               && !flags.childMade
               && !flags.force
               && !flags.doneWait
               && !flags.doneOrder
               && !flags.fromDepend
               && !flags.doneAllsrc
               && !flags.cycle
               && !flags.doneCycle;
}
~~~

On x86_64, GCC 11.2 generates:

~~~asm
GNodeFlags_IsNone(GNodeFlagsS):
        mov     eax, edi
        and     eax, 1
        jne     .L6
        test    dil, 2
        jne     .L1
        mov     eax, edi
        shr     ax, 2
        and     eax, 1
        jne     .L6
        test    dil, 8
        jne     .L1
        mov     eax, edi
        shr     ax, 4
        and     eax, 1
        jne     .L6
        test    dil, 32
        jne     .L1
        mov     eax, edi
        shr     ax, 6
        and     eax, 1
        jne     .L6
        test    dil, dil
        js      .L1
        shr     di, 8
        mov     eax, edi
        and     eax, 1
        xor     eax, 1
        ret
.L6:
        xor     eax, eax
.L1:
        ret
~~~

ICC 2021.3.0 generates shorter code:

~~~asm
        test      edi, 1                                        #18.10
        jne       ..B1.10       # Prob 50%                      #18.10
        test      edi, 2                                        #19.13
        jne       ..B1.10       # Prob 50%                      #19.13
        test      edi, 4                                        #20.13
        jne       ..B1.10       # Prob 50%                      #20.13
(and so on)
~~~

Many other compilers fail to see the potential for optimizing this code as
well.

Clang is better, it generates:

~~~asm
GNodeFlags_IsNone(GNodeFlagsS):     # @GNodeFlags_IsNone(GNodeFlagsS)
        test    edi, 511
        sete    al
        ret
~~~

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

end of thread, other threads:[~2024-05-21  9:10 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-28 19:58 [Bug tree-optimization/103457] New: boolean operations on bit-fields are not merged roland.illig at gmx dot de
2021-11-28 22:27 ` [Bug tree-optimization/103457] " pinskia at gcc dot gnu.org
2021-11-28 23:20 ` roland.illig at gmx dot de
2021-11-29  8:52 ` marxin at gcc dot gnu.org
2023-04-26  6:55 ` rguenth at gcc dot gnu.org
2023-07-27  9:22 ` rguenth at gcc dot gnu.org
2024-05-21  9:10 ` jakub 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).