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

login
register
mail settings
Submitter Thomas Koenig
Date April 30, 2013, 9:47 p.m.
Message ID <51803C02.40706@netcologne.de>
Download mbox | patch
Permalink /patch/240698/
State New
Headers show

Comments

Thomas Koenig - April 30, 2013, 9:47 p.m.
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.
Steve Kargl - April 30, 2013, 9:54 p.m.
On Tue, Apr 30, 2013 at 11:47:46PM +0200, Thomas Koenig wrote:
> +      e->value.op.op1 = NULL;
> +      e->value.op.op2 = NULL;
> +      mpz_init_set_si (e->value.integer, 1);
> +      /* Typespec cand location are still OK.  */

s/cand/and
Thomas Koenig - May 1, 2013, 8:29 a.m.
Hi Steve,


> s/cand/and

Fixed, thanks.

	Thomas

Patch

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;
 }