public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Kewen.Lin" <linkw@linux.ibm.com>
To: Richard Biener <richard.guenther@gmail.com>
Cc: Alexander Monakov <amonakov@ispras.ru>,
	Jeff Law <jeffreyalaw@gmail.com>,
	Maxim Kuvyrkov <maxim.kuvyrkov@linaro.org>,
	GCC Patches <gcc-patches@gcc.gnu.org>,
	Richard Sandiford <richard.sandiford@arm.com>,
	Jeff Law <jlaw@ventanamicro.com>,
	Vladimir Makarov <vmakarov@redhat.com>,
	zhroma@ispras.ru, Andrey Belevantsev <abel@ispras.ru>,
	Segher Boessenkool <segher@kernel.crashing.org>,
	Peter Bergner <bergner@linux.ibm.com>,
	Michael Meissner <meissner@linux.ibm.com>,
	Alexandre Oliva <oliva@adacore.com>
Subject: Re: PING^1 [PATCH v3] sched: Change no_real_insns_p to no_real_nondebug_insns_p [PR108273]
Date: Thu, 23 Nov 2023 17:09:03 +0800	[thread overview]
Message-ID: <fab8b5ba-43df-70ec-5646-f60cbd3811eb@linux.ibm.com> (raw)
In-Reply-To: <CAFiYyc0hQu0CyvpOnzyQvFAMaQYAm+Zi_=5txLXLkUirdbWBwg@mail.gmail.com>

on 2023/11/23 16:20, Richard Biener wrote:
> On Thu, Nov 23, 2023 at 4:02 AM Kewen.Lin <linkw@linux.ibm.com> wrote:
>>
>> on 2023/11/22 18:25, Richard Biener wrote:
>>> On Wed, Nov 22, 2023 at 10:31 AM Kewen.Lin <linkw@linux.ibm.com> wrote:
>>>>
>>>> on 2023/11/17 20:55, Alexander Monakov wrote:
>>>>>
>>>>> On Fri, 17 Nov 2023, Kewen.Lin wrote:
>>>>>>> I don't think you can run cleanup_cfg after sched_init. I would suggest
>>>>>>> to put it early in schedule_insns.
>>>>>>
>>>>>> Thanks for the suggestion, I placed it at the beginning of haifa_sched_init
>>>>>> instead, since schedule_insns invokes haifa_sched_init, although the
>>>>>> calls rgn_setup_common_sched_info and rgn_setup_sched_infos are executed
>>>>>> ahead but they are all "setup" functions, shouldn't affect or be affected
>>>>>> by this placement.
>>>>>
>>>>> I was worried because sched_init invokes df_analyze, and I'm not sure if
>>>>> cfg_cleanup can invalidate it.
>>>>
>>>> Thanks for further explaining!  By scanning cleanup_cfg, it seems that it
>>>> considers df, like compact_blocks checks df, try_optimize_cfg invokes
>>>> df_analyze etc., but I agree that moving cleanup_cfg before sched_init
>>>> makes more sense.
>>>>
>>>>>
>>>>>>> I suspect this may be caused by invoking cleanup_cfg too late.
>>>>>>
>>>>>> By looking into some failures, I found that although cleanup_cfg is executed
>>>>>> there would be still some empty blocks left, by analyzing a few failures there
>>>>>> are at least such cases:
>>>>>>   1. empty function body
>>>>>>   2. block holding a label for return.
>>>>>>   3. block without any successor.
>>>>>>   4. block which becomes empty after scheduling some other block.
>>>>>>   5. block which looks mergeable with its always successor but left.
>>>>>>   ...
>>>>>>
>>>>>> For 1,2, there is one single successor EXIT block, I think they don't affect
>>>>>> state transition, for 3, it's the same.  For 4, it depends on if we can have
>>>>>> the assumption this kind of empty block doesn't have the chance to have debug
>>>>>> insn (like associated debug insn should be moved along), I'm not sure.  For 5,
>>>>>> a reduced test case is:
>>>>>
>>>>> Oh, I should have thought of cases like these, really sorry about the slip
>>>>> of attention, and thanks for showing a testcase for item 5. As Richard as
>>>>> saying in his response, cfg_cleanup cannot be a fix here. The thing to check
>>>>> would be changing no_real_insns_p to always return false, and see if the
>>>>> situation looks recoverable (if it breaks bootstrap, regtest statistics of
>>>>> a non-bootstrapped compiler are still informative).
>>>>
>>>> As you suggested, I forced no_real_insns_p to return false all the time, some
>>>> issues got exposed, almost all of them are asserting NOTE_P insn shouldn't be
>>>> encountered in those places, so the adjustments for most of them are just to
>>>> consider NOTE_P or this kind of special block and so on.  One draft patch is
>>>> attached, it can be bootstrapped and regress-tested on ppc64{,le} and x86.
>>>> btw, it's without the previous cfg_cleanup adjustment (hope it can get more
>>>> empty blocks and expose more issues).  The draft isn't qualified for code
>>>> review but I hope it can provide some information on what kinds of changes
>>>> are needed for the proposal.  If this is the direction which we all agree on,
>>>> I'll further refine it and post a formal patch.  One thing I want to note is
>>>> that this patch disable one assertion below:
>>>>
>>>> diff --git a/gcc/sched-rgn.cc b/gcc/sched-rgn.cc
>>>> index e5964f54ead..abd334864fb 100644
>>>> --- a/gcc/sched-rgn.cc
>>>> +++ b/gcc/sched-rgn.cc
>>>> @@ -3219,7 +3219,7 @@ schedule_region (int rgn)
>>>>      }
>>>>
>>>>    /* Sanity check: verify that all region insns were scheduled.  */
>>>> -  gcc_assert (sched_rgn_n_insns == rgn_n_insns);
>>>> +  // gcc_assert (sched_rgn_n_insns == rgn_n_insns);
>>>>
>>>>    sched_finish_ready_list ();
>>>>
>>>> Some cases can cause this assertion to fail, it's due to the mismatch on
>>>> to-be-scheduled and scheduled insn counts.  The reason why it happens is that
>>>> one block previously has only one INSN_P but while scheduling some other blocks
>>>> it gets moved as well then we ends up with an empty block so that the only
>>>> NOTE_P insn was counted then, but since this block isn't empty initially and
>>>> NOTE_P gets skipped in a normal block, the count to-be-scheduled can't count
>>>> it in.  It can be fixed with special-casing this kind of block for counting
>>>> like initially recording which block is empty and if a block isn't recorded
>>>> before then fix up the count for it accordingly.  I'm not sure if someone may
>>>> have an argument that all the complication make this proposal beaten by
>>>> previous special-casing debug insn approach, looking forward to more comments.
>>>
>>> Just a comment that the NOTE_P thing is odd - do we only ever have those for
>>> otherwise empty BBs?  How are they skipped otherwise (and why does that not
>>> work for otherwise empty BBs)?
>>
>> Yes, previously (bypassing empty BBs) there is no chance to encounter NOTE_P
>> when scheduling insns, as for notes in normal BBs, when setting up the head
>> and tail, some are skipped (like get_ebb_head_tail), and there are also some
>> special handlings remove_notes and unlink_bb_notes to guarantee they are
>> gone.  By disabling empty BB bypassing, all empty BBs will be actually
>> uniformed as (head == tail && NOTE_P (head)), we have to deal with NOTE_P.
> 
> I see.  I expected most of them to be naturally part of another EBB.  So it's
> rather a limitation of the head/tail representation.
> 
> I wonder if there's a more minimal fix though.  But iff head or tail

Not sure I got the question correctly, if it is for this inconsistent states
issue, I think what Maxim suggested seems to be the minimal fixes.

> of an EBB then I
> guess either head or tail has to point to a stmt in said block which necessarily
> then means either a debug or note.

Yes, will only have NOTE_P for empty BB, if there is a debug insn then it wins
(all NOTEs get dropped).  remove_notes runs from head to tail, it's applied for
EBB's special head and tail.

BR,
Kewen

  reply	other threads:[~2023-11-23  9:09 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-25  2:45 Kewen.Lin
2023-11-08  2:49 ` PING^1 " Kewen.Lin
2023-11-08  9:45   ` Richard Sandiford
2023-11-09  9:10   ` Maxim Kuvyrkov
2023-11-09 17:40     ` Alexander Monakov
2023-11-10  1:57       ` Kewen.Lin
2023-11-10  3:49         ` Jeff Law
2023-11-10 11:25           ` Alexander Monakov
2023-11-10 13:32             ` Richard Biener
2023-11-10 14:18               ` Alexander Monakov
2023-11-10 14:20                 ` Richard Biener
2023-11-10 14:41                   ` Alexander Monakov
2023-11-15  9:12                     ` Kewen.Lin
2023-11-15  9:43                       ` Alexander Monakov
2023-11-17  9:03                         ` Kewen.Lin
2023-11-17 10:13                           ` Richard Biener
2023-11-17 12:55                           ` Alexander Monakov
2023-11-22  9:30                             ` Kewen.Lin
2023-11-22 10:25                               ` Richard Biener
2023-11-23  2:36                                 ` Kewen.Lin
2023-11-23  8:20                                   ` Richard Biener
2023-11-23  9:09                                     ` Kewen.Lin [this message]
2023-12-12  7:02                               ` [PATCH draft v2] sched: Don't skip empty block in scheduling [PR108273] Kewen.Lin
2023-11-10  3:49       ` PING^1 [PATCH v3] sched: Change no_real_insns_p to no_real_nondebug_insns_p [PR108273] Jeff Law
2023-11-15  9:01       ` [PATCH] sched: Remove debug counter sched_block Kewen.Lin
2023-12-12  6:17         ` PING^1 " Kewen.Lin
2023-12-20 20:43           ` Jeff Law
2023-12-21  5:46             ` Kewen.Lin

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=fab8b5ba-43df-70ec-5646-f60cbd3811eb@linux.ibm.com \
    --to=linkw@linux.ibm.com \
    --cc=abel@ispras.ru \
    --cc=amonakov@ispras.ru \
    --cc=bergner@linux.ibm.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jeffreyalaw@gmail.com \
    --cc=jlaw@ventanamicro.com \
    --cc=maxim.kuvyrkov@linaro.org \
    --cc=meissner@linux.ibm.com \
    --cc=oliva@adacore.com \
    --cc=richard.guenther@gmail.com \
    --cc=richard.sandiford@arm.com \
    --cc=segher@kernel.crashing.org \
    --cc=vmakarov@redhat.com \
    --cc=zhroma@ispras.ru \
    /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).