Bug 40628 - Assignment using "= trim(string)": Optimize "trim" away
Summary: Assignment using "= trim(string)": Optimize "trim" away
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.5.0
: P3 normal
Target Milestone: ---
Assignee: Thomas Koenig
URL: http://gcc.gnu.org/ml/gcc-patches/201...
Keywords: missed-optimization, patch
Depends on:
Blocks:
 
Reported: 2009-07-03 07:15 UTC by Tobias Burnus
Modified: 2010-07-25 19:37 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2010-06-18 21:12:29


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Burnus 2009-07-03 07:15:53 UTC
In assignments, such as
  string = trim(string)
  string(n1:n2) = trim(string)
the trim has no effect and can be optimized away.

(Note: With Fortran 2003 and allocatable strings with "len=:", the first version cannot be optimized as on length mismatch the LHS is reallocated.)

Such code can easily be present in real-world code and causes unnecessarily a large overhead, cf. e.g. http://www.tddft.org/trac/octopus/changeset/5672
Comment 1 Thomas Koenig 2010-06-18 21:12:28 UTC
Mine.
Comment 2 Tobias Burnus 2010-06-18 21:19:30 UTC
In the link, one also finds
  trim(str1) == trim(str2)
Comment 3 Thomas Koenig 2010-07-25 19:31:53 UTC
Subject: Bug 40628

Author: tkoenig
Date: Sun Jul 25 19:31:37 2010
New Revision: 162519

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=162519
Log:
2010-07-25  Thomas Koenig  <tkoenig@gcc.gnu.org>

	PR fortran/40628
	* Make-lang.in:  Add fortran/frontend-passes.o.
	* gfortran.h:  Add prototype for gfc_run_passes.
	* resolve.c (gfc_resolve):  Call gfc_run_passes.
	* frontend-passes.c:  New file.

2010-07-25  Thomas Koenig  <tkoenig@gcc.gnu.org>

	PR fortran/40628
	* trim_optimize_1.f90:  New test.
	* character_comparision_1.f90:  New test.


Added:
    trunk/gcc/fortran/frontend-passes.c
    trunk/gcc/testsuite/gfortran.dg/character_comparison_1.f90
    trunk/gcc/testsuite/gfortran.dg/trim_optimize_1.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/Make-lang.in
    trunk/gcc/fortran/gfortran.h
    trunk/gcc/fortran/resolve.c
    trunk/gcc/testsuite/ChangeLog

Comment 4 Thomas Koenig 2010-07-25 19:37:30 UTC
Fixed on trunk.  Closing.