public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jonathan Wakely <jwakely@redhat.com>
To: Jakub Jelinek <jakub@redhat.com>
Cc: Richard Biener <rguenther@suse.de>,
	Jason Merrill <jason@redhat.com>,
	gcc-patches@gcc.gnu.org
Subject: Re: [PATCH] phiopt: Optimize (x <=> y) cmp z [PR94589]
Date: Tue, 4 May 2021 10:42:12 +0100	[thread overview]
Message-ID: <20210504094212.GH3008@redhat.com> (raw)
In-Reply-To: <20210504074413.GI1179226@tucnak>

On 04/05/21 09:44 +0200, Jakub Jelinek wrote:
>Hi!
>
>genericize_spaceship genericizes i <=> j to approximately
>({ int c; if (i == j) c = 0; else if (i < j) c = -1; else c = 1; c; })
>for strong ordering and
>({ int c; if (i == j) c = 0; else if (i < j) c = -1; else if (i > j) c = 1; else c = 2; c; })
>for partial ordering.
>The C++ standard supports then == or != comparisons of that against
>strong/partial ordering enums, or </<=/==/!=/>/>= comparisons of <=> result
>against literal 0.
>
>In some cases we already optimize that but in many cases we keep performing
>all the 2 or 3 comparisons, compute the spaceship value and then compare
>that.
>
>The following patch recognizes those patterns if the <=> operands are
>integral types or floating point (the latter only for -ffast-math) and
>optimizes it to the single comparison that is needed (plus adds debug stmts
>if needed for the spaceship result).
>
>Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
>
>There are two things I'd like to address in a follow-up:
>1) if (HONOR_NANS (TREE_TYPE (lhs1)) || HONOR_SIGNED_ZEROS (TREE_TYPE (lhs1)))
>is what I've copied from elsewhere in phiopt, but thinking about it,
>alll we care is probably only HONOR_NANS, the matched pattern starts with
>== or != comparison and branches to the PHI bb with -1/0/1/2 result if it is
>equal, which should be the case for signed zero differences.
>2) the pr94589-2.C testcase should be matching just 12 times each, but runs
>into operator>=(strong_ordering, unspecified) being defined as

Should this say s/strong/partial/  ?



  reply	other threads:[~2021-05-04  9:42 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-04  7:44 Jakub Jelinek
2021-05-04  9:42 ` Jonathan Wakely [this message]
2021-05-04  9:56   ` Jakub Jelinek
2021-05-05 11:39 ` Richard Biener
2021-05-05 13:18   ` [PATCH] phiopt, v2: " Jakub Jelinek
2021-05-05 14:17     ` Richard Biener
2021-05-05 11:45 ` [PATCH] phiopt: " Marc Glisse
2021-05-05 16:52   ` Jakub Jelinek
2021-05-06 10:22     ` Jakub Jelinek
2021-05-06 19:42       ` Marc Glisse
2021-05-11  7:34         ` [PATCH] match.pd: Optimize (x & y) == x into (x & ~y) == 0 [PR94589] Jakub Jelinek
2021-05-11  8:11           ` Marc Glisse
2021-05-11  8:20           ` Richard Biener
2021-05-14 17:26         ` [PATCH] phiopt: Optimize (x <=> y) cmp z [PR94589] Jakub Jelinek
2021-05-15 10:09           ` Marc Glisse
2021-05-05 15:45 ` Martin Sebor

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=20210504094212.GH3008@redhat.com \
    --to=jwakely@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jakub@redhat.com \
    --cc=jason@redhat.com \
    --cc=rguenther@suse.de \
    /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).