public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jeff Law <law@redhat.com>
To: Segher Boessenkool <segher@kernel.crashing.org>,
	       Wilco Dijkstra <wdijkstr@arm.com>
Cc: "'GCC Patches'" <gcc-patches@gcc.gnu.org>
Subject: Re: RFC: Combine of compare & and oddity
Date: Thu, 03 Sep 2015 15:52:00 -0000	[thread overview]
Message-ID: <55E86C67.7030303@redhat.com> (raw)
In-Reply-To: <20150903131809.GA27819@gate.crashing.org>

On 09/03/2015 07:18 AM, Segher Boessenkool wrote:
> On Thu, Sep 03, 2015 at 12:43:34PM +0100, Wilco Dijkstra wrote:
>>>> Combine canonicalizes certain AND masks in a comparison with zero into extracts of the
>>> widest
>>>> register type. During matching these are expanded into a very inefficient sequence that
>>> fails to
>>>> match. For example (x & 2) == 0 is matched in combine like this:
>>>>
>>>> Failed to match this instruction:
>>>> (set (reg:CC 66 cc)
>>>>      (compare:CC (zero_extract:DI (subreg:DI (reg/v:SI 76 [ xD.2641 ]) 0)
>>>>              (const_int 1 [0x1])
>>>>              (const_int 1 [0x1]))
>>>>          (const_int 0 [0])))
>>>
>>> Yes.  Some processors even have specific instructions to do this.
>>
>> However there are 2 issues with this, one is the spurious subreg,
>
> Combine didn't make that up out of thin air; something already used
> DImode here.  It could simplify it to SImode in this case, that is
> true, don't know why it doesn't; it isn't necessarily faster code to
> do so, it can be slower, it might not match, etc.
Right.  It may also be the case that on a 64 bit target, but the 
underlying object is 32 bits and combine wanted to do things in word_mode.

But yes, there's a reason why the subreg is in there and there are times 
when the subregs get in the way of the hand-written pattern matching 
that occurs in combine.c and elsewhere.

So it's generally useful to squash away the subregs when we can. 
However, it's also the case that the subregs can't always be squashed 
away -- so it's also helpful to dig into the transformations in 
combine.c that you want to fire and figure out if and how that code can 
be extended to handle the embedded subregs.

>
>> (*) I think that is another issue in combine - when both alternatives match you
>> want to select the lowest cost one, not the first one that matches.
>
> That's recog, not combine.  And quite a few backends rely on "first match
> wins", because it always has been that way.  It also is very easy to write
> such patterns accidentally (sometimes even the exact same one twice in the
> same machine description, etc.)
Note that it's also been documented that first match wins for 20+ years.



>
>> So my question is, is it combine's job to try all possible permutations that
>> constitute a bit or mask test?
>
> Combine converts the merged instructions to what it thinks is the
> canonical or cheapest form, and uses that.  It does not try multiple
> options (the zero_ext* -> and+shift rewriting is not changing the
> semantics of the pattern at all).
Right.  Once combine finds something that works, it's done and moves 
onto the next set of insns to combine.


>
>>>> Neither matches the AArch64 patterns for ANDS/TST (which is just compare and AND). If the
>>> immediate
>>>> is not a power of 2 or a power of 2 -1 then it matches correctly as expected.
>>>>
>>>> I don't understand how ((x >> 1) & 1) != 0 could be a useful expansion
>>>
>>> It is zero_extract(x,1,1) really.  This is convenient for (old and embedded)
>>> processors that have special bit-test instructions.  If we now want combine
>>> to not do this, we'll have to update all backends that rely on it.
>>
>> Would any backend actually rely on this given it only does some specific masks,
>> has a redundant shift with 0 for the mask case and the odd subreg as well?
>
> Such backends match the zero_extract patterns, of course.  Random example:
> the h8300 patterns for the "btst" instruction.
PA, m68k and almost certainly others.  I suspect it's fairly common in 
older ports.


Jeff

  parent reply	other threads:[~2015-09-03 15:51 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-02 17:09 Wilco Dijkstra
2015-09-02 18:49 ` Segher Boessenkool
2015-09-02 19:56   ` Segher Boessenkool
2015-09-03 11:51   ` Wilco Dijkstra
2015-09-03 13:57     ` Segher Boessenkool
2015-09-03 15:00       ` Wilco Dijkstra
2015-09-03 15:21         ` Andrew Pinski
2015-09-03 16:15         ` Jeff Law
2015-09-03 16:40           ` Segher Boessenkool
2015-09-03 18:56             ` Wilco Dijkstra
2015-09-03 19:05               ` Jeff Law
2015-09-03 19:20                 ` Richard Sandiford
2015-09-03 21:20                   ` Jeff Law
2015-09-03 19:22               ` Segher Boessenkool
2015-09-03 16:24         ` Segher Boessenkool
2015-09-03 16:36           ` Kyrill Tkachov
2015-09-03 16:44             ` Wilco Dijkstra
2015-09-03 17:27             ` Segher Boessenkool
2015-09-03 17:30               ` Oleg Endo
2015-09-03 18:53                 ` Wilco Dijkstra
2015-09-03 18:42           ` Jeff Law
2015-09-03 19:06             ` Segher Boessenkool
2015-09-03 15:52       ` Jeff Law [this message]
2015-09-02 20:45 ` Jeff Law
2015-09-02 21:05   ` Segher Boessenkool
2015-09-03 15:26     ` 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=55E86C67.7030303@redhat.com \
    --to=law@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=segher@kernel.crashing.org \
    --cc=wdijkstr@arm.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).