diff options
author | Tamar Christina <tamar.christina@arm.com> | 2021-11-24 06:39:05 +0000 |
---|---|---|
committer | Tamar Christina <tamar.christina@arm.com> | 2021-11-24 06:39:05 +0000 |
commit | 755c2e7d71cbab89b2bd1d787db46428a604efb2 (patch) | |
tree | 3a96133010d3ed8194e020e684572e9719300ee3 /gcc/gimple-range.h | |
parent | 0888d6bbe97e10de0e624f4ab46acc276e5ee1d7 (diff) | |
download | gcc-755c2e7d71cbab89b2bd1d787db46428a604efb2.zip gcc-755c2e7d71cbab89b2bd1d787db46428a604efb2.tar.gz gcc-755c2e7d71cbab89b2bd1d787db46428a604efb2.tar.bz2 |
middle-end: Fix failures with bitclear patterns on signed values
During testing after rebasing to commit I noticed a failing testcase with the
bitmask compare patch.
Consider the following C++ testcase:
#include <compare>
#define A __attribute__((noipa))
A bool f5 (double i, double j) { auto c = i <=> j; return c >= 0; }
This turns into a comparison against chars, on systems where chars are signed
the pattern inserts an unsigned convert such that it's able to do the
transformation.
i.e.:
# RANGE [-1, 2]
# c$_M_value_22 = PHI <-1(3), 0(2), 2(5), 1(4)>
# RANGE ~[3, 254]
_11 = (unsigned char) c$_M_value_22;
_19 = _11 <= 1;
# .MEM_24 = VDEF <.MEM_6(D)>
D.10434 ={v} {CLOBBER};
# .MEM_14 = VDEF <.MEM_24>
D.10407 ={v} {CLOBBER};
# VUSE <.MEM_14>
return _19;
instead of:
# RANGE [-1, 2]
# c$_M_value_5 = PHI <-1(3), 0(2), 2(5), 1(4)>
# RANGE [-2, 2]
_3 = c$_M_value_5 & -2;
_19 = _3 == 0;
# .MEM_24 = VDEF <.MEM_6(D)>
D.10440 ={v} {CLOBBER};
# .MEM_14 = VDEF <.MEM_24>
D.10413 ={v} {CLOBBER};
# VUSE <.MEM_14>
return _19;
This causes much worse codegen under -ffast-math due to phiops no longer
recognizing the pattern. It turns out that phiopts spaceship_replacement is
looking for the exact form that was just changed.
The comments seems to suggest this code only checks for (res & ~1) == 0 but the
implementation seems to suggest it's broader.
As such I added a case to check to see if the value comparison we found is a
type cast. and strips away the type cast and continues.
In match.pd the typecasts are only added for signed comparisons to == 0 and != 0
which are then rewritten into comparisons with 1.
As such I only check for 1 and LE and GT, which is what match.pd would have
rewritten it to.
This fixes the regression but this is not code I 100% understand, since I don't
really know the semantics of the spaceship operator so would appreciate an extra
look.
gcc/ChangeLog:
* tree-ssa-phiopt.c (spaceship_replacement): Handle new canonical
codegen.
Diffstat (limited to 'gcc/gimple-range.h')
0 files changed, 0 insertions, 0 deletions