diff mbox

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

Message ID 51803C02.40706@netcologne.de
State New
Headers show

Commit Message

Thomas Koenig April 30, 2013, 9:47 p.m. UTC
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.

Comments

Steve Kargl April 30, 2013, 9:54 p.m. UTC | #1
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. UTC | #2
Hi Steve,


> s/cand/and

Fixed, thanks.

	Thomas
diff mbox

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