phiopt: Optimize partial_ordering spaceship >= 0 -ffinite-math-only [PR94589]
authorJakub Jelinek <jakub@redhat.com>
Tue, 18 May 2021 08:08:51 +0000 (10:08 +0200)
committerJakub Jelinek <jakub@redhat.com>
Tue, 18 May 2021 08:08:51 +0000 (10:08 +0200)
commit65061ea287a80cfb214e402cfd2373a14bfec95a
tree1f99a7d4ffd69642018df6da8b634301e0fce7ef
parentb2a09773155892e426b90ce8367e2ed6996b44ef
phiopt: Optimize partial_ordering spaceship >= 0 -ffinite-math-only [PR94589]

As mentioned earlier, spaceship_replacement didn't optimize partial_ordering
>= 0 comparisons, because the possible values are -1, 0, 1, 2 and the
>= comparison is implemented as (res & 1) == res to choose the 0 and 1
cases from that.  As we optimize that only with -ffinite-math-only, the
2 case is assumed not to happen and my earlier match.pd change optimizes
(res & 1) == res into (res & ~1) == 0, so this patch pattern matches
that case and handles it like res >= 0.

2021-05-18  Jakub Jelinek  <jakub@redhat.com>

PR tree-optimization/94589
* tree-ssa-phiopt.c (spaceship_replacement): Pattern match
phi result used in (res & ~1) == 0 comparison as res >= 0 as
res == 2 would be UB with -ffinite-math-only.

* g++.dg/opt/pr94589-2.C: Adjust scan-tree-dump count from 14 to 12.
gcc/testsuite/g++.dg/opt/pr94589-2.C
gcc/tree-ssa-phiopt.c