public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jeff Law <law@redhat.com>
To: Xionghu Luo <luoxhu@linux.ibm.com>, "gcc@gcc.gnu.org" <gcc@gcc.gnu.org>
Cc: jakub@redhat.com, bonzini@gnu.org,
	segher Boessenkool <segher@kernel.crashing.org>,
	ebotcazou@gcc.gnu.org, abel@gcc.gnu.org
Subject: Re: CSE deletes valid REG_EQUAL?
Date: Thu, 12 Nov 2020 21:10:14 -0700	[thread overview]
Message-ID: <b0c3bed3-9f6e-4729-cb72-0ba81aa3810d@redhat.com> (raw)
In-Reply-To: <a0441a89-b7ac-7312-e38c-902c4de48308@linux.ibm.com>


On 11/12/20 7:02 PM, Xionghu Luo via Gcc wrote:
> Hi all,
>
> In PR51505(https://gcc.gnu.org/bugzilla/show_bug.cgi?id=51505), Paolo Bonzini 
> added the code to delete REG_EQUAL notes in df_remove_dead_eq_notes:
>
> gcc/df-problems.c:
> df_remove_dead_eq_notes (rtx_insn *insn, bitmap live)
> {
> ...
> 	case REG_EQUAL:
> 	case REG_EQUIV:
> 	  {
> 	    /* Remove the notes that refer to dead registers.  As we have at most
> 	       one REG_EQUAL/EQUIV note, all of EQ_USES will refer to this note
> 	       so we need to purge the complete EQ_USES vector when removing
> 	       the note using df_notes_rescan.  */
> 	    df_ref use;
> 	    bool deleted = false;
>
> 	    FOR_EACH_INSN_EQ_USE (use, insn)
> 	      if (DF_REF_REGNO (use) >= FIRST_PSEUDO_REGISTER
> 		  && DF_REF_LOC (use)
> 		  && (DF_REF_FLAGS (use) & DF_REF_IN_NOTE)
> 		  && !bitmap_bit_p (live, DF_REF_REGNO (use))
> 		  && loc_mentioned_in_p (DF_REF_LOC (use), XEXP (link, 0)))
> 		{
> 		  deleted = true;
> 		  break;
> 		}
> 	    if (deleted)
> 	      {
> 		rtx next;
> 		if (REG_DEAD_DEBUGGING)
> 		  df_print_note ("deleting: ", insn, link);
> 		next = XEXP (link, 1);
> 		free_EXPR_LIST_node (link);
> 		*pprev = link = next;
> 		df_notes_rescan (insn);
> 	      }
> ...
> }
>
>
> while I have a test case as below:
>
>
> typedef long myint_t;
> __attribute__ ((noinline)) myint_t
> hash_loop (myint_t nblocks, myint_t hash)
> {
>     int i;
>     for (i = 0; i < nblocks; i++)
>       hash = ((hash + 13) | hash) + 0x66546b64;
>     return hash;
> }
>
> before cse1:
>
>    22: L22:
>    16: NOTE_INSN_BASIC_BLOCK 4
>    17: r125:DI=r120:DI+0xd
>    18: r118:DI=r125:DI|r120:DI
>    19: r126:DI=r118:DI+0x66540000
>    20: r120:DI=r126:DI+0x6b64
>       REG_EQUAL r118:DI+0x66546b64
>    21: r119:DI=r119:DI-0x1
>    23: r127:CC=cmp(r119:DI,0)
>    24: pc={(r127:CC!=0)?L22:pc}
>       REG_BR_PROB 955630228
>
> The dump in cse1:
>
>    16: NOTE_INSN_BASIC_BLOCK 4
>    17: r125:DI=r120:DI+0xd
>    18: r118:DI=r125:DI|r120:DI
>       REG_DEAD r125:DI
>       REG_DEAD r120:DI
>    19: r126:DI=r118:DI+0x66540000
>       REG_DEAD r118:DI
>    20: r120:DI=r126:DI+0x6b64
>       REG_DEAD r126:DI
>    21: r119:DI=r119:DI-0x1
>    23: r127:CC=cmp(r119:DI,0)
>    24: pc={(r127:CC!=0)?L22:pc}
>       REG_DEAD r127:CC
>       REG_BR_PROB 955630228
>       ; pc falls through to BB 6
>
>
> The output shows "REQ_EQUAL r118:DI+0x66546b64" is deleted by df_remove_dead_eq_notes,
> but r120:DI is not REG_DEAD here, so is it correct here to check insn use and find that
> r118:DI is dead then do the delete?

It doesn't matter where the death occurs, any REG_DEAD note will cause
the REG_EQUAL note to be removed.  So given the death note for r118,
then any REG_EQUAL note that references r118 will be removed.  This is
overly pessimistic as the note may still be valid/useful at some
points.  See

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


Jeff


ps.  Note that a REG_EQUAL note is valid at a particular point in the IL
-- it is not a function-wide equivalence.  So you have to be careful
using such values as they can be invalidated by other statements. 
Contrast to a REG_EQUIV note where the equivalence is global and you
don't have to worry about invalidation.




  reply	other threads:[~2020-11-13  4:11 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-13  2:02 Xionghu Luo
2020-11-13  4:10 ` Jeff Law [this message]
2020-11-13 13:55   ` Segher Boessenkool
2020-11-17  1:12     ` Jeff Law
2020-11-17  8:57       ` Paolo Bonzini

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=b0c3bed3-9f6e-4729-cb72-0ba81aa3810d@redhat.com \
    --to=law@redhat.com \
    --cc=abel@gcc.gnu.org \
    --cc=bonzini@gnu.org \
    --cc=ebotcazou@gcc.gnu.org \
    --cc=gcc@gcc.gnu.org \
    --cc=jakub@redhat.com \
    --cc=luoxhu@linux.ibm.com \
    --cc=segher@kernel.crashing.org \
    /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).