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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2020-09-04
                 CC|                            |jakub at gcc dot gnu.org

--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
We already have a rule for this:
/* Optimize -1 >> x for arithmetic right shifts.  */
(simplify
 (rshift integer_all_onesp@0 @1)
 (if (!TYPE_UNSIGNED (type)
      && tree_expr_nonnegative_p (@1))
  @0))
but the rule requires that the shift count is non-negative.
That was added in PR38359 fix.
Even current wide_int_binop has:
    case RSHIFT_EXPR:
    case LSHIFT_EXPR:
      if (wi::neg_p (arg2))
        {
          tmp = -arg2;
          if (code == RSHIFT_EXPR)
            code = LSHIFT_EXPR;
          else
            code = RSHIFT_EXPR;
        }
      else
        tmp = arg2;
and so it treats rshift shifts by negative values as left shifts.
So, if we wanted to fix this PR, we'd need to remove the
tree_expr_nonnegative_p and change wide_int_binop to perhaps best punt on
negative arg2 instead of trying to handle it.  Wonder what it will break.

Reply via email to