Hi!

On Thu, Oct 15, 2020 at 03:52:01PM +0800, guojiufu wrote:
> I just had a check on below patch for PR66552.
> https://gcc.gnu.org/pipermail/gcc-patches/2020-February/540930.html
> It seems this patch works fine now. This patch fixes PR66552 which
> request to optimizes (x shift (n mod C)) to
> (x shift (n bit_and (C - 1))) when C is a constant and power of two.

>  /* Optimize TRUNC_MOD_EXPR by a power of two into a BIT_AND_EXPR,
>     i.e. "X % C" into "X & (C - 1)", if X and C are positive.
>     Also optimize A % (C << N)  where C is a power of 2,
> -   to A & ((C << N) - 1).  */
> +   to A & ((C << N) - 1).  And optimize "A shift (B % C)" where C
> +   is a power of 2, shift operation included "<<" and ">>" and assume
> +   (B % C) will not be negative as shifts negative values would be UB,
> +   to  "A shift (B & (C - 1))".  */

Maybe this can be phrased better?  Not that I have any proposed text :-/

The patch looks good to me, fwiw.


Segher

Reply via email to