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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |missed-optimization
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2016-05-16
     Ever confirmed|0                           |1
           Severity|normal                      |enhancement

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #1)
> Most likely the opt needs to be moved from fold-const to match.pd .  Should
> be a simple patch.

Yes:
      /* If this is an NE or EQ comparison of zero against the result of a
         signed MOD operation whose second operand is a power of 2, make
         the MOD operation unsigned since it is simpler and equivalent.  */
      if (integer_zerop (arg1)
          && !TYPE_UNSIGNED (TREE_TYPE (arg0))
          && (TREE_CODE (arg0) == TRUNC_MOD_EXPR
              || TREE_CODE (arg0) == CEIL_MOD_EXPR
              || TREE_CODE (arg0) == FLOOR_MOD_EXPR
              || TREE_CODE (arg0) == ROUND_MOD_EXPR)
          && integer_pow2p (TREE_OPERAND (arg0, 1)))
        {
          tree newtype = unsigned_type_for (TREE_TYPE (arg0));
          tree newmod = fold_build2_loc (loc, TREE_CODE (arg0), newtype,
                                     fold_convert_loc (loc, newtype,
                                                       TREE_OPERAND (arg0, 0)),
                                     fold_convert_loc (loc, newtype,
                                                       TREE_OPERAND (arg0,
1)));

          return fold_build2_loc (loc, code, type, newmod,
                              fold_convert_loc (loc, newtype, arg1));
        }


Something like:
(for mod (ceil_mod floor_mod round_mod trunc_mod)
 (for eqne (ne eq)
  (simplify (eqne (mod @1 integer_pow2p@2) integer_zerop)
   (if (!TYPE_UNSIGNED (TREE_TYPE (@1)))
    ( .... ))))

I am lazy to fill in the ... part right now but you get the idea.

Reply via email to