public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/99918] New: suboptimal code for bool bitfield tests
@ 2021-04-05 20:15 msebor at gcc dot gnu.org
  2021-04-05 20:22 ` [Bug tree-optimization/99918] " pinskia at gcc dot gnu.org
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: msebor at gcc dot gnu.org @ 2021-04-05 20:15 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 99918
           Summary: suboptimal code for bool bitfield tests
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

GCC does a better job folding operations involving plain Booleans than it does
with bool bit-fields.  The example below shows that in f() the return statement
is folded to zero while in g() it's not.  This is behind a class of
-Wmaybe-uninitialized warnings.

$ cat z.c && gcc -O2 -S -Wall -fdump-tree-optimized=/dev/stdout z.c
struct A { _Bool i, j; };

_Bool f (struct A a)
{
  if (a.i)
    a.j = 0;
  else
    a.j = a.i;

  return a.j;    // folded to 0
}

struct B { _Bool i: 1, j: 1; };

_Bool g (struct B b)
{
  if (b.i)
    b.j = 0;
  else
    b.j = b.i;

  return b.j;    // not folded
}


;; Function f (f, funcdef_no=0, decl_uid=1946, cgraph_uid=1, symbol_order=0)

_Bool f (struct A a)
{
  <bb 2> [local count: 1073741824]:
  return 0;

}



;; Function g (g, funcdef_no=1, decl_uid=1953, cgraph_uid=2, symbol_order=1)

Removing basic block 5
_Bool g (struct B b)
{
  _Bool b$j;
  unsigned char _1;
  unsigned char _2;
  _Bool _3;

  <bb 2> [local count: 1073741824]:
  _1 = VIEW_CONVERT_EXPR<unsigned char>(b);
  _2 = _1 & 1;
  if (_2 != 0)
    goto <bb 4>; [50.00%]
  else
    goto <bb 3>; [50.00%]

  <bb 3> [local count: 536870913]:
  _3 = b.i;

  <bb 4> [local count: 1073741824]:
  # b$j_5 = PHI <0(2), _3(3)>
  return b$j_5;

}

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

end of thread, other threads:[~2023-07-12 22:05 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-05 20:15 [Bug tree-optimization/99918] New: suboptimal code for bool bitfield tests msebor at gcc dot gnu.org
2021-04-05 20:22 ` [Bug tree-optimization/99918] " pinskia at gcc dot gnu.org
2021-04-05 20:23 ` [Bug tree-optimization/99918] [9/10/11 Regression] " msebor at gcc dot gnu.org
2021-04-05 20:27 ` msebor at gcc dot gnu.org
2021-04-05 20:40 ` msebor at gcc dot gnu.org
2021-04-06  8:39 ` rguenth at gcc dot gnu.org
2021-04-08 14:22 ` rguenth at gcc dot gnu.org
2021-06-01  8:20 ` [Bug tree-optimization/99918] [9/10/11/12 " rguenth at gcc dot gnu.org
2022-05-27  9:44 ` [Bug tree-optimization/99918] [10/11/12/13 " rguenth at gcc dot gnu.org
2022-06-28 10:44 ` jakub at gcc dot gnu.org
2022-07-01 12:49 ` fkorta at gmail dot com
2023-07-07 10:39 ` [Bug tree-optimization/99918] [11/12/13/14 " rguenth at gcc dot gnu.org
2023-07-12 22:05 ` 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).