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

--- Comment #9 from Richard Biener <rguenth at gcc dot gnu.org> ---
With all VARYING we simplify

i_19 = (int) _2;
_6 = (int) _5;
Value numbering stmt = _7 = _6 <= i_19;
Applying pattern match.pd:6775, gimple-match-4.cc:1795
Match-and-simplified _6 <= i_19 to 1

where _5 is _Bool and _2 is unsigned int.  We match

 zext <= (int) 4294967295u

note that I see

Value numbering stmt = _2 = f$0_25;
Setting value number of _2 to 4294967295 (changed)
Value numbering stmt = i_19 = (int) _2;
Match-and-simplified (int) _2 to -1
RHS (int) _2 simplified to -1 
Not changing value number of i_19 from VARYING to -1
Making available beyond BB6 i_19 for value i_19

so it's odd we see the constant here, but ... we go

      (if (TREE_CODE (@10) == INTEGER_CST
           && INTEGRAL_TYPE_P (TREE_TYPE (@00))
           && !int_fits_type_p (@10, TREE_TYPE (@00)))
       (with
        {
          tree min = lower_bound_in_type (TREE_TYPE (@10), TREE_TYPE (@00));
          tree max = upper_bound_in_type (TREE_TYPE (@10), TREE_TYPE (@00));
          bool above = integer_nonzerop (const_binop (LT_EXPR, type, max,
@10));
          bool below = integer_nonzerop (const_binop (LT_EXPR, type, @10,
min));
        }
        (if (above || below)

failing to see that we deal with a relational compare and a sign-change.

The original code from fold-const.cc had only INTEGER_TYPE support,
r6-4300-gf6c1575958f7bf made it cover all integral types (it half-way
supported BOOLEAN_TYPE already).  But the issue was latent I think.
One notable difference was that I think get_unwidened made sure to
convert a constant to the wider type while here we have @10 != @1
and the conversion not applied.  We're doing it correct in earlier code:

    /* ???  The special-casing of INTEGER_CST conversion was in the original
       code and here to avoid a spurious overflow flag on the resulting
       constant which fold_convert produces.  */
    (if (TREE_CODE (@1) == INTEGER_CST)

using @1 instead of @10.

Correcting that avoids the pattern from triggering in this wrong way.
  • [Bug tree-optimization/110176] ... rguenth at gcc dot gnu.org via Gcc-bugs

Reply via email to