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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
           Assignee|unassigned at gcc dot gnu.org      |pinskia at gcc dot 
gnu.org

--- Comment #14 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
So I suspecting it is this pattern:
/* -(type)!A -> (type)A - 1.  */
(simplify
 (negate (convert?:s (logical_inverted_value:s @0)))
 (if (INTEGRAL_TYPE_P (type)
      && TREE_CODE (type) != BOOLEAN_TYPE
      && TYPE_PRECISION (type) > 1
      && TREE_CODE (@0) == SSA_NAME
      && ssa_name_has_boolean_range (@0))
  (plus (convert:type @0) { build_all_ones_cst (type); })))

We start out with:
-(unsigned int)(bool:31 == 0)

Yes bool:31 == 0 will have 0/1 but bool:31 does not.

Even more:
bool
ssa_name_has_boolean_range (tree op)
{
  gcc_assert (TREE_CODE (op) == SSA_NAME);

  /* Boolean types always have a range [0..1].  */
  if (TREE_CODE (TREE_TYPE (op)) == BOOLEAN_TYPE)
    return true;

Changing that pattern to:
/* -(type)!A -> (type)A - 1.  */
(simplify
 (negate (convert?:s (logical_inverted_value:s zero_one_valued_p@0)))
 (if (INTEGRAL_TYPE_P (type)
      && TREE_CODE (type) != BOOLEAN_TYPE
      && TYPE_PRECISION (type) > 1)
  (plus (convert:type @0) { build_all_ones_cst (type); })))

Fixes the testcase in comment #10 and should fix the original issue too.

Reply via email to