[patch, fortran] Move expressions from the mask in a forall header
Thomas Koenig
tkoenig@netcologne.de
Sun Aug 17 11:49:00 GMT 2014
Hello world,
this patch moves expressions which do not depend on the
index variable(s) from FORALL headers (which also includes
DO CONCURRENT).
For the test case in do_concurrent_4.f90,
do concurrent(i=1:n, a(i)>sum(a)/n)
a(i) = a(i) * 0.5
end do
Without the patch, this gets translated in a
straightforward manner to
DO CONCURRENT main:i 1:10:1(> main:a(main:i) (/
_gfortran_sum_r4[[((main:a(FULL)) ((arg not-present)) ((arg
not-present)))]] 1.00000000e1))
ASSIGN main:a(main:i) (* main:a(main:i) 5.00000000e-1) END DO
With the patch and with front-end optimization on, this becomes
ASSIGN block@7:__var_1 (/ _gfortran_sum_r4[[((main:a(FULL)) ((arg
not-present)) ((arg not-present)))]] 1.00000000e1)
DO CONCURRENT main:i 1:10:1(> main:a(main:i) block@7:__var_1)
ASSIGN main:a(main:i) (* main:a(main:i) 5.00000000e-1) END DO
There is one fine point regarding the part of the patch used to check
if an expression is identical to the loop variable:
+ se = (*e)->symtree;
+
+ if (se == NULL)
+ return 0;
+
+ for (fa = (*current_code)->ext.forall_iterator; fa;
+ fa = fa->next)
+ {
+ if (se == fa->var->symtree)
+ return 1;
+ }
+ return 0;
Originally, this was
+ se = (*e)->symtree->n.sym;
+
+ for (fa = (*current_code)->ext.forall_iterator; fa; fa = fa->next)
+ {
+ si = fa->var->symtree->n.sym;
+ if (si == se)
+ return 1;
+ }
+
but this caused a regression in forall_5.f90 when
fa->var->symtree held the address 0x04 (which only
occurred when running the test suite). I could not
figure out where this strange value was being generated,
so I setteled for comparing the symtree address instead
(and adding a NULL check just in case :-)
Regression-tested. OK for trunk?
Regards
Thomas
2014-08-17 Thomas Koenig <tkoeng@gcc.gnu.org>
PR fortran/60661
* frontend-passes.c (optimize_forall_header): Add prototype,
new function.
(optimize_code): Call optimize_forall_header.
(concurrent_iterator_check): New function.
(forall_header_varmove): New function.
2014-08-17 Thomas Koenig <tkoeng@gcc.gnu.org>
PR fortran/60661
* gfortran.dg/do_concurrent_4.f90: New test.
* gfortran.dg/do_concurrent_5.f90: New test.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: p7.diff
Type: text/x-patch
Size: 2288 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20140817/b2245083/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: do_concurrent_4.f90
Type: text/x-fortran
Size: 595 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20140817/b2245083/attachment-0001.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: do_concurrent_5.f90
Type: text/x-fortran
Size: 609 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20140817/b2245083/attachment-0002.bin>
More information about the Fortran
mailing list