[PATCH] PR fortran/31593: Speed up loops with DO variables as procedure arguments
Tobias Schlüter
tobias.schlueter@physik.uni-muenchen.de
Mon Aug 24 21:45:00 GMT 2009
Steven Bosscher wrote:
> 2009/8/24 Tobias Schlüter <tobias.schlueter@physik.uni-muenchen.de>:
>> diff -r 395e36e913de gcc/fortran/trans-stmt.c
>
> Patches are often a bit more readable if you use diff -p (shows the
> function you're patching)...
I've not yet managed to teach mercurial that bit, but I'll look again.
It makes ChangeLog writing harder as well :)
>> --- a/gcc/fortran/trans-stmt.c Sun Aug 23 18:13:56 2009 +0000
>> +++ b/gcc/fortran/trans-stmt.c Mon Aug 24 21:43:32 2009 +0200
>> @@ -756,6 +756,49 @@
>> }
>>
>>
>
> Comment here to explain what you are doing (stack of DO loop vars) and
> why (show the transformations you intend to do)?
>
>> +typedef struct do_var_stack {
>> + struct do_var_stack *prev;
>> + gfc_symbol *sym;
>> +} do_var_stack;
>> +
>> +static do_var_stack *dvs_top = NULL;
>> +
>> +
>> +static void
>> +push_do_var (gfc_symbol *s)
>
> Comment before the function please. Same for pop_do_var() and gfc_is_do_var()
Sorry, yes, will do. I didn't write them, when I wrote this originally,
and forgot when I warmed the patch up.
>> +{
>> + do_var_stack *p
>> + = (do_var_stack *)gfc_getmem(sizeof(do_var_stack));
>
> Since you're putting them on a stack -- why not use an obstack of
> objects instead? See obstack examples throughout the middle-end.
I'll have a look, I take it that I could just search linearly instead of
traversing a linked list?
> Ah, you explained it here. Maybe just point to here from the other site.
I thought about that, but I thought that other optimizations may come to
our collective minds.
>> + if (gfc_is_do_var (expr->symtree->n.sym)
>> + && !expr->symtree->n.sym->attr.target)
>
> I would put the TARGET check before the gfc_is_do_var() check.
Makes sense.
> This patch speeds up one of my toy codes by ~12%. Nice :-)
Heh, I'm afraid that it only speeds up toy code, Thomas's contrived
example gains some 40%.
Cheers,
- Tobi
More information about the Fortran
mailing list