public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
To: Richard Biener <richard.guenther@gmail.com>
Cc: Aldy Hernandez <aldyh@redhat.com>, GCC patches <gcc-patches@gcc.gnu.org>
Subject: Re: redundant bitmap_bit_p followed by bitmap_clear_bit [was: Re: [COMMITTED] Kill second order relations in the path solver.]
Date: Tue, 02 Nov 2021 22:00:15 +0100	[thread overview]
Message-ID: <4CC62E82-7434-4229-8891-477B6988CC59@gmail.com> (raw)
In-Reply-To: <CAFiYyc0AgRw7qn0-BG7s0PE3cQfhtkawwR33U=Rsnu3gfgxNXA@mail.gmail.com>

On 2 November 2021 14:43:38 CET, Richard Biener <richard.guenther@gmail.com> wrote:
>On Mon, Nov 1, 2021 at 10:02 PM Bernhard Reutner-Fischer via
>Gcc-patches <gcc-patches@gcc.gnu.org> wrote:
>>
>> On Mon, 1 Nov 2021 15:21:03 +0100
>> Aldy Hernandez <aldyh@redhat.com> wrote:
>>
>> > I'm not convinced this makes the code clearer to read, especially if
>> > it's not on a critical path.  But if you feel strongly, please submit
>> > a patch ;-).
>>
>> No i don't feel strongly about it.
>> Compiling e.g. -O2 ira.o
>> # Overhead       Samples  Command  Shared Object  Symbol
>> # ........  ............  .......  .............  .........................
>> #
>>    100.00%          4197  cc1plus  cc1plus        [.] mark_reachable_blocks
>>    100.00%         22000  cc1plus  cc1plus        [.] path_oracle::killing_def
>> and the mark_elimination is reload.
>> So it's not just a handful of calls saved but some. And it would be
>> smaller code as it saves a call. Well maybe another day.
>
>Note that single bit set/clear are already implemented as test && set/clear.
>Note that unfortunately the sbitmap bitmap_set/clear_bit overloads do not
>return the previous state of the bit.  Maybe providing

All 3 spots here, dse, ira and killing_def do not look at the bit but use it as a bool, fwiw.
These 3 are the only users I (resp coccinelle) found who do the redundant bitmap_bit_p, bitmap_clear_bit.

>bitmap_test_and_set_bit () and bitmap_test_and_clear_bit () would be
>better (but note we currently return true when the bit changed, not when
>it was set).

A big portion of users of bitmap_bit_p could use a bitmap_bit_p that returns bool as is.
The rest would know the bit they asked for, no?
Hence bitmap_bit_p could be changed to return a bool rather easily. testb instead of testl on x86_64 fwiw.
thanks,

>
>Richard.
>
>> thanks,
>> >
>> > Aldy
>> >
>> > On Mon, Nov 1, 2021 at 3:10 PM Bernhard Reutner-Fischer
>> > <rep.dot.nop@gmail.com> wrote:
>> > >
>> > > On Thu, 28 Oct 2021 01:55:30 +0200
>> > > Bernhard Reutner-Fischer <rep.dot.nop@gmail.com> wrote:
>> > >
>> > > > On Wed, 27 Oct 2021 20:13:21 +0200
>> > > > Aldy Hernandez via Gcc-patches <gcc-patches@gcc.gnu.org> wrote:
>> > >
>> > > > > @@ -1306,6 +1307,24 @@ path_oracle::killing_def (tree ssa)
>> > > > >    ptr->m_next = m_equiv.m_next;
>> > > > >    m_equiv.m_next = ptr;
>> > > > >    bitmap_ior_into (m_equiv.m_names, b);
>> > > > > +
>> > > > > +  // Walk the relation list an remove SSA from any relations.
>> > > >
>> > > > s/an /and /
>> > > >
>> > > > > +  if (!bitmap_bit_p (m_relations.m_names, v))
>> > > > > +    return;
>> > > > > +
>> > > > > +  bitmap_clear_bit (m_relations.m_names, v);
>> > > >
>> > > > IIRC bitmap_clear_bit returns true if the bit was set, false otherwise,
>> > > > so should be used as if(!bitmap_clear_bit) above.
>> > >
>> > > > > +  relation_chain **prev = &(m_relations.m_head);
>> > > >
>> > > > s/[()]//
>> > > > thanks,
>> > >
>> > > There seems to be two other spots where a redundant bitmap_bit_p checks
>> > > if we want to bitmap_clear_bit. In dse and ira.
>> > > Like:
>> > > $ cat ~/coccinelle/gcc_bitmap_bit_p-0.cocci ; echo EOF
>> > > // replace redundant bitmap_bit_p() bitmap_clear_bit with the latter
>> > > @ rule1 @
>> > > identifier fn;
>> > > expression bitmap, bit;
>> > > @@
>> > >
>> > > fn(...) {
>> > > <...
>> > > (
>> > > -if (bitmap_bit_p (bitmap, bit))
>> > > +if (bitmap_clear_bit (bitmap, bit))
>> > > {
>> > >   ...
>> > > -  bitmap_clear_bit (bitmap, bit);
>> > >   ...
>> > > }
>> > > |
>> > > -if (bitmap_bit_p (bitmap, bit))
>> > > +if (bitmap_clear_bit (bitmap, bit))
>> > > {
>> > >   ...
>> > > }
>> > > ...
>> > > -bitmap_clear_bit (bitmap, bit);
>> > > )
>> > > ...>
>> > > }
>> > > EOF
>> > > $ find gcc/ -type f -a \( -name "*.c" -o -name "*.cc" \) -a \( ! -path "gcc/testsuite/*" -a ! -path "gcc/contrib/*" \) -exec spatch -sp_file ~/coccinelle/gcc_bitmap_bit_p-0.cocci --show-diff {} \;
>> > > diff =
>> > > --- gcc/dse.c
>> > > +++ /tmp/cocci-output-1104419-443759-dse.c
>> > > @@ -3238,9 +3238,8 @@ mark_reachable_blocks (sbitmap unreachab
>> > >    edge e;
>> > >    edge_iterator ei;
>> > >
>> > > -  if (bitmap_bit_p (unreachable_blocks, bb->index))
>> > > +  if (bitmap_clear_bit(unreachable_blocks, bb->index))
>> > >      {
>> > > -      bitmap_clear_bit (unreachable_blocks, bb->index);
>> > >        FOR_EACH_EDGE (e, ei, bb->preds)
>> > >         {
>> > >           mark_reachable_blocks (unreachable_blocks, e->src);
>> > > diff =
>> > > --- gcc/ira.c
>> > > +++ /tmp/cocci-output-1104678-d8679a-ira.c
>> > > @@ -2944,17 +2944,15 @@ mark_elimination (int from, int to)
>> > >    FOR_EACH_BB_FN (bb, cfun)
>> > >      {
>> > >        r = DF_LR_IN (bb);
>> > > -      if (bitmap_bit_p (r, from))
>> > > +      if (bitmap_clear_bit(r, from))
>> > >         {
>> > > -         bitmap_clear_bit (r, from);
>> > >           bitmap_set_bit (r, to);
>> > >         }
>> > >        if (! df_live)
>> > >          continue;
>> > >        r = DF_LIVE_IN (bb);
>> > > -      if (bitmap_bit_p (r, from))
>> > > +      if (bitmap_clear_bit(r, from))
>> > >         {
>> > > -         bitmap_clear_bit (r, from);
>> > >           bitmap_set_bit (r, to);
>> > >         }
>> > >      }
>> > > # in ira.c one would have to fixup the curly braces manually
>> > > PS: coccinelle seems to ruin the spaces before braces in the '+' even
>> > > though i have written them correctly according to GNU style..
>> > >
>> >
>>


  parent reply	other threads:[~2021-11-02 21:00 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-27 18:13 [COMMITTED] Kill second order relations in the path solver Aldy Hernandez
2021-10-27 18:13 ` [COMMITTED] Reorder relation calculating code " Aldy Hernandez
2021-10-27 18:13 ` [COMMITTED] Kill known equivalences before a new assignment " Aldy Hernandez
2021-10-27 23:55 ` [COMMITTED] Kill second order relations " Bernhard Reutner-Fischer
2021-11-01 14:10   ` redundant bitmap_bit_p followed by bitmap_clear_bit [was: Re: [COMMITTED] Kill second order relations in the path solver.] Bernhard Reutner-Fischer
2021-11-01 14:21     ` Aldy Hernandez
2021-11-01 21:02       ` Bernhard Reutner-Fischer
2021-11-02 13:43         ` Richard Biener
2021-11-02 18:01           ` Richard Sandiford
2021-11-02 21:00           ` Bernhard Reutner-Fischer [this message]
2021-11-03  8:01             ` Richard Biener

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4CC62E82-7434-4229-8891-477B6988CC59@gmail.com \
    --to=rep.dot.nop@gmail.com \
    --cc=aldyh@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=richard.guenther@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).