This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] bswap: Increase search limit by 1


On Tue, Jun 23, 2009 at 1:37 PM, Andreas
Krebbel<krebbel@linux.vnet.ibm.com> wrote:
> Hi,
>
> as Uros pointed out the current libgcc bswap optimizations aren't
> matched by the bswap optimizer pass. ?This is caused by the libgcc
> implementations using a signed argument and result type what requires
> additional type casts. ?Due to these the search depth limit exceeds
> and the patterns don't get recognized. ?This can easily be fixed by
> increasing the search limit by one.
>
> Done with the attached patch.
>
> The patch also adds the libgcc variants to the respective testcases.
>
> Bootstrapped on s390x. No regressions.
>
> Ok for mainline?

Ok.

Thanks,
Richard.

> Bye,
>
> -Andreas-
>
>
> 2009-06-23 ?Andreas Krebbel ?<krebbel1@de.ibm.com>
>
> ? ? ? ?* tree-ssa-math-opts.c (find_bswap): Increase the search depth in
> ? ? ? ?order to match bswaps with signed source operands.
>
>
> Index: gcc/tree-ssa-math-opts.c
> ===================================================================
> --- gcc/tree-ssa-math-opts.c.orig ? ? ? 2009-06-23 08:58:17.000000000 +0200
> +++ gcc/tree-ssa-math-opts.c ? ?2009-06-23 11:09:38.000000000 +0200
> @@ -1125,9 +1125,14 @@ find_bswap (gimple stmt)
> ? struct symbolic_number n;
> ? tree source_expr;
>
> + ?/* The last parameter determines the depth search limit. ?It usually
> + ? ? correlates directly to the number of bytes to be touched. ?We
> + ? ? increase that number by one here in order to also cover signed ->
> + ? ? unsigned conversions of the src operand as can be seen in
> + ? ? libgcc. ?*/
> ? source_expr = ?find_bswap_1 (stmt, &n,
> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? TREE_INT_CST_LOW (
> - ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?TYPE_SIZE_UNIT (gimple_expr_type (stmt))));
> + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?TYPE_SIZE_UNIT (gimple_expr_type (stmt))) + 1);
>
> ? if (!source_expr)
> ? ? return NULL_TREE;
> Index: gcc/testsuite/gcc.dg/optimize-bswapdi-1.c
> ===================================================================
> --- gcc/testsuite/gcc.dg/optimize-bswapdi-1.c.orig ? ? ?2009-06-22 10:11:09.000000000 +0200
> +++ gcc/testsuite/gcc.dg/optimize-bswapdi-1.c ? 2009-06-23 12:34:25.000000000 +0200
> @@ -24,5 +24,25 @@ swap64 (uint64_t in)
> ? return __const_swab64 (in);
> ?}
>
> -/* { dg-final { scan-tree-dump-times "64 bit bswap implementation found at" 1 "bswap" } } */
> +/* This variant is currently used by libgcc. ?The difference is that
> + ? the bswap source and destination have a signed integer type which
> + ? requires a slightly higher search depth in order to dive through
> + ? the cast as well. ?*/
> +
> +typedef int DItype __attribute__ ((mode (DI)));
> +DItype
> +swap64_b (DItype u)
> +{
> + ?return ((((u) & 0xff00000000000000ull) >> 56)
> + ? ? ? ? | (((u) & 0x00ff000000000000ull) >> 40)
> + ? ? ? ? | (((u) & 0x0000ff0000000000ull) >> 24)
> + ? ? ? ? | (((u) & 0x000000ff00000000ull) >> ?8)
> + ? ? ? ? | (((u) & 0x00000000ff000000ull) << ?8)
> + ? ? ? ? | (((u) & 0x0000000000ff0000ull) << 24)
> + ? ? ? ? | (((u) & 0x000000000000ff00ull) << 40)
> + ? ? ? ? | (((u) & 0x00000000000000ffull) << 56));
> +}
> +
> +
> +/* { dg-final { scan-tree-dump-times "64 bit bswap implementation found at" 2 "bswap" } } */
> ?/* { dg-final { cleanup-tree-dump "bswap" } } */
> Index: gcc/testsuite/gcc.dg/optimize-bswapsi-1.c
> ===================================================================
> --- gcc/testsuite/gcc.dg/optimize-bswapsi-1.c.orig ? ? ?2009-06-22 10:11:09.000000000 +0200
> +++ gcc/testsuite/gcc.dg/optimize-bswapsi-1.c ? 2009-06-23 12:35:48.000000000 +0200
> @@ -31,5 +31,21 @@ swap32_b (uint32_t in)
> ? return a;
> ?}
>
> -/* { dg-final { scan-tree-dump-times "32 bit bswap implementation found at" 2 "bswap" } } */
> +/* This variant is currently used by libgcc. ?The difference is that
> + ? the bswap source and destination have a signed integer type which
> + ? requires a slightly higher search depth in order to dive through
> + ? the cast as well. ?*/
> +
> +typedef int SItype __attribute__ ((mode (SI)));
> +
> +SItype
> +swap32_c (SItype u)
> +{
> + ?return ((((u) & 0xff000000) >> 24)
> + ? ? ? ? | (((u) & 0x00ff0000) >> ?8)
> + ? ? ? ? | (((u) & 0x0000ff00) << ?8)
> + ? ? ? ? | (((u) & 0x000000ff) << 24));
> +}
> +
> +/* { dg-final { scan-tree-dump-times "32 bit bswap implementation found at" 3 "bswap" } } */
> ?/* { dg-final { cleanup-tree-dump "bswap" } } */
>


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]