[PATCH] fold x << (n % C) to x << (n & C-1) if C meets power2
commit222f312a773157f53396ba4cb287deb07f84cc34
authorguojiufu <guojiufu@linux.ibm.com>
Mon, 19 Oct 2020 05:48:19 +0000 (19 13:48 +0800)
committerguojiufu <guojiufu@linux.ibm.com>
Mon, 19 Oct 2020 09:26:41 +0000 (19 17:26 +0800)
treed865a929bc4d8d6f467ce98e33831931f4a50451
parentdccb0f8801363462a11fd13a33ff3f4092ff82bd
[PATCH] fold x << (n % C) to x << (n & C-1) if C meets power2

This patch fixes PR66552 which is also as:
https://gcc.gnu.org/pipermail/gcc-patches/2020-February/540930.html
which requests to optimizes (x shift (n mod C)) to
(x shift (n bit_and (C - 1))) when C is a constant and power of two.

gcc/ChangeLog
2020-10-19  Li Jia He  <helijia@gcc.gnu.org>

PR tree-optimization/66552
* match.pd (x << (n % C) -> x << (n & C-1)): New simplification.

gcc/testsuite/ChangeLog
2020-10-19  Li Jia He  <helijia@gcc.gnu.org>

PR tree-optimization/66552
* gcc.dg/pr66552.c: New testcase.
gcc/match.pd
gcc/testsuite/gcc.dg/pr66552.c [new file with mode: 0644]