public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jiufu Guo <guojiufu@linux.ibm.com>
To: Jeff Law <law@redhat.com>
Cc: Richard Biener <rguenther@suse.de>,
	gcc-patches@gcc.gnu.org,        Jakub Jelinek <jakub@redhat.com>,
	Daniel Berlin <dberlin@dberlin.org>,
	       segher@kernel.crashing.org, wschmidt@linux.ibm.com
Subject: Re: [PATCH] A jump threading opportunity for condition branch
Date: Tue, 04 Jun 2019 05:19:00 -0000	[thread overview]
Message-ID: <h485zpmyljy.fsf@genoa.aus.stglabs.ibm.com> (raw)
In-Reply-To: <47b8d7f9-0039-593e-0813-7dc5e58acfe9@redhat.com> (Jeff Law's	message of "Fri, 31 May 2019 09:03:28 -0600")

Jeff Law <law@redhat.com> writes:

> On 5/31/19 1:24 AM, Richard Biener wrote:
>> On Thu, 30 May 2019, Jeff Law wrote:
>> 
>>> On 5/30/19 12:41 AM, Richard Biener wrote:
>>>> On May 29, 2019 10:18:01 PM GMT+02:00, Jeff Law <law@redhat.com> wrote:
>>>>> On 5/23/19 6:11 AM, Richard Biener wrote:
>>>>>> On Thu, 23 May 2019, Jiufu Guo wrote:
>>>>>>
>>>>>>> Hi,
>>>>>>>
>>>>>>> Richard Biener <rguenther@suse.de> writes:
>>>>>>>
>>>>>>>> On Tue, 21 May 2019, Jiufu Guo wrote:
>>>>>
>>>>>>>>> +    }
>>>>>>>>> +
>>>>>>>>> +  if (TREE_CODE_CLASS (gimple_assign_rhs_code (def)) !=
>>>>> tcc_comparison)
>>>>>>>>> +    return false;
>>>>>>>>> +
>>>>>>>>> +  /* Check if phi's incoming value is defined in the incoming
>>>>> basic_block.  */
>>>>>>>>> +  edge e = gimple_phi_arg_edge (phi, index);
>>>>>>>>> +  if (def->bb != e->src)
>>>>>>>>> +    return false;
>>>>>>>> why does this matter?
>>>>>>>>
>>>>>>> Through preparing pathes and duplicating block, this transform can
>>>>> also
>>>>>>> help to combine a cmp in previous block and a gcond in current
>>>>> block.
>>>>>>> "if (def->bb != e->src)" make sure the cmp is define in the incoming
>>>>>>> block of the current; and then combining "cmp with gcond" is safe. 
>>>>> If
>>>>>>> the cmp is defined far from the incoming block, it would be hard to
>>>>>>> achieve the combining, and the transform may not needed.
>>>>>> We're in SSA form so the "combining" doesn't really care where the
>>>>>> definition comes from.
>>>>> Combining doesn't care, but we need to make sure the copy of the
>>>>> conditional ends up in the right block since it wouldn't necessarily be
>>>>> associated with def->bb anymore.  But I'd expect the sinking pass to
>>>>> make this a non-issue in practice anyway.
>>>>>
>>>>>>
>>>>>>>>> +
>>>>>>>>> +  if (!single_succ_p (def->bb))
>>>>>>>>> +    return false;
>>>>>>>> Or this?  The actual threading will ensure this will hold true.
>>>>>>>>
>>>>>>> Yes, other thread code check this and ensure it to be true, like
>>>>>>> function thread_through_normal_block. Since this new function is
>>>>> invoked
>>>>>>> outside thread_through_normal_block, so, checking single_succ_p is
>>>>> also
>>>>>>> needed for this case.
>>>>>> I mean threading will isolate the path making this trivially true.
>>>>>> It's also no requirement for combining, in fact due to the single-use
>>>>>> check the definition can be sinked across the edge already (if
>>>>>> the edges dest didn't have multiple predecessors which this threading
>>>>>> will fix as well).
>>>>> I don't think so.  The CMP source block could end with a call and have
>>>>> an abnormal edge (for example).  We can't put the copied conditional
>>>>> before the call and putting it after the call essentially means
>>>>> creating
>>>>> a new block.
>>>>>
>>>>> The CMP source block could also end with a conditional.  Where do we
>>>>> put
>>>>> the one we want to copy into the CMP source block in that case? :-)
>>>>>
>>>>> This is something else we'd want to check if we ever allowed the the
>>>>> CMP
>>>>> defining block to not be the immediate predecessor of the conditional
>>>>> jump block.  If we did that we'd need to validate that the block where
>>>>> we're going to insert the copy of the jump has a single successor.
>>>>
>>>> But were just isolating a path here. The actual combine job is left to followup cleanups. 
>>> Absolutely agreed.  My point was that there's some additional stuff we'd
>>> have to verify does the right thing if we wanted to allow the CMP to be
>>> somewhere other than in the immediate predecessor of the conditional
>>> jump block.
>> 
>> For correctness?  No.  For the CMP to be forwarded?  No.  For optimality
>> maybe - forwarding a binary operation always incurs register pressure
>> increase.
> For correctness of the patch.  Conceptually I have _no_ issues with
> having the CMP in a different block than an immediate predecessor of the
> conditional jump block.  But the patch does certain code which would
> need to be audited with that change in mind.
Thanks for all your great comments! It is right, if immediate predecessor
of conditional jump block has more than one successors, the conditional
jump block can be duplicated to split the path; and the condtional jump
will keep in the duplicate block instead inserting into predecessor.  From
functionality aspect, it is still correct. While it does not merge CMP
with conditional jump in this pass; then it may not directly help to
eliminate the CMP. While I also agree this path may provides other
optimize opportunity in following passes.

I just have a check with gcc bootstrap, and find there are ~1800 edges
as !single_succ_p (e->src).  And similar number edges are single_succ_p
(e->src).  It would be valuable to take the opptunity for these edges of
!single_succ_p (e->src).

Jiufu Guo
>
>> 
>> Btw, as you already said sinking should have sinked the CMP to the
>> predecessor (since we have a single use in the PHI).
>> 
>> So I hardly see the point of making this difference.
> :-)
>
> jeff

  reply	other threads:[~2019-06-04  5:19 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-21 13:45 Jiufu Guo
2019-05-22 12:38 ` Richard Biener
2019-05-23 12:06   ` Jiufu Guo
2019-05-23 12:11     ` Richard Biener
2019-05-23 14:40       ` Jiufu Guo
2019-05-24 12:45         ` Richard Biener
2019-05-24 14:52           ` Jiufu Guo
2019-05-28 14:07           ` [PATCH V2] " Jiufu Guo
2019-05-29  1:51             ` Jiufu Guo
2019-05-29 12:40             ` Richard Biener
2019-05-29 19:47               ` Jeff Law
2019-05-30 15:09                 ` Jiufu Guo
2019-05-30 23:55                   ` Jeff Law
2019-05-31  7:34                     ` Richard Biener
2019-06-04  3:03                     ` Jiufu Guo
2019-05-30 15:34             ` Jeff Law
2019-06-03  2:18               ` [PATCH V3] " Jiufu Guo
2019-06-04  5:30                 ` [PATCH V4] " Jiufu Guo
2019-06-13 18:56                   ` Jeff Law
2019-06-14 12:51                     ` Jiufu Guo
2019-06-14 16:34                       ` Jeff Law
2019-05-29 20:26           ` [PATCH] " Jeff Law
2019-05-30  6:57             ` Richard Biener
2019-05-30  6:58               ` Jiufu Guo
2019-05-30 14:59                 ` Jeff Law
2019-05-30 15:03               ` Jeff Law
2019-05-29 20:22       ` Jeff Law
2019-05-30  6:40         ` Jiufu Guo
2019-05-30  6:44         ` Richard Biener
2019-05-30 20:17           ` Jeff Law
2019-05-31  7:30             ` Richard Biener
2019-05-31 15:28               ` Jeff Law
2019-06-04  5:19                 ` Jiufu Guo [this message]
2019-06-04  7:07                   ` Richard Biener
2019-06-07  0:05                 ` Jeff Law
2019-05-29 20:18     ` Jeff Law
2019-05-30  6:41       ` Richard Biener
2019-05-29 20:12 ` Jeff Law

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=h485zpmyljy.fsf@genoa.aus.stglabs.ibm.com \
    --to=guojiufu@linux.ibm.com \
    --cc=dberlin@dberlin.org \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jakub@redhat.com \
    --cc=law@redhat.com \
    --cc=rguenther@suse.de \
    --cc=segher@kernel.crashing.org \
    --cc=wschmidt@linux.ibm.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).