public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Henderson <richard.henderson@linaro.org>
To: "Richard Earnshaw (lists)" <Richard.Earnshaw@arm.com>,
	gcc-patches@gcc.gnu.org, marcus.shawcroft@arm.com,
	segher@kernel.crashing.org, Wilco.Dijkstra@arm.com,
	richard.sandiford@arm.com
Subject: Re: [PATCH v2 00/11] aarch64: Implement TImode comparisons
Date: Tue, 7 Apr 2020 10:05:26 -0700	[thread overview]
Message-ID: <ff654104-ee3a-f6fc-260d-190a933a2cbf@linaro.org> (raw)
In-Reply-To: <mptwo6rs1cz.fsf@arm.com>

On 4/7/20 9:32 AM, Richard Sandiford wrote:
> It's not really reversibility that I'm after (at least not for its
> own sake).
> 
> If we had a three-input compare_cc rtx_code that described a comparison
> involving a carry input, we'd certainly be using it here, because that's
> what the instruction does.  Given that we don't have the rtx_code, three
> obvious choices are:
> 
> (1) Add it.
> 
> (2) Continue to represent what the instruction does using an unspec.
> 
> (3) Don't try to represent the "three-input compare_cc" operation and
>     instead describe a two-input comparison that only yields a valid
>     result for a subset of tests.
> 
> (1) seems like the best technical solution but would probably be
> a lot of work.  I guess the reason I like (2) is that it stays
> closest to (1).

Indeed, the biggest problem that I'm having with copying the arm solution to
aarch64 is the special cases of the constants.

The first problem is that (any_extend:M1 (match_operand:M2)) is invalid rtl for
a constant, so you can't share the same define_insn to handle both register and
immediate input.

The second problem is how unpredictable the canonical rtl of an expression can
be after constant folding.  Which again requires more and more define_insns.
Even the Arm target gets this wrong.  In particular,

> (define_insn "cmpsi3_carryin_<CC_EXTEND>out"
>   [(set (reg:<CC_EXTEND> CC_REGNUM)
>         (compare:<CC_EXTEND>
>          (SE:DI (match_operand:SI 1 "s_register_operand" "0,r"))
>          (plus:DI (match_operand:DI 3 "arm_borrow_operation" "")
>                   (SE:DI (match_operand:SI 2 "s_register_operand" "l,r")))))
>    (clobber (match_scratch:SI 0 "=l,r"))]

is non-canonical according to combine.  It will only attempt the ordering

  (compare
    (plus ...)
    (sign_extend ...))

I have no idea why combine is attempting to reverse the sense of the comparison
here.  I can only presume it would also reverse the sense of the branch on
which the comparison is made, had the pattern matched.

This second problem is partially worked around by fwprop, in that it will try
to simply replace the operand without folding if that is recognizable.  Thus
cases like

  (compare (const_int 0) (plus ...))

can be produced from fwprop but not combine.  Which works well enough to not
bother with the CC_RSBmode that the arm target uses.

The third problem is the really quite complicated code that goes into
SELECT_CC_MODE.  This really should not be as difficult as it is, and is the
sort of thing for which we built recog.

Related to that is the insn costing, which also ought to use something akin to
recog.  We have all of the information there: if the insn is recognizable, the
type/length attributes can be used to provide a good value.


r~

  reply	other threads:[~2020-04-07 17:05 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-02 18:53 Richard Henderson
2020-04-02 18:53 ` [PATCH v2 01/11] aarch64: Accept 0 as first argument to compares Richard Henderson
2020-04-02 18:53 ` [PATCH v2 02/11] aarch64: Accept zeros in add<GPI>3_carryin Richard Henderson
2020-04-02 18:53 ` [PATCH v2 03/11] aarch64: Provide expander for sub<GPI>3_compare1 Richard Henderson
2020-04-02 18:53 ` [PATCH v2 04/11] aarch64: Introduce aarch64_expand_addsubti Richard Henderson
2020-04-02 18:53 ` [PATCH v2 05/11] aarch64: Use UNSPEC_SBCS for subtract-with-borrow + output flags Richard Henderson
2020-04-09 21:52   ` Segher Boessenkool
2020-04-10  3:50     ` Richard Henderson
2020-04-02 18:53 ` [PATCH v2 06/11] aarch64: Use UNSPEC_ADCS for add-with-carry " Richard Henderson
2020-04-02 18:53 ` [PATCH v2 07/11] aarch64: Remove CC_ADCmode Richard Henderson
2020-04-02 18:53 ` [PATCH v2 08/11] aarch64: Accept -1 as second argument to add<mode>3_carryin Richard Henderson
2020-04-02 18:53 ` [PATCH v2 09/11] aarch64: Adjust result of aarch64_gen_compare_reg Richard Henderson
2020-04-02 18:53 ` [PATCH v2 10/11] aarch64: Implement TImode comparisons Richard Henderson
2020-04-02 18:53 ` [PATCH v2 11/11] aarch64: Implement absti2 Richard Henderson
2020-04-02 18:55 ` [PATCH v2 00/11] aarch64: Implement TImode comparisons Richard Henderson
2020-04-03 11:34 ` Richard Earnshaw (lists)
2020-04-03 12:27   ` Richard Sandiford
2020-04-03 13:17     ` Richard Earnshaw (lists)
2020-04-03 15:03       ` Richard Sandiford
2020-04-06  9:27         ` Richard Earnshaw (lists)
2020-04-06 11:19           ` Richard Sandiford
2020-04-06 12:22             ` Richard Biener
2020-04-08  9:10               ` Richard Sandiford
2020-04-07  9:52             ` Richard Earnshaw (lists)
2020-04-07 16:32               ` Richard Sandiford
2020-04-07 17:05                 ` Richard Henderson [this message]
2020-04-07 19:43               ` Segher Boessenkool
2020-04-07 20:27             ` Segher Boessenkool
2020-04-07 21:43               ` Richard Henderson
2020-04-07 23:58                 ` Segher Boessenkool
2020-04-08  0:50                   ` Richard Henderson
2020-04-08 20:56                     ` Segher Boessenkool
2020-04-08  9:06               ` Richard Sandiford

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=ff654104-ee3a-f6fc-260d-190a933a2cbf@linaro.org \
    --to=richard.henderson@linaro.org \
    --cc=Richard.Earnshaw@arm.com \
    --cc=Wilco.Dijkstra@arm.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=marcus.shawcroft@arm.com \
    --cc=richard.sandiford@arm.com \
    --cc=segher@kernel.crashing.org \
    /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).