[Bug middle-end/105629] [13 Regression] g++.dg/opt/pr94589-2.C for cris, m68k, s390x

rguenth at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Mon May 23 09:15:57 GMT 2022


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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org
             Status|UNCONFIRMED                 |ASSIGNED
           Priority|P3                          |P1
   Last reconfirmed|                            |2022-05-23
             Target|                            |x86_64-*-*
     Ever confirmed|0                           |1
           Assignee|unassigned at gcc dot gnu.org      |rguenth at gcc dot gnu.org

--- Comment #7 from Richard Biener <rguenth at gcc dot gnu.org> ---
Thanks, so the relevant IL change is probably

  # c$_M_value_3 = PHI <-1(3), 0(2), 2(5), 1(4)>
  _11 = (unsigned char) c$_M_value_3;
  _16 = _11 <= 1;

vs

  # c$_M_value_3 = PHI <-1(3), 0(2), 2(5), 1(4)>
  _11 = (unsigned int) c$_M_value_3;
  _16 = _11 <= 1;

where the conversion from c$_M_value_3 is now sign-extending which is something
spaceship_replacement does not expect.  We how do

Matching expression match.pd:2114, generic-match.cc:676
Matching expression match.pd:2121, generic-match.cc:736
Applying pattern match.pd:5497, generic-match.cc:23783   (****)
Matching expression match.pd:2114, generic-match.cc:676
Matching expression match.pd:2121, generic-match.cc:736
Matching expression match.pd:2126, generic-match.cc:776
Applying pattern match.pd:5868, generic-match.cc:62355
Applying pattern match.pd:3662, generic-match.cc:27474
Applying pattern match.pd:3742, generic-match.cc:26853
Applying pattern match.pd:3648, generic-match.cc:27432

;; Function constexpr bool std::operator>=(partial_ordering,
__cmp_cat::__unspec) (null)
;; enabled by -tree-original


<<< Unknown tree: must_not_throw_expr
  return <retval> = (unsigned int) __v._M_value <= 1
   >>>;

with the marked (****) folding that eventually you re-disable for GENERIC.

In the end we use .SPACESHIP on x86_64 but end up with

bool f17 (double i)
{
  bool _2;
  int _7;
  bool prephitmp_8;

  <bb 2> [local count: 1073741824]:
  _7 = .SPACESHIP (i_1(D), 5.0e+0);
  if (_7 != 0)
    goto <bb 3>; [50.00%]
  else
    goto <bb 5>; [50.00%]

  <bb 3> [local count: 536870913]:
  if (_7 == 1)
    goto <bb 4>; [50.00%]
  else
    goto <bb 5>; [50.00%]

  <bb 4> [local count: 268435456]:
  _2 = i_1(D) > 5.0e+0;

  <bb 5> [local count: 1073741824]:
  # prephitmp_8 = PHI <1(2), _2(4), 0(3)>
  return prephitmp_8;

which is a regression from GCC 12.  I think the non-widening constraint can
be relaxed.  Indeed the following fixes it - Jakub, is there anything
that would prevent sign-extending to work?

diff --git a/gcc/tree-ssa-phiopt.cc b/gcc/tree-ssa-phiopt.cc
index 8c9c46d41f1..e61d9736937 100644
--- a/gcc/tree-ssa-phiopt.cc
+++ b/gcc/tree-ssa-phiopt.cc
@@ -2217,7 +2217,7 @@ spaceship_replacement (basic_block cond_bb, basic_block
middle_bb,

       if (!TYPE_UNSIGNED (ty2) || !INTEGRAL_TYPE_P (ty2))
        return false;
-      if (TYPE_PRECISION (ty1) != TYPE_PRECISION (ty2))
+      if (TYPE_PRECISION (ty1) > TYPE_PRECISION (ty2))
        return false;
       if (SSA_NAME_OCCURS_IN_ABNORMAL_PHI (orig_use_lhs))
        return false;


More information about the Gcc-bugs mailing list