public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/15826] New: don't use "if" to extract a single bit bit-field.
@ 2004-06-04 18:55 kazu at cs dot umass dot edu
  2004-06-04 19:07 ` [Bug tree-optimization/15826] " pinskia at gcc dot gnu dot org
                   ` (5 more replies)
  0 siblings, 6 replies; 14+ messages in thread
From: kazu at cs dot umass dot edu @ 2004-06-04 18:55 UTC (permalink / raw)
  To: gcc-bugs

Transform foo() into bar().

struct s {
  unsigned int bit : 1;
};

unsigned int
foo (struct s *p)
{
  if (p->bit)
    return 1;
  else
    return 0;
}

unsigned int
bar (struct s *p)
{
  return (unsigned int) (p->bit);
}

Currently, the last tree-ssa form I get looks like so:

;; Function foo (foo)

foo (p)
{
  int T.1;
  unsigned int T.0;

<bb 0>:
  T.0_2 = p_1->bit;
  if (T.0_2 != 0) goto <L0>; else goto <L1>;

<L0>:;
  return 1;

<L1>:;
  return 0;

}



;; Function bar (bar)

bar (p)
{
<bb 0>:
  return p_1->bit;

}

The assembly code:

        .p2align 2,,3
.globl foo
        .type   foo, @function
foo:
        testb   $1, (%eax)      # 43    *testqi_1/3     [length = 3]
        setne   %al     # 40    *setcc_1        [length = 3]
        movzbl  %al, %eax       # 45    *zero_extendqisi2_movzbw        [length
= 3]
        ret     # 48    return_internal [length = 1]
        .size   foo, .-foo
        .p2align 2,,3
.globl bar
        .type   bar, @function
bar:
        movzbl  (%eax), %eax    # 28    *zero_extendqisi2_movzbw        [length
= 3]
        andl    $1, %eax        # 12    *andsi_1/1      [length = 3]
        ret     # 31    return_internal [length = 1]
        .size   bar, .-bar

Note that alias.i.t50.tailc contains:

<L22>:;
  T.1776_58 = x_2->unchanging;
  if (T.1776_58 != 0) goto <L25>; else goto <L26>;

<L25>:;
  return 0;

<L26>:;
  return 1;

-- 
           Summary: don't use "if" to extract a single bit bit-field.
           Product: gcc
           Version: 3.5.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: enhancement
          Priority: P2
         Component: tree-optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: kazu at cs dot umass dot edu
                CC: gcc-bugs at gcc dot gnu dot org


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


^ permalink raw reply	[flat|nested] 14+ messages in thread
[parent not found: <bug-15826-5009@http.gcc.gnu.org/bugzilla/>]
[parent not found: <bug-15826-4@http.gcc.gnu.org/bugzilla/>]

end of thread, other threads:[~2020-04-19 18:28 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-06-04 18:55 [Bug tree-optimization/15826] New: don't use "if" to extract a single bit bit-field kazu at cs dot umass dot edu
2004-06-04 19:07 ` [Bug tree-optimization/15826] " pinskia at gcc dot gnu dot org
2004-06-04 19:26 ` pinskia at gcc dot gnu dot org
2004-06-07 17:59 ` pinskia at gcc dot gnu dot org
2004-06-07 18:05 ` pinskia at gcc dot gnu dot org
2004-06-16  6:21 ` kazu at cs dot umass dot edu
2005-05-04  1:52 ` pinskia at gcc dot gnu dot org
     [not found] <bug-15826-5009@http.gcc.gnu.org/bugzilla/>
2006-03-02 14:24 ` pinskia at gcc dot gnu dot org
2007-04-05 21:01 ` steven at gcc dot gnu dot org
2008-04-30 19:22 ` rguenth at gcc dot gnu dot org
     [not found] <bug-15826-4@http.gcc.gnu.org/bugzilla/>
2012-01-24  0:55 ` pinskia at gcc dot gnu.org
2014-10-31  4:01 ` pinskia at gcc dot gnu.org
2014-12-01 14:07 ` rguenth at gcc dot gnu.org
2020-04-19 18:28 ` law 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).