Bug 60780 - Equivalence statements in nested modules results in fast growing duplicate statements in module files
Summary: Equivalence statements in nested modules results in fast growing duplicate st...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.8.2
: P3 normal
Target Milestone: 5.2
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-04-07 17:27 UTC by russelldub
Modified: 2015-06-05 20:42 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2014-04-09 00:00:00


Attachments
Code to reproduce issue. (298 bytes, text/plain)
2014-04-07 17:27 UTC, russelldub
Details

Note You need to log in before you can comment on or make changes to this bug.
Description russelldub 2014-04-07 17:27:25 UTC
Created attachment 32558 [details]
Code to reproduce issue.

Equivalence statements in equivalence statements results in quickly growing number of duplicated statements in nested module files.  The attached file shows the issue.  Compiled with
> gfortran equiv_mod.f90
Resulting module files grow from 3.1 kb to 128 kb.  (This issue is somewhat mitigated by compressing modules in latest gfortran, but duplicate statements still exist).  The fortran interface to HDF5 is affected by this.  In code that uses HDF5 in nested fashion module files can grow to multiple GB in size resulting in ICE when memory is exhausted.  May be related to pr 38171.

Reproduced in 4.4.7, 4.6.1, 4.8.2 and recent git clone.
Comment 1 russelldub 2014-04-07 17:41:15 UTC
> Equivalence statements in equivalence statements

Should read "Equivalence statements in modules".  Apologies.
Comment 2 Dominique d'Humieres 2014-04-09 08:27:44 UTC
> May be related to pr 38171.

Rather related to pr40958 comment 13.
Comment 3 russelldub 2014-10-08 01:57:16 UTC
Any hope for movement on this?  I've made some attempts at diagnosing the issue, but not sure why equivalences behave differently than other statements in the modules.
Comment 4 russelldub 2014-10-08 02:00:18 UTC
Any hope for movement on this?  I've made some attempts at diagnosing the issue, but not sure why equivalences behave differently than other statements in the modules.
Comment 5 Dominique d'Humieres 2015-03-09 10:22:26 UTC
I have doubled the number of modules to get the following results

gcc version 4.8.5

21.907u 0.994s 0:23.00 99.5%	0+0k 0+22io 3pf+0w

-rw-r--r-- 1 dominiq staff     2923 Mar  9 10:59  module0.mod
-rw-r--r-- 1 dominiq staff     3079 Mar  9 10:59  module1.mod
-rw-r--r-- 1 dominiq staff     4230 Mar  9 10:59  module2.mod
-rw-r--r-- 1 dominiq staff     6376 Mar  9 10:59  module3.mod
-rw-r--r-- 1 dominiq staff    10512 Mar  9 10:59  module4.mod
-rw-r--r-- 1 dominiq staff    18628 Mar  9 10:59  module5.mod
-rw-r--r-- 1 dominiq staff    34704 Mar  9 10:59  module6.mod
-rw-r--r-- 1 dominiq staff    66700 Mar  9 10:59  module7.mod
-rw-r--r-- 1 dominiq staff   130536 Mar  9 10:59  module8.mod
-rw-r--r-- 1 dominiq staff   258052 Mar  9 10:59  module9.mod
-rw-r--r-- 1 dominiq staff   512931 Mar  9 10:59 module10.mod
-rw-r--r-- 1 dominiq staff  1022530 Mar  9 10:59 module11.mod
-rw-r--r-- 1 dominiq staff  2041569 Mar  9 10:59 module12.mod
-rw-r--r-- 1 dominiq staff  4079488 Mar  9 10:59 module13.mod
-rw-r--r-- 1 dominiq staff  8155167 Mar  9 10:59 module14.mod
-rw-r--r-- 1 dominiq staff 16306366 Mar  9 10:59 module15.mod
-rw-r--r-- 1 dominiq staff 32608774 Mar  9 10:59 module16.mod

gcc version 4.9.3

5.432u 0.389s 0:06.00 96.8%	0+0k 8+19io 1355pf+0w

-rw-r--r-- 1 dominiq staff    485 Mar  9 11:03  module0.mod
-rw-r--r-- 1 dominiq staff    498 Mar  9 11:03  module1.mod
-rw-r--r-- 1 dominiq staff    526 Mar  9 11:03  module2.mod
-rw-r--r-- 1 dominiq staff    560 Mar  9 11:03  module3.mod
-rw-r--r-- 1 dominiq staff    602 Mar  9 11:03  module4.mod
-rw-r--r-- 1 dominiq staff    668 Mar  9 11:03  module5.mod
-rw-r--r-- 1 dominiq staff    770 Mar  9 11:03  module6.mod
-rw-r--r-- 1 dominiq staff    952 Mar  9 11:03  module7.mod
-rw-r--r-- 1 dominiq staff   1279 Mar  9 11:03  module8.mod
-rw-r--r-- 1 dominiq staff   1911 Mar  9 11:03  module9.mod
-rw-r--r-- 1 dominiq staff   3165 Mar  9 11:03 module10.mod
-rw-r--r-- 1 dominiq staff   5650 Mar  9 11:03 module11.mod
-rw-r--r-- 1 dominiq staff  10603 Mar  9 11:03 module12.mod
-rw-r--r-- 1 dominiq staff  20493 Mar  9 11:03 module13.mod
-rw-r--r-- 1 dominiq staff  40276 Mar  9 11:03 module14.mod
-rw-r--r-- 1 dominiq staff  79811 Mar  9 11:03 module15.mod
-rw-r--r-- 1 dominiq staff 158891 Mar  9 11:03 module16.mod

gcc version 5.0.0

5.525u 0.381s 0:06.06 97.3%	0+0k 9+23io 1605pf+0w

-rw-r--r-- 1 dominiq staff    485 Mar  9 11:07  module0.mod
-rw-r--r-- 1 dominiq staff    500 Mar  9 11:07  module1.mod
-rw-r--r-- 1 dominiq staff    529 Mar  9 11:07  module2.mod
-rw-r--r-- 1 dominiq staff    562 Mar  9 11:07  module3.mod
-rw-r--r-- 1 dominiq staff    606 Mar  9 11:07  module4.mod
-rw-r--r-- 1 dominiq staff    672 Mar  9 11:07  module5.mod
-rw-r--r-- 1 dominiq staff    774 Mar  9 11:07  module6.mod
-rw-r--r-- 1 dominiq staff    956 Mar  9 11:07  module7.mod
-rw-r--r-- 1 dominiq staff   1283 Mar  9 11:07  module8.mod
-rw-r--r-- 1 dominiq staff   1915 Mar  9 11:07  module9.mod
-rw-r--r-- 1 dominiq staff   3170 Mar  9 11:07 module10.mod
-rw-r--r-- 1 dominiq staff   5650 Mar  9 11:07 module11.mod
-rw-r--r-- 1 dominiq staff  10603 Mar  9 11:07 module12.mod
-rw-r--r-- 1 dominiq staff  20493 Mar  9 11:07 module13.mod
-rw-r--r-- 1 dominiq staff  40276 Mar  9 11:07 module14.mod
-rw-r--r-- 1 dominiq staff  79811 Mar  9 11:07 module15.mod
-rw-r--r-- 1 dominiq staff 158891 Mar  9 11:07 module16.mod

gcc version 5.0.0 with the patch in pr40958 comment 18

0.045u 0.034s 0:00.24 29.1%	0+0k 12+18io 1767pf+0w

-rw-r--r-- 1 dominiq staff  485 Mar  9 11:07  module0.mod
-rw-r--r-- 1 dominiq staff  500 Mar  9 11:07  module1.mod
-rw-r--r-- 1 dominiq staff  515 Mar  9 11:09  module2.mod
-rw-r--r-- 1 dominiq staff  527 Mar  9 11:09  module3.mod
-rw-r--r-- 1 dominiq staff  539 Mar  9 11:09  module4.mod
-rw-r--r-- 1 dominiq staff  552 Mar  9 11:09  module5.mod
-rw-r--r-- 1 dominiq staff  567 Mar  9 11:09  module6.mod
-rw-r--r-- 1 dominiq staff  578 Mar  9 11:09  module7.mod
-rw-r--r-- 1 dominiq staff  590 Mar  9 11:09  module8.mod
-rw-r--r-- 1 dominiq staff  603 Mar  9 11:09  module9.mod
-rw-r--r-- 1 dominiq staff  621 Mar  9 11:09 module10.mod
-rw-r--r-- 1 dominiq staff  632 Mar  9 11:09 module11.mod
-rw-r--r-- 1 dominiq staff  647 Mar  9 11:09 module12.mod
-rw-r--r-- 1 dominiq staff  663 Mar  9 11:09 module13.mod
-rw-r--r-- 1 dominiq staff  677 Mar  9 11:09 module14.mod
-rw-r--r-- 1 dominiq staff  692 Mar  9 11:09 module15.mod
-rw-r--r-- 1 dominiq staff  728 Mar  9 11:09 module16.mod

Without the patch the module sizes double each time a module is added (asymptotic behavior) while the prefactor for 4.9 and 5.0 is ~200 smaller compared to 4.8. With the patch, the compile time is negligible and the module sizes increase is quite small (linear?).

May be the patch should be submitted to fortran@gcc.gnu.org (for next stage1).
Comment 6 Jerry DeLisle 2015-03-09 18:49:06 UTC
The patch for 40958 is simple enough that we may be able to just commit it to trunk.  Fortran is not release critical.  With the patch do we have any problems with known large code bases like CP2K?

Is 40958 a duplicate of this PR or is there something else lurking?
Comment 7 Dominique d'Humieres 2015-03-09 18:57:05 UTC
> Is 40958 a duplicate of this PR or is there something else lurking?

AFAIU pr40958 comment 13, Janne was anticipating possible exponential behaviors from a rather theoretical point of view. This PR is an instance of such exponential behavior.

IMO pr40958 should be closed and new PRs for exponential behavior opened when new instances are found.
Comment 8 russelldub 2015-03-11 05:12:35 UTC
> May be the patch should be submitted to fortran@gcc.gnu.org (for next stage1).

I'd be happy if this could be resolved.  Should I submit or someone with more clout among the gfortran maintainers/developers?
Comment 9 kargls 2015-06-05 16:55:25 UTC
Author: kargl
Date: Fri Jun  5 16:54:53 2015
New Revision: 224159

URL: https://gcc.gnu.org/viewcvs?rev=224159&root=gcc&view=rev
Log:
2015-06-03  Russell Whitesides  <russelldub@gmail.com>
	    Steven G. Kargl  <kargl@gcc.gnu.org>

	PR fortran/40958
	PR fortran/60780
	PR fortran/66377
	* module.c (load_equiv): Add check for loading duplicate EQUIVALENCEs
	from different modules.  Eliminate the pruning of unused
	equivalence-objects


2015-06-03  Steven G. Kargl  <kargl@gcc.gnu.org>

	PR fortran/66377
	gfortran.dg/equiv_9.f90: New test.

Added:
    trunk/gcc/testsuite/gfortran.dg/equiv_9.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/module.c
    trunk/gcc/testsuite/ChangeLog
Comment 10 kargls 2015-06-05 20:41:07 UTC
Author: kargl
Date: Fri Jun  5 20:40:35 2015
New Revision: 224171

URL: https://gcc.gnu.org/viewcvs?rev=224171&root=gcc&view=rev
Log:
2015-06-03  Russell Whitesides  <russelldub@gmail.com>
	    Steven G. Kargl  <kargl@gcc.gnu.org>

	PR fortran/40958
	PR fortran/60780
	PR fortran/66377
	* module.c (load_equiv): Add check for loading duplicate EQUIVALENCEs
	from different modules.  Eliminate the pruning of unused
	equivalence-objects


2015-06-03  Steven G. Kargl  <kargl@gcc.gnu.org>

	PR fortran/66377
	gfortran.dg/equiv_9.f90: New test.


Added:
    branches/gcc-5-branch/gcc/testsuite/gfortran.dg/equiv_9.f90
Modified:
    branches/gcc-5-branch/gcc/fortran/ChangeLog
    branches/gcc-5-branch/gcc/fortran/module.c
    branches/gcc-5-branch/gcc/testsuite/ChangeLog
Comment 11 kargls 2015-06-05 20:42:14 UTC
Fixed on trunk and 5-branch.  Thanks for the PR and patch.