[Bug c++/54011] New: missed optimization opportunities for bool struct/class members

plasmahh at gmx dot net gcc-bugzilla@gcc.gnu.org
Wed Jul 18 09:27:00 GMT 2012


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

             Bug #: 54011
           Summary: missed optimization opportunities for bool
                    struct/class members
    Classification: Unclassified
           Product: gcc
           Version: 4.7.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: plasmahh@gmx.net


Hi, when taking the following code (or on http://tinyurl.com/bs2qa3h to easier
play with (leads to gcc explorer, might of course be inactive after some time))

#define BSET //:1
struct A
{
  bool b0 BSET;
  bool b1 BSET;
  bool b2 BSET;
  bool b3 BSET;
  bool b4 BSET;
  bool b5 BSET;
  bool b6 BSET;
  bool b7 BSET;
};
  //#define TO (__LINE__%2)
  #define TO 0
 void foo( A& a )
  {
    a.b0 = TO;
    a.b1 = TO;
    a.b2 = TO;
    a.b3 = TO;
   #if 1
    a.b4 = TO;
    a.b5 = TO;
    a.b6 = TO;
    a.b7 = TO;
    #endif
  }

I see some missed opportunities for optimization. While clang compiles this to:

    movq    $0, (%rdi)
    ret

gcc will compile this to:

    movb    $0, (%rdi)
    movb    $0, 1(%rdi)
    movb    $0, 2(%rdi)
    movb    $0, 3(%rdi)
    movb    $0, 4(%rdi)
    movb    $0, 5(%rdi)
    movb    $0, 6(%rdi)
    movb    $0, 7(%rdi)
    ret

What I think a good debugger should do is:

In case of bool being one byte, determine the longest "chain" of values being
set, group them into useful operation sizes (2/4/8/16 bytes maybe) and create
an appropriate value to store to that location. In the case of the bools being
bitset members (above BSET define to try it out) gcc already seems to do this
quite fine (things will get the appropriate and/or bitwise operations applied).



More information about the Gcc-bugs mailing list