public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* RFC: Combine of compare & and oddity
@ 2015-09-02 17:09 Wilco Dijkstra
  2015-09-02 18:49 ` Segher Boessenkool
  2015-09-02 20:45 ` Jeff Law
  0 siblings, 2 replies; 26+ messages in thread
From: Wilco Dijkstra @ 2015-09-02 17:09 UTC (permalink / raw)
  To: 'GCC Patches', 'Segher Boessenkool'

Hi,

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])))
Failed to match this instruction:
(set (reg:CC 66 cc)
    (compare:CC (and:DI (lshiftrt:DI (subreg:DI (reg/v:SI 76 [ xD.2641 ]) 0)
                (const_int 1 [0x1]))
            (const_int 1 [0x1]))
        (const_int 0 [0])))

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 even uses shifts by 0 at
times which are unlikely to ever match anything). Why does combine not try to match the obvious (x &
C) != 0 case? Single-bit and mask tests are very common, so this blocks efficient code generation on
many targets.

It's trivial to change change_zero_ext to expand extracts always into AND and remove the redundant
subreg. However wouldn't it make more sense to never special case certain AND immediate in the first
place?

Wilco






^ permalink raw reply	[flat|nested] 26+ messages in thread

end of thread, other threads:[~2015-09-03 21:12 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-09-02 17:09 RFC: Combine of compare & and oddity 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
2015-09-02 20:45 ` Jeff Law
2015-09-02 21:05   ` Segher Boessenkool
2015-09-03 15:26     ` Jeff Law

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).