public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/15826] don't use "if" to extract a single bit bit-field.
       [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
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu.org @ 2012-01-24  0:55 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|gcc-bugs at gcc dot gnu.org |

--- Comment #8 from Andrew Pinski <pinskia at gcc dot gnu.org> 2012-01-24 00:03:45 UTC ---
(In reply to comment #6)
Only comment #6 remains to be fixed.  
FRE does not recognize p->bit as "BIT_FIELD_REF <*p, 8, 0> & 1".


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

* [Bug tree-optimization/15826] don't use "if" to extract a single bit bit-field.
       [not found] <bug-15826-4@http.gcc.gnu.org/bugzilla/>
  2012-01-24  0:55 ` [Bug tree-optimization/15826] don't use "if" to extract a single bit bit-field 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
  3 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu.org @ 2014-10-31  4:01 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=15826
Bug 15826 depends on bug 15459, which changed state.

Bug 15459 Summary: [meta-bug] there should be a tree combiner like the rtl one
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=15459

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |FIXED


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

* [Bug tree-optimization/15826] don't use "if" to extract a single bit bit-field.
       [not found] <bug-15826-4@http.gcc.gnu.org/bugzilla/>
  2012-01-24  0:55 ` [Bug tree-optimization/15826] don't use "if" to extract a single bit bit-field 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
  3 siblings, 0 replies; 13+ messages in thread
From: rguenth at gcc dot gnu.org @ 2014-12-01 14:07 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #9 from Richard Biener <rguenth at gcc dot gnu.org> ---
Which boils down to the premature fold-const.c:optimize_bit_field_compare
which creates this BIT_FIELD_REF (fold_truth_andor_1 does similar stupid
stuff).


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

* [Bug tree-optimization/15826] don't use "if" to extract a single bit bit-field.
       [not found] <bug-15826-4@http.gcc.gnu.org/bugzilla/>
                   ` (2 preceding siblings ...)
  2014-12-01 14:07 ` rguenth at gcc dot gnu.org
@ 2020-04-19 18:28 ` law at redhat dot com
  3 siblings, 0 replies; 13+ messages in thread
From: law at redhat dot com @ 2020-04-19 18:28 UTC (permalink / raw)
  To: gcc-bugs

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

Jeffrey A. Law <law at redhat dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |law at redhat dot com
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=81601
         Resolution|---                         |FIXED

--- Comment #19 from Jeffrey A. Law <law at redhat dot com> ---
So the core issue here, using an if, conditional moves and the like to do
single bit field extraction/testing is resolved.

There is still an issue of canonicalizing the two representations which in turn
opens up the possibility of finding more common subexpressions when both forms
might be used.  That is actually being tracked via pr81601.

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

* [Bug tree-optimization/15826] don't use "if" to extract a single bit bit-field.
       [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
  2 siblings, 0 replies; 13+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2008-04-30 19:22 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from rguenth at gcc dot gnu dot org  2008-04-30 19:21 -------
On the trunk I have after phiopt1:

;; Function andrew (andrew)

Removing basic block 3
Merging blocks 2 and 4
andrew (struct s * p)
{
  _Bool D.1212;
  int i;
  unsigned int D.1183;
  <unnamed-unsigned:1> D.1182;

<bb 2>:
  D.1182_3 = p_2(D)->bit;
  (void) 0;
  D.1212_9 = D.1182_3 != 0;
  i_10 = (int) D.1212_9;
  D.1183_6 = (unsigned int) i_10;
  return D.1183_6;

}

;; Function foo (foo)

Removing basic block 3
Merging blocks 2 and 4
foo (struct s * p)
{
  _Bool D.1199;
  unsigned int D.1177;
  <unnamed-unsigned:1> D.1176;

<bb 2>:
  D.1176_3 = p_2(D)->bit;
  (void) 0;
  D.1199_8 = D.1176_3 != 0;
  D.1177_9 = (unsigned int) D.1199_8;
  return D.1177_9;

}

which the next forwprop pass optimizes to

foo (struct s * p)
{
  unsigned int D.1177;
  <unnamed-unsigned:1> D.1176;

<bb 2>:
  D.1176_3 = p_2(D)->bit;
  D.1177_9 = D.1176_3 != 0;
  return D.1177_9;

}

andrew (struct s * p)
{
  unsigned int D.1183;
  <unnamed-unsigned:1> D.1182;

<bb 2>:
  D.1182_3 = p_2(D)->bit;
  D.1183_6 = D.1182_3 != 0;
  return D.1183_6;

}


-- 


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


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

* [Bug tree-optimization/15826] don't use "if" to extract a single bit bit-field.
       [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
  2 siblings, 0 replies; 13+ messages in thread
From: steven at gcc dot gnu dot org @ 2007-04-05 21:01 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from steven at gcc dot gnu dot org  2007-04-05 22:01 -------
The tree dump for the original test case now looks like this for me:

;; Function foo (foo)

foo (p)
{
<bb 2>:
  return (unsigned int) ((BIT_FIELD_REF <*p, 8, 0> & 1) != 0);

}



;; Function bar (bar)

bar (p)
{
<bb 2>:
  return (unsigned int) p->bit;

}



The resulting assembler output is the same, but I imagine VRP should be able to
fold away the "& 1" test.  I don't know if the BIT_FIELD_REF itself should be
optimized away, but I guess so.  Consider the following test case:

struct s
{
  unsigned int bit:1;
};

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


This gets "optimized" at the tree level to this ugly code:
;; Function foo (foo)

foo (p)
{
  unsigned int D.1979;

<bb 2>:
  if ((BIT_FIELD_REF <*p, 8, 0> & 1) != 0) goto <L0>; else goto <L4>;

<L4>:;
  D.1979 = 0;
  goto <bb 5> (<L2>);

<L0>:;
  D.1979 = (unsigned int) p->bit;

<L2>:;
  return D.1979;

}

In summary, I don't think we can close this bug just yet.


-- 

steven at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|2005-12-10 04:15:46         |2007-04-05 22:01:25
               date|                            |


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


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

* [Bug tree-optimization/15826] don't use "if" to extract a single bit bit-field.
       [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
  2 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-03-02 14:24 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from pinskia at gcc dot gnu dot org  2006-03-02 14:24 -------
This is interesting, we now get BIT_FIELD_REF.


-- 


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


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

* [Bug tree-optimization/15826] don't use "if" to extract a single bit bit-field.
  2004-06-04 18:55 [Bug tree-optimization/15826] New: " kazu at cs dot umass dot edu
                   ` (4 preceding siblings ...)
  2004-06-16  6:21 ` kazu at cs dot umass dot edu
@ 2005-05-04  1:52 ` pinskia at gcc dot gnu dot org
  5 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-05-04  1:52 UTC (permalink / raw)
  To: gcc-bugs



-- 
Bug 15826 depends on bug 15618, which changed state.

Bug 15618 Summary: Missed bool optimization
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15618

           What    |Old Value                   |New Value
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED

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


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

* [Bug tree-optimization/15826] don't use "if" to extract a single bit bit-field.
  2004-06-04 18:55 [Bug tree-optimization/15826] New: " kazu at cs dot umass dot edu
                   ` (3 preceding siblings ...)
  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
  5 siblings, 0 replies; 13+ messages in thread
From: kazu at cs dot umass dot edu @ 2004-06-16  6:21 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From kazu at cs dot umass dot edu  2004-06-16 06:20 -------
Now that we have a single return statement, let me regenerate t50.tailc.

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);
}

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

I get:

;; Function foo (foo)

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

<bb 0>:
  T.0_3 = p_2->bit;
  T.7_8 = T.0_3 != 0;
  T.2_1 = (unsigned int)T.7_8;
  return T.2_1;

}



;; Function bar (bar)

bar (p)
{
  unsigned int T.3;

<bb 0>:
  T.3_2 = p_1->bit;
  return T.3_2;

}



;; Function andrew (andrew)

andrew (p)
{
  _Bool T.16;
  int i;
  unsigned int T.6;
  int T.5;
  unsigned int T.4;

<bb 0>:
  T.4_3 = p_2->bit;
  T.16_9 = T.4_3 != 0;
  i_1 = (int)T.16_9;
  T.6_5 = (unsigned int)i_1;
  return T.6_5;

}

So basically, the problems boils down to the tree combiner.


-- 


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


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

* [Bug tree-optimization/15826] don't use "if" to extract a single bit bit-field.
  2004-06-04 18:55 [Bug tree-optimization/15826] New: " kazu at cs dot umass dot edu
                   ` (2 preceding siblings ...)
  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
  5 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-06-07 18:05 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-06-07 18:05 -------
I should note now that PR 15268 is fixed, the only thing that is needed is for one-wide-bitfield != 0 
needs to be converted to (_Bool)one-wide-bitfield.

-- 


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


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

* [Bug tree-optimization/15826] don't use "if" to extract a single bit bit-field.
  2004-06-04 18:55 [Bug tree-optimization/15826] New: " 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
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-06-07 17:59 UTC (permalink / raw)
  To: gcc-bugs



-- 
Bug 15826 depends on bug 15268, which changed state.

Bug 15268 Summary: [tree-ssa] return statements are not combined on the tree level
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15268

           What    |Old Value                   |New Value
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED

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


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

* [Bug tree-optimization/15826] don't use "if" to extract a single bit bit-field.
  2004-06-04 18:55 [Bug tree-optimization/15826] New: " 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
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-06-04 19:26 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-06-04 19:26 -------
Here is another example:
struct s {
  unsigned int bit : 1;
};

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

I will note that the example in comment #1 needs to have the return values merged together before the 
real optimization happens (see PR 15268 and a patch which I posted but have not gotten around to 
answering/tying  RTH's question/seguestion yet).

But basically it can be optimization by putting a cast to bool first so a != 0 becomes (bool)a and PHI-
opt already optimizated out the branches.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
  BugsThisDependsOn|                            |15268


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


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

* [Bug tree-optimization/15826] don't use "if" to extract a single bit bit-field.
  2004-06-04 18:55 [Bug tree-optimization/15826] New: " kazu at cs dot umass dot edu
@ 2004-06-04 19:07 ` pinskia at gcc dot gnu dot org
  2004-06-04 19:26 ` pinskia at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-06-04 19:07 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-06-04 19:07 -------
Confirmed, this is related to bug 15618 which is for bools.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
  BugsThisDependsOn|                            |15618
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|                            |1
   Last reconfirmed|0000-00-00 00:00:00         |2004-06-04 19:07:43
               date|                            |


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


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

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

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-15826-4@http.gcc.gnu.org/bugzilla/>
2012-01-24  0:55 ` [Bug tree-optimization/15826] don't use "if" to extract a single bit bit-field 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
     [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
2004-06-04 18:55 [Bug tree-optimization/15826] New: " 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

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