* [patch, fortran]
@ 2011-06-05 21:00 Thomas Koenig
2011-06-06 19:25 ` [patch, fortran] Some more TRIM optimizations Thomas Koenig
0 siblings, 1 reply; 5+ messages in thread
From: Thomas Koenig @ 2011-06-05 21:00 UTC (permalink / raw)
To: fortran, gcc-patches
[-- Attachment #1: Type: text/plain, Size: 445 bytes --]
Hello world,
the attached patch extends removing trailing TRIMs in assignments for
cases like a // trim(b). Regression-tested. OK for trunk?
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.
[-- Attachment #2: p1.diff --]
[-- Type: text/x-patch, Size: 695 bytes --]
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)
[-- Attachment #3: trim_optimize_7.f90 --]
[-- Type: text/plain, Size: 628 bytes --]
! { 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" } }
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [patch, fortran] Some more TRIM optimizations
2011-06-05 21:00 [patch, fortran] Thomas Koenig
@ 2011-06-06 19:25 ` Thomas Koenig
2011-06-10 17:27 ` Thomas Koenig
0 siblings, 1 reply; 5+ messages in thread
From: Thomas Koenig @ 2011-06-06 19:25 UTC (permalink / raw)
To: fortran, gcc-patches
[-- Attachment #1: Type: text/plain, Size: 617 bytes --]
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.
[-- Attachment #2: p1.diff --]
[-- Type: text/x-patch, Size: 695 bytes --]
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)
[-- Attachment #3: trim_optimize_7.f90 --]
[-- Type: text/plain, Size: 676 bytes --]
! { 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" } }
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2011-06-11 8:24 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-06-05 21:00 [patch, fortran] Thomas Koenig
2011-06-06 19:25 ` [patch, fortran] Some more TRIM optimizations Thomas Koenig
2011-06-10 17:27 ` Thomas Koenig
2011-06-10 17:52 ` jerry DeLisle
2011-06-11 10:06 ` Thomas Koenig
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).