diff options
author | Thomas Koenig <tkoenig@gcc.gnu.org> | 2011-06-11 08:22:35 +0000 |
---|---|---|
committer | Thomas Koenig <tkoenig@gcc.gnu.org> | 2011-06-11 08:22:35 +0000 |
commit | b5ee9d1c0d9955335e7d8a0cf7653f44d0afb2ab (patch) | |
tree | fde0740af1e7c95d4eb70f492675b55b2699317c | |
parent | 891daafaf87384c823ff5186562e5132f246a9e4 (diff) | |
download | gcc-b5ee9d1c0d9955335e7d8a0cf7653f44d0afb2ab.zip gcc-b5ee9d1c0d9955335e7d8a0cf7653f44d0afb2ab.tar.gz gcc-b5ee9d1c0d9955335e7d8a0cf7653f44d0afb2ab.tar.bz2 |
frontend-passes.c (optimize_assignment): Follow chains of concatenation operators to the end for removing trailing TRIMS...
2011-05-11 Thomas Koenig <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-11 Thomas Koenig <tkoenig@gcc.gnu.org>
* gfortran.dg/trim_optimize_7.f90: New test.
From-SVN: r174944
-rw-r--r-- | gcc/fortran/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/fortran/frontend-passes.c | 8 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 4 | ||||
-rw-r--r-- | gcc/testsuite/gfortran.dg/trim_optimize_7.f90 | 19 |
4 files changed, 37 insertions, 0 deletions
diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index dbfaa7c..ac9f3ca 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,9 @@ +2011-05-11 Thomas Koenig <tkoenig@gcc.gnu.org> + + * frontend-passes.c (optimize_assignment): Follow chains + of concatenation operators to the end for removing trailing + TRIMS for assignments. + 2011-06-10 Daniel Carrera <dcarrera@gmail.com> * trans-decl.c (gfc_build_builtin_function_decls): diff --git a/gcc/fortran/frontend-passes.c b/gcc/fortran/frontend-passes.c index f100e1f..d1cc229 100644 --- a/gcc/fortran/frontend-passes.c +++ b/gcc/fortran/frontend-passes.c @@ -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) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index ffbc9f3..f34cf19 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2011-05-11 Thomas Koenig <tkoenig@gcc.gnu.org> + + * gfortran.dg/trim_optimize_7.f90: New test. + 2011-06-10 Wei Guozhi <carrot@google.com> PR target/45335 diff --git a/gcc/testsuite/gfortran.dg/trim_optimize_7.f90 b/gcc/testsuite/gfortran.dg/trim_optimize_7.f90 new file mode 100644 index 0000000..26663c0 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/trim_optimize_7.f90 @@ -0,0 +1,19 @@ +! { 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" } } |