Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Common string constants elimination

highegg
Beginner
299 Views
Hello,
is there any optimization option I don't know about to merge duplicate string literals in the compiled code? Consider the simple test code:

subroutine test1(s1,s2)
character(*) s1,s2
write(0,101) s1,s2
101 format(a,', ',a)
end subroutine

subroutine test2()
call test1('hello','world')
call test1('goodbye','world')
call test1('hello','heaven')
end subroutine


whether compiled with ifort -O2, -O3 even -Os, the resulting object code
contains two instances of "hello" as well as "world".
Also, compiling to assembler shows that the three calls to test1 share no arguments (i.e. different strings are being referenced).

On the contrary, gfortran eliminates the duplicate literals even at -O0.
Of course, the same effect can be achieved by using named string constants, but I still reckon this is a fairly useful code size optimization.

Perhaps there is an option for this; If not, I can file an enhancement suggestion to Premier Support.

Thanks for comments
0 Kudos
3 Replies
Steven_L_Intel1
Employee
299 Views
There is no option for this. Feel free to submit a feature request for it.
0 Kudos
jimdempseyatthecove
Honored Contributor III
299 Views

Stick the strings in a module and decalre as a parameter. Then to global search and replace. This has the added benefit of using a different use file to change a language.

Jim Dempsey

0 Kudos
Steven_L_Intel1
Employee
299 Views
Back when I worked on VAX and Alpha compilers, constant pooling was a pretty standard thing to do, but memory sizes were smaller back then as well. Unless you have lots of copies of big strings, there's not really a measurable advantage to pooling, but I'll agree that it seems inelegant to not do so.
0 Kudos
Reply