[PATCH] Fix PR66552, Missed optimization when shift amount is result of signed modulus
Richard Biener
rguenther@suse.de
Mon Feb 17 08:01:00 GMT 2020
On Mon, 17 Feb 2020, Li Jia He wrote:
> Hi,
>
> This patch wants to fix PR66552 on gimple and optimizes (x shift (n mod C))
> to (x shift (n bit_and (C - 1))) when C is a constant and power of two as
> discussed in PR66552.
>
> The regression testing for the patch was done on GCC mainline on
>
> powerpc64le-unknown-linux-gnu (Power 9 LE)
>
> with no regressions. Is it OK for GCC11 ?
I fail to see the connection with a shift operation, can you explain?
Thanks,
Richard.
> Thanks,
> Lijia He
>
> gcc/ChangeLog
> 2020-02-17 Li Jia He <helijia@linux.ibm.com>
>
> PR tree-optimization/66552
> * match.pd (x shift (n mod pow2(c))): Optimizes to
> (x shift (n bit_and (pow2(c) - 1)).
>
> testsuite/ChangeLog
> 2019-02-17 Li Jia He <helijia@linux.ibm.com>
>
> PR tree-optimization/66552
> * testsuite/gcc.dg/pr66552.c: New testcase.
> ---
> gcc/match.pd | 6 ++++++
> gcc/testsuite/gcc.dg/pr66552.c | 14 ++++++++++++++
> 2 files changed, 20 insertions(+)
> create mode 100644 gcc/testsuite/gcc.dg/pr66552.c
>
> diff --git a/gcc/match.pd b/gcc/match.pd
> index 73834c25593..1d74f7dba7f 100644
> --- a/gcc/match.pd
> +++ b/gcc/match.pd
> @@ -546,6 +546,12 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
> (simplify
> (mod (mod@2 @0 @1) @1)
> @2)
> + /* Optimize (x shift (n mod C)) to (x shift (n bit_and (C - 1))) when C is a
> + constant and power of two. */
> + (for shift (lshift rshift)
> + (simplify
> + (shift @0 (mod @1 integer_pow2p@2))
> + (shift @0 (bit_and @1 (minus @2 { build_int_cst (TREE_TYPE (@2), 1); })))))
> /* From extract_muldiv_1: (X * C1) % C2 is zero if C1 is a multiple of C2. */
> (simplify
> (mod (mult @0 INTEGER_CST@1) INTEGER_CST@2)
> diff --git a/gcc/testsuite/gcc.dg/pr66552.c b/gcc/testsuite/gcc.dg/pr66552.c
> new file mode 100644
> index 00000000000..7583c9ad25a
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/pr66552.c
> @@ -0,0 +1,14 @@
> +/* { dg-do compile } */
> +/* { dg-options "-O2 -fdump-tree-lower" } */
> +
> +unsigned a(unsigned x, int n)
> +{
> + return x >> (n % 32);
> +}
> +
> +unsigned b(unsigned x, int n)
> +{
> + return x << (n % 32);
> +}
> +
> +/* { dg-final { scan-tree-dump-not " % " "lower" } } */
>
--
Richard Biener <rguenther@suse.de>
SUSE Software Solutions Germany GmbH, Maxfeldstrasse 5, 90409 Nuernberg,
Germany; GF: Felix Imendörffer; HRB 36809 (AG Nuernberg)
More information about the Gcc-patches
mailing list