[Bug tree-optimization/100672] wrong code with vector shift and unary minus

rguenth at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Wed May 19 11:26:00 GMT 2021


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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2021-05-19

--- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> ---
We have in negate_expr/negate_expr_p

    case RSHIFT_EXPR:
      /* Optimize -((int)x >> 31) into (unsigned)x >> 31 for int.  */
      if (TREE_CODE (TREE_OPERAND (t, 1)) == INTEGER_CST)
        {
          tree op1 = TREE_OPERAND (t, 1);
          if (wi::to_wide (op1) == TYPE_PRECISION (type) - 1)
            {
              tree ntype = TYPE_UNSIGNED (type)
                           ? signed_type_for (type)
                           : unsigned_type_for (type);
              tree temp = fold_convert_loc (loc, ntype, TREE_OPERAND (t, 0));
              temp = fold_build2_loc (loc, RSHIFT_EXPR, ntype, temp, op1);
              return fold_convert_loc (loc, type, temp);
            }
        }

note the use of TYPE_PRECISION on a vector type...


More information about the Gcc-bugs mailing list