From: Mikael Morin <mikael.morin@sfr.fr>
To: Thomas Koenig <tkoenig@netcologne.de>
Cc: "fortran@gcc.gnu.org" <fortran@gcc.gnu.org>,
gcc-patches <gcc-patches@gcc.gnu.org>
Subject: Re: [patch, Fortran] PR 55806 - Inefficient ANY with array constructors
Date: Mon, 14 Jan 2013 13:29:00 -0000 [thread overview]
Message-ID: <50F4083E.30902@sfr.fr> (raw)
In-Reply-To: <50F331C8.2000200@netcologne.de>
Le 13/01/2013 23:14, Thomas Koenig a écrit :
> Hi Mikael,
>
> thanks a lot for your comments!
>
>>> + actual_arglist->expr = gfc_copy_expr (e); +
>>> actual_arglist->next = gfc_get_actual_arglist ();
>> Another one is needed. I get a segmentation fault with SUM.
>
> Fixed by using gfc_build_intrisic_call.
Nice.
>
> Updated test case and patch attached.
> Index: frontend-passes.c
> ===================================================================
> --- frontend-passes.c (Revision 195136)
> +++ frontend-passes.c (Arbeitskopie)
[...]
> + else if (id == GFC_ISYM_ANY || id == GFC_ISYM_ALL)
> + fcn = gfc_build_intrinsic_call (current_ns,
> + fn->value.function.isym->id,
> + fn->value.function.isym->name,
> + fn->where, 2, gfc_copy_expr (e),
> + NULL);
> + else
> + gfc_error ("Illegal id in copy_walk_reduction_arg");
This is not very useful for a user. It should be an internal error (or
gcc_unreachable would do as well).
> +
> +/* Callback function for optimzation of reductions to scalars. Transform ANY
> + ([f1,f2,f3, ...]) to f1 .or. f2 .or. f3 .or. ..., with ANY, SUM and PRODUCT
> + correspondingly. Handly only the simple cases without MASK and DIM. */
> +
> +static int
> +callback_reduction (gfc_expr **e, int *walk_subtrees ATTRIBUTE_UNUSED,
> + void *data ATTRIBUTE_UNUSED)
> +{
> + gfc_expr *fn, *arg;
> + gfc_intrinsic_op op;
> + gfc_isym_id id;
> + gfc_actual_arglist *a;
> + gfc_actual_arglist *dim;
> + gfc_constructor *c;
> + gfc_expr *res, *new_expr;
> + gfc_actual_arglist *mask;
> +
> + fn = *e;
> +
> + if (fn->rank != 0 || fn->expr_type != EXPR_FUNCTION
> + || fn->value.function.isym == NULL)
> + return 0;
> +
> + id = fn->value.function.isym->id;
> +
> + if (id != GFC_ISYM_SUM && id != GFC_ISYM_PRODUCT
> + && id != GFC_ISYM_ANY && id != GFC_ISYM_ALL)
> + return 0;
> +
> + a = fn->value.function.actual;
> +
> + /* Don't handle MASK or DIM. */
> +
> + dim = a->next;
> +
> + if (dim->expr != NULL)
> + return 0;
> +
Trailing whitespace.
> + mask = dim->next;
> + if (mask != NULL)
> + if ( mask->expr != NULL)
> + return 0;
This is a bit confusing as mask is the first argument in the ANY/ALL
case. You can use something like this instead:
if (id == GFC_ISYM_SUM || id == GFC_ISYM_PRODUCT)
{
mask = dim->next;
if (mask->expr != NULL)
return 0;
}
>
> OK for trunk?
>
OK with the changes suggested above. Thanks.
Mikael
next prev parent reply other threads:[~2013-01-14 13:29 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-01-01 20:18 Thomas Koenig
2013-01-06 16:33 ` Thomas Koenig
2013-01-08 23:16 ` *ping* " Thomas Koenig
2013-01-11 19:53 ` Mikael Morin
2013-01-13 22:14 ` Thomas Koenig
2013-01-14 13:29 ` Mikael Morin [this message]
2013-01-14 21:51 ` Thomas Koenig
2017-11-02 10:27 ` Bernhard Reutner-Fischer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=50F4083E.30902@sfr.fr \
--to=mikael.morin@sfr.fr \
--cc=fortran@gcc.gnu.org \
--cc=gcc-patches@gcc.gnu.org \
--cc=tkoenig@netcologne.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).