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: PR40501


On Tue, Jun 23, 2009 at 5:37 PM, Andreas
Krebbel<krebbel@linux.vnet.ibm.com> wrote:
> Hi,
>
> with the attached patch the bswap pass generates conversion statements
> for argument and the result of the emitted builtin invocation if
> necessary.
>
> This fixes PR40501.
>
> Bootstrapped on s390, s390x and x86_64.
> No regressions.
>
> Ok for mainline?

Ok.

Thanks,
Richard.

> Bye,
>
> -Andreas-
>
>
> 2009-06-23 ?Andreas Krebbel ?<krebbel1@de.ibm.com>
>
> ? ? ? ?PR middle-end/40501
> ? ? ? ?* tree-ssa-math-opts.c (execute_optimize_bswap): Convert the bswap
> ? ? ? ?src and dst operands if necessary.
>
>
> Index: gcc/tree-ssa-math-opts.c
> ===================================================================
> --- gcc/tree-ssa-math-opts.c.orig
> +++ gcc/tree-ssa-math-opts.c
> @@ -1159,6 +1159,7 @@ execute_optimize_bswap (void)
> ? basic_block bb;
> ? bool bswap32_p, bswap64_p;
> ? bool changed = false;
> + ?tree bswap32_type = NULL_TREE, bswap64_type = NULL_TREE;
>
> ? if (BITS_PER_UNIT != 8)
> ? ? return 0;
> @@ -1176,6 +1177,20 @@ execute_optimize_bswap (void)
> ? if (!bswap32_p && !bswap64_p)
> ? ? return 0;
>
> + ?/* Determine the argument type of the builtins. ?The code later on
> + ? ? assumes that the return and argument type are the same. ?*/
> + ?if (bswap32_p)
> + ? ?{
> + ? ? ?tree fndecl = built_in_decls[BUILT_IN_BSWAP32];
> + ? ? ?bswap32_type = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (fndecl)));
> + ? ?}
> +
> + ?if (bswap64_p)
> + ? ?{
> + ? ? ?tree fndecl = built_in_decls[BUILT_IN_BSWAP64];
> + ? ? ?bswap64_type = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (fndecl)));
> + ? ?}
> +
> ? FOR_EACH_BB (bb)
> ? ? {
> ? ? ? gimple_stmt_iterator gsi;
> @@ -1183,7 +1198,8 @@ execute_optimize_bswap (void)
> ? ? ? for (gsi = gsi_after_labels (bb); !gsi_end_p (gsi); gsi_next (&gsi))
> ? ? ? ? {
> ? ? ? ? ?gimple stmt = gsi_stmt (gsi);
> - ? ? ? ? tree bswap_src;
> + ? ? ? ? tree bswap_src, bswap_type;
> + ? ? ? ? tree bswap_tmp;
> ? ? ? ? ?tree fndecl = NULL_TREE;
> ? ? ? ? ?int type_size;
> ? ? ? ? ?gimple call;
> @@ -1198,11 +1214,17 @@ execute_optimize_bswap (void)
> ? ? ? ? ? ?{
> ? ? ? ? ? ?case 32:
> ? ? ? ? ? ? ?if (bswap32_p)
> - ? ? ? ? ? ? ? fndecl = built_in_decls[BUILT_IN_BSWAP32];
> + ? ? ? ? ? ? ? {
> + ? ? ? ? ? ? ? ? fndecl = built_in_decls[BUILT_IN_BSWAP32];
> + ? ? ? ? ? ? ? ? bswap_type = bswap32_type;
> + ? ? ? ? ? ? ? }
> ? ? ? ? ? ? ?break;
> ? ? ? ? ? ?case 64:
> ? ? ? ? ? ? ?if (bswap64_p)
> - ? ? ? ? ? ? ? fndecl = built_in_decls[BUILT_IN_BSWAP64];
> + ? ? ? ? ? ? ? {
> + ? ? ? ? ? ? ? ? fndecl = built_in_decls[BUILT_IN_BSWAP64];
> + ? ? ? ? ? ? ? ? bswap_type = bswap64_type;
> + ? ? ? ? ? ? ? }
> ? ? ? ? ? ? ?break;
> ? ? ? ? ? ?default:
> ? ? ? ? ? ? ?continue;
> @@ -1217,8 +1239,41 @@ execute_optimize_bswap (void)
> ? ? ? ? ? ?continue;
>
> ? ? ? ? ?changed = true;
> - ? ? ? ? call = gimple_build_call (fndecl, 1, bswap_src);
> - ? ? ? ? gimple_call_set_lhs (call, gimple_assign_lhs (stmt));
> +
> + ? ? ? ? bswap_tmp = bswap_src;
> +
> + ? ? ? ? /* Convert the src expression if necessary. ?*/
> + ? ? ? ? if (!useless_type_conversion_p (TREE_TYPE (bswap_tmp), bswap_type))
> + ? ? ? ? ? {
> + ? ? ? ? ? ? gimple convert_stmt;
> +
> + ? ? ? ? ? ? bswap_tmp = create_tmp_var (bswap_type, "bswapsrc");
> + ? ? ? ? ? ? add_referenced_var (bswap_tmp);
> + ? ? ? ? ? ? bswap_tmp = make_ssa_name (bswap_tmp, NULL);
> +
> + ? ? ? ? ? ? convert_stmt = gimple_build_assign_with_ops (
> + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?CONVERT_EXPR, bswap_tmp, bswap_src, NULL);
> + ? ? ? ? ? ? gsi_insert_before (&gsi, convert_stmt, GSI_SAME_STMT);
> + ? ? ? ? ? }
> +
> + ? ? ? ? call = gimple_build_call (fndecl, 1, bswap_tmp);
> +
> + ? ? ? ? bswap_tmp = gimple_assign_lhs (stmt);
> +
> + ? ? ? ? /* Convert the result if necessary. ?*/
> + ? ? ? ? if (!useless_type_conversion_p (TREE_TYPE (bswap_tmp), bswap_type))
> + ? ? ? ? ? {
> + ? ? ? ? ? ? gimple convert_stmt;
> +
> + ? ? ? ? ? ? bswap_tmp = create_tmp_var (bswap_type, "bswapdst");
> + ? ? ? ? ? ? add_referenced_var (bswap_tmp);
> + ? ? ? ? ? ? bswap_tmp = make_ssa_name (bswap_tmp, NULL);
> + ? ? ? ? ? ? convert_stmt = gimple_build_assign_with_ops (
> + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?CONVERT_EXPR, gimple_assign_lhs (stmt), bswap_tmp, NULL);
> + ? ? ? ? ? ? gsi_insert_after (&gsi, convert_stmt, GSI_SAME_STMT);
> + ? ? ? ? ? }
> +
> + ? ? ? ? gimple_call_set_lhs (call, bswap_tmp);
>
> ? ? ? ? ?if (dump_file)
> ? ? ? ? ? ?{
>


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