Bug 14771 - frontend doesn't record parentheses
Summary: frontend doesn't record parentheses
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: tree-ssa
: P2 normal
Target Milestone: 4.1.0
Assignee: Tobias Schlüter
URL:
Keywords: accepts-invalid, missed-optimization, wrong-code
: 20894 25048 (view as bug list)
Depends on:
Blocks: 14741 20894 25048
  Show dependency treegraph
 
Reported: 2004-03-29 16:25 UTC by Tobias Schlüter
Modified: 2006-02-12 18:32 UTC (History)
3 users (show)

See Also:
Host: all
Target: all
Build: all
Known to work:
Known to fail:
Last reconfirmed: 2006-02-09 15:24:09


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Schlüter 2004-03-29 16:25:12 UTC
gfortran parses
 c = a + b + c
as 
 (assign c (+ (+ a b) c))
which is the same parse tree as for
 c = (a + b) + c

Fortran allows a greater range of optimizations in the former case, but since it
is unable to distinguish between those two cases, the former case may be
unnecessarily pessimized by optimizers.

I have a patch to the parser and parse-tree dumper which makes gfortran record
the parentheses. It is covered by my copyright assignment to g95 as I prepared
the patch in Oct 2002. Since I have no copyright assignment for gcc I'm not sure
if I can update it for the current sources (mostly formatting and function name
changes) without running into copyright trouble. Therefore I point you to my old
patch, which I reposted to the gfortran list:
http://gcc.gnu.org/ml/fortran/2004-03/msg00048.html with the matchexp.c part
replaced by the patch from http://gcc.gnu.org/ml/fortran/2004-03/msg00046.html

The original postings on g95-develop@lists.sourceforge.net can be found in the
thread following this posting:
http://www.geocrawler.com/archives/3/3588/2002/10/50/9910846/
Comment 1 Tobias Schlüter 2004-03-29 16:26:39 UTC
(In reply to comment #0)
> Fortran allows a greater range of optimizations in the former case, but since it
> is unable to distinguish between those two cases, the former case may be
> unnecessarily pessimized by optimizers.

"it" refers to gfortran, not Fortran. Sorry for being unclear.
Comment 2 Andrew Pinski 2004-03-29 16:33:50 UTC
Confirmed, I thought I saw a dup of this bug somewhere.
Comment 3 Tobias Schlüter 2004-04-12 17:29:09 UTC
changed subject line to the canonical form
Comment 4 Tobias Schlüter 2004-04-21 15:58:11 UTC
I have updated my patch, copyright assignment is in the works. No need for
anyone to work on this.
Comment 5 Andrew Pinski 2004-05-30 04:44:16 UTC
*** Bug 14741 has been marked as a duplicate of this bug. ***
Comment 6 Tobias Schlüter 2005-04-11 00:06:34 UTC
Not recording parentheses does have correctness implications, see this thread:
http://gcc.gnu.org/ml/fortran/2005-04/msg00302.html

Upgrading the bug status accordingly.  Looks like I have to revive my patch
sometime soon.
Comment 7 Francois-Xavier Coudert 2006-02-08 21:51:36 UTC
(In reply to comment #4)
> I have updated my patch, copyright assignment is in the works. No need for
> anyone to work on this.

Hum, Tobias, any news on that one? :)
Comment 8 Tobias Schlüter 2006-02-08 21:59:35 UTC
I'll try to get to it in the next few days, it shouldn't be too hard.
Comment 9 Tobias Schlüter 2006-02-09 15:24:09 UTC
For the record, Walt Brainerd's testcase from #6 is as follows:
      PROGRAM fc107

! Submitted by Walt Brainerd, The Fortran Company
! GNU Fortran 95 (GCC 4.1.0 20050322 (experimental))
! Windows XP

! Output should be 3

! Output is 999

      INTEGER I
      INTEGER TRYME
      I = 3
      print *, tryme((i),i)
      END

      INTEGER FUNCTION TRYME(RTNME,HITME)
      INTEGER RTNME,HITME
      HITME = 999
      TRYME = RTNME
      END

This together with PR20894 and PR25048 is fixed by a patch I'm about to send, once I've finished ChangeLogs and testcases.
Comment 10 Tobias Schlüter 2006-02-09 15:25:33 UTC
*** Bug 20894 has been marked as a duplicate of this bug. ***
Comment 11 Tobias Schlüter 2006-02-09 15:55:11 UTC
Adding Walt Brainerd, as requested in <http://gcc.gnu.org/ml/fortran/2005-04/msg00344.html>.

Patch posted here: <http://gcc.gnu.org/ml/fortran/2006-02/msg00172.html>
Comment 12 Tobias Schlüter 2006-02-09 16:00:24 UTC
*** Bug 25048 has been marked as a duplicate of this bug. ***
Comment 13 Tobias Schlüter 2006-02-10 00:10:52 UTC
Subject: Bug 14771

Author: tobi
Date: Fri Feb 10 00:10:47 2006
New Revision: 110819

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=110819
Log:
fortran/
2006-02-09  Tobias Schlueter  <tobias.schlueter@physik.uni-muenchen.de>

        PR fortran/14771
        * gfortran.h (gfc_intrinsic_op): Add INTRINSIC_PARENTHESES.
        * dump-parse-tree (gfc_show_expr): Handle INTRINSIC_PARENTHESES.
        * expr.c (simplify_intrinsic_op): Treat INTRINSIC_PARENTHESES as
        if it were INTRINSIC_UPLUS.
        * resolve.c (resolve_operator): Handle INTRINSIC_PARENTHESES.
        * match.c (intrinsic_operators): Add INTRINSIC_PARENTHESES.
        * matchexp.c (match_primary): Record parentheses surrounding
        numeric expressions.
        * module.c (intrinsics): Add INTRINSIC_PARENTHESES for module
        dumping.
        * trans-expr.c (gfc_conv_expr_op): Handle INTRINSIC_PARENTHESES.

testsuite/
2006-02-09  Tobias Schlueter  <tobias.schlueter@physik.uni-muenchen.de>
        Paul Thomas  <pault@gcc.gnu.org>

        PR fortran/14771
        * gfortran.dg/parens_1.f90: New.
        * gfortran.dg/parens_2.f90: New.
        * gfortran.dg/parens_3.f90: New.



Added:
    trunk/gcc/testsuite/gfortran.dg/parens_1.f90
    trunk/gcc/testsuite/gfortran.dg/parens_2.f90
    trunk/gcc/testsuite/gfortran.dg/parens_3.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/dump-parse-tree.c
    trunk/gcc/fortran/expr.c
    trunk/gcc/fortran/gfortran.h
    trunk/gcc/fortran/match.c
    trunk/gcc/fortran/matchexp.c
    trunk/gcc/fortran/module.c
    trunk/gcc/fortran/resolve.c
    trunk/gcc/fortran/trans-expr.c
    trunk/gcc/testsuite/ChangeLog

Comment 14 Tobias Schlüter 2006-02-10 18:08:31 UTC
Subject: Bug 14771

Author: tobi
Date: Fri Feb 10 18:08:27 2006
New Revision: 110840

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=110840
Log:
fortran/
	PR fortran/14771
	* arith.c (eval_intrinsic): Accept INTRINSIC_PARENTHESES.
	* expr.c (check_intrinsic_op): Likewise.
	* module.c (mio_expr): Likewise.
testsuite/
	PR fortran/14771
	* gfortran.dg/parens_4.f90: New.
	* gfortran.dg/parens_5.f90: New.


Added:
    trunk/gcc/testsuite/gfortran.dg/parens_4.f90
    trunk/gcc/testsuite/gfortran.dg/parens_5.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/arith.c
    trunk/gcc/fortran/expr.c
    trunk/gcc/fortran/module.c
    trunk/gcc/testsuite/ChangeLog

Comment 15 Tobias Schlüter 2006-02-12 18:31:43 UTC
Subject: Bug 14771

Author: tobi
Date: Sun Feb 12 18:31:40 2006
New Revision: 110894

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=110894
Log:
fortran/
        Backport r110819 and r110840 from the trunk
        PR fortran/14771
        * gfortran.h (gfc_intrinsic_op): Add INTRINSIC_PARENTHESES.
        * dump-parse-tree (gfc_show_expr): Handle INTRINSIC_PARENTHESES.
        * expr.c (simplify_intrinsic_op): Treat INTRINSIC_PARENTHESES as
        if it were INTRINSIC_UPLUS.
        * resolve.c (resolve_operator): Handle INTRINSIC_PARENTHESES.
        * match.c (intrinsic_operators): Add INTRINSIC_PARENTHESES.
        * matchexp.c (match_primary): Record parentheses surrounding
        numeric expressions.
        * module.c (intrinsics): Add INTRINSIC_PARENTHESES for module
        dumping.
        * trans-expr.c (gfc_conv_expr_op): Handle INTRINSIC_PARENTHESES.

        PR fortran/14771
        * arith.c (eval_intrinsic): Accept INTRINSIC_PARENTHESES.
        * expr.c (check_intrinsic_op): Likewise.
        * module.c (mio_expr): Likewise.
testsuite/
        Backport r110819 and r110840 from the trunk
        PR fortran/14771
        * gfortran.dg/parens_1.f90: New.
        * gfortran.dg/parens_2.f90: New.
        * gfortran.dg/parens_3.f90: New.
        * gfortran.dg/parens_4.f90: New.
        * gfortran.dg/parens_5.f90: New.


Added:
    branches/gcc-4_1-branch/gcc/testsuite/gfortran.dg/parens_1.f90
      - copied unchanged from r110819, trunk/gcc/testsuite/gfortran.dg/parens_1.f90
    branches/gcc-4_1-branch/gcc/testsuite/gfortran.dg/parens_2.f90
      - copied unchanged from r110819, trunk/gcc/testsuite/gfortran.dg/parens_2.f90
    branches/gcc-4_1-branch/gcc/testsuite/gfortran.dg/parens_3.f90
      - copied unchanged from r110819, trunk/gcc/testsuite/gfortran.dg/parens_3.f90
    branches/gcc-4_1-branch/gcc/testsuite/gfortran.dg/parens_4.f90
      - copied unchanged from r110840, trunk/gcc/testsuite/gfortran.dg/parens_4.f90
    branches/gcc-4_1-branch/gcc/testsuite/gfortran.dg/parens_5.f90
      - copied unchanged from r110840, trunk/gcc/testsuite/gfortran.dg/parens_5.f90
Modified:
    branches/gcc-4_1-branch/gcc/fortran/ChangeLog
    branches/gcc-4_1-branch/gcc/fortran/arith.c
    branches/gcc-4_1-branch/gcc/fortran/dump-parse-tree.c
    branches/gcc-4_1-branch/gcc/fortran/expr.c
    branches/gcc-4_1-branch/gcc/fortran/gfortran.h
    branches/gcc-4_1-branch/gcc/fortran/match.c
    branches/gcc-4_1-branch/gcc/fortran/matchexp.c
    branches/gcc-4_1-branch/gcc/fortran/module.c
    branches/gcc-4_1-branch/gcc/fortran/resolve.c
    branches/gcc-4_1-branch/gcc/fortran/trans-expr.c
    branches/gcc-4_1-branch/gcc/testsuite/ChangeLog

Comment 16 Tobias Schlüter 2006-02-12 18:32:46 UTC
Fixed.