diff options
-rw-r--r-- | gcc/fortran/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/fortran/frontend-passes.c | 18 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/gfortran.dg/power_5.f90 | 36 |
4 files changed, 65 insertions, 0 deletions
diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 9e47b13f0ec..4439749dbaa 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,9 @@ +2013-04-30 Thomas Koenig <tkoenig@gcc.gnu.org> + + PR fortran/57071 + * frontend-passes.c (optimize_power): Simplify + 1**k to 1. + 2013-04-28 Tobias Burnus <burnus@net-b.de> PR fortran/57114 diff --git a/gcc/fortran/frontend-passes.c b/gcc/fortran/frontend-passes.c index 63efb9f919c..a2e88b4f408 100644 --- a/gcc/fortran/frontend-passes.c +++ b/gcc/fortran/frontend-passes.c @@ -1148,6 +1148,24 @@ optimize_power (gfc_expr *e) *e = *ishft; return true; } + + else if (mpz_cmp_si (op1->value.integer, 1L) == 0) + { + op2 = e->value.op.op2; + if (op2 == NULL) + return false; + + gfc_free_expr (op1); + gfc_free_expr (op2); + + e->expr_type = EXPR_CONSTANT; + e->value.op.op1 = NULL; + e->value.op.op2 = NULL; + mpz_init_set_si (e->value.integer, 1); + /* Typespec cand location are still OK. */ + return true; + } + return false; } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index ae111b265c8..1016036dca3 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2013-04-30 Thomas Koenig <tkoenig@gcc.gnu.org> + + PR fortran/57071 + * gfortran.dg/power_5.f90: New test. + 2013-04-30 Richard Biener <rguenther@suse.de> PR middle-end/57122 diff --git a/gcc/testsuite/gfortran.dg/power_5.f90 b/gcc/testsuite/gfortran.dg/power_5.f90 new file mode 100644 index 00000000000..f42b26051cb --- /dev/null +++ b/gcc/testsuite/gfortran.dg/power_5.f90 @@ -0,0 +1,36 @@ +! { dg-do run } +! { dg-options "-ffrontend-optimize -fdump-tree-original" } +! PR 57071 - Check that 1**k is transformed into 1 +program main + implicit none + integer, parameter :: n = 3 + integer(kind=8), dimension(-n:n) :: a + integer, dimension(-n:n) :: c, d + integer :: m + integer :: i, v + integer (kind=2) :: i2 + + v = 1 + m = n + ! Test in scalar expressions + do i=-n,n + if (v /= 1**i) call abort + end do + + ! Test in array constructors + a(-m:m) = [ (1**i, i= -m, m) ] + if (any(a .ne. v)) call abort + + ! Test in array expressions + c = [ ( i, i = -n , n ) ] + d = 1**c + if (any(d .ne. v)) call abort + + ! Test in different kind expressions + do i2=-n,n + if (v /= 1**i2) call abort + end do + +end program main +! { dg-final { scan-tree-dump-times "_gfortran_pow_i4_i4" 0 "original" } } +! { dg-final { cleanup-tree-dump "original" } } |