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

--- Comment #18 from Georg-Johann Lay <gjl at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #16)
> But that still fails because combine really does not like subregs:
> [...]
> Failed to match this instruction:
> (set (reg/i:QI 24 r24)
>      (subreg:QI (lshiftrt:SI (reg:SI 48)
>                 (const_int 31 [0x1f])) 0))

Eons ago I solved the canonicalization problem during combine as follow:

Prior to recog_for_combine, there was a target hook that could canonicalize
combined rtx's to a canonical form.  This was achieved by means of special
split patterns (wrapped in some unspec_canonicalize and insn condition).  If
there was a match, combine would proceed with the canonicalized form.

IMO, trying to target-independent canonicalize in combine itself just works to
some degree, because combine is well in target-specigic land, and targets are
very different.

;; Combine's "smart" method to extract the MSB.
(define_insn_and_split "*extzv.neg.subreg-msb.<mode>"
  [(set (match_operand:QI 0 "register_operand"                          "=r")
        (neg:QI (subreg:QI
                 (ashiftrt:HISI (match_operand:HISI 1 "register_operand" "r")
                                (match_operand:QI 2 "const<MSB>_operand" "n"))
                 0)))]
   ""
   "#"
   "&& reload_completed"
   [; "*extzv"
    (parallel [(set (match_dup 0)
                    (zero_extract:QI (match_dup 1)
                                     (const_int 1)
                                     (match_dup 2)))
               (clobber (reg:CC REG_CC))])]
   {
     ...;
   })

Such patterns work, bit the problem is that you are pushing combine away from a
(target-)canonical form.

Next best match would be a pre-reload matching split.  If that works, it might
be superior to a post-reload split, but it happens at split1 which runs after
reload.

The closest match to canonicalization are the non-matching splits that will run
during combine.  The problem with these is that such splits must have very
special for (like split 1 pattern into exactly 2, additional restrictios
apply), and in many cases non-matching splits will fail or are not possible.

Such a target-specific canonicalization would push combine towards a
target-canonical form, instead of encouraging it to go further astray and try
even more crazy, none-canonical combinations.

Reply via email to