This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch, fortran, committed] Change 1**k to 1


Hello world,

the attached patch was committed after Tobias Burnus' OK
in PR 57073 and regression-testing.

	Thomas

2013-04-30  Thomas Koenig  <tkoenig@gcc.gnu.org>

        PR fortran/57071
        * frontend-passes.c (optimize_power):  Simplify
        1**k to 1.

2013-04-30  Thomas Koenig  <tkoenig@gcc.gnu.org>

        PR fortran/57071
        * gfortran.dg/power_5.f90:  New test.
Index: frontend-passes.c
===================================================================
--- frontend-passes.c	(Revision 198369)
+++ frontend-passes.c	(Arbeitskopie)
@@ -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;
 }
 
! { 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" } }

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]