diff mbox

[fortran] Some more TRIM optimizations

Message ID 4DED2982.2060802@netcologne.de
State New
Headers show

Commit Message

Thomas Koenig June 6, 2011, 7:24 p.m. UTC
I wrote:

> Hello world,
>
> the attached patch extends removing trailing TRIMs in assignments for
> cases like a // trim(b). Regression-tested. OK for trunk?
>
> Thomas

This time with the test case corrected (cleanup of the *.original file)
and a more meaningful Subject line.

OK?

	Thomas

2011-05-06  Thomas König  <tkoenig@gcc.gnu.org>

         * frontend-passes.c (optimize_assignment): Follow chains
         of concatenation operators to the end for removing trailing
         TRIMS for assignments.

2011-05-06  Thomas König  <tkoenig@gcc.gnu.org>

         * gfortran.dg/trim_optimize_7.f90:  New test.
! { dg-do run }
! { dg-options "-O -fdump-tree-original" }
! Check that trailing trims are also removed from assignment of
! expressions involving concatenations of strings .
program main
  character(2) :: a,b,c
  character(8) :: d
  a = 'a '
  b = 'b '
  c = 'c '
  d = a // b // a // trim(c)   ! This should be optimized away.
  if (d /= 'a b a c ') call abort
  d = a // trim(b) // c // a   ! This shouldn't.
  if (d /= 'a bc a  ') call abort
  d = a // b // a // trim(trim(c)) ! This should also be optimized away.
  if (d /= 'a b a c ') call abort
end
! { dg-final { scan-tree-dump-times "string_len_trim" 1 "original" } }
! { dg-final { cleanup-tree-dump "original" } }

Comments

Thomas Koenig June 10, 2011, 5:08 p.m. UTC | #1
I wrote:

>
>> Hello world,
>>
>> the attached patch extends removing trailing TRIMs in assignments for
>> cases like a // trim(b). Regression-tested. OK for trunk?
>>
>> Thomas
>
> This time with the test case corrected (cleanup of the *.original file)
> and a more meaningful Subject line.
>
> OK?

Ping ** 0.5714

Full patch can be found at

http://gcc.gnu.org/ml/fortran/2011-06/msg00053.html

	Thomas
Jerry DeLisle June 10, 2011, 5:39 p.m. UTC | #2
On 06/10/2011 10:08 AM, Thomas Koenig wrote:
> I wrote:
>
>>
>>> Hello world,
>>>
>>> the attached patch extends removing trailing TRIMs in assignments for
>>> cases like a // trim(b). Regression-tested. OK for trunk?
>>>
>>> Thomas
>>
>> This time with the test case corrected (cleanup of the *.original file)
>> and a more meaningful Subject line.
>>
>> OK?
>
> Ping ** 0.5714
>
> Full patch can be found at
>
> http://gcc.gnu.org/ml/fortran/2011-06/msg00053.html

OK and thanks for patch.

Jerry
Thomas Koenig June 11, 2011, 8:23 a.m. UTC | #3
Hi Jerry,

>
>> Ping ** 0.5714
>>
>> Full patch can be found at
>>
>> http://gcc.gnu.org/ml/fortran/2011-06/msg00053.html
>
> OK and thanks for patch.

Sending        fortran/ChangeLog
Sending        fortran/frontend-passes.c
Sending        testsuite/ChangeLog
Adding         testsuite/gfortran.dg/trim_optimize_7.f90
Transmitting file data ....
Committed revision 174944.

Thanks for the review!

	Thomas
diff mbox

Patch

Index: frontend-passes.c
===================================================================
--- frontend-passes.c	(Revision 174391)
+++ frontend-passes.c	(Arbeitskopie)
@@ -500,6 +500,14 @@  optimize_assignment (gfc_code * c)
 
   if (lhs->ts.type == BT_CHARACTER)
     {
+      /* Check for a // b // trim(c).  Looping is probably not
+	 necessary because the parser usually generates
+	 (// (// a b ) trim(c) ) , but better safe than sorry.  */
+
+      while (rhs->expr_type == EXPR_OP
+	     && rhs->value.op.op == INTRINSIC_CONCAT)
+	rhs = rhs->value.op.op2;
+
       if (rhs->expr_type == EXPR_FUNCTION &&
 	  rhs->value.function.isym &&
 	  rhs->value.function.isym->id == GFC_ISYM_TRIM)