This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
[patch, fortran] power.f90 FAIL in testsuite
- From: Scott Robert Ladd <coyote at coyotegulch dot com>
- To: gcc-patches at gcc dot gnu dot org, fortran at gcc dot gnu dot org
- Date: Mon, 01 Nov 2004 15:22:01 -0500
- Subject: [patch, fortran] power.f90 FAIL in testsuite
I'm looking for commentary on this proposed patch, which fixes the
incorrect calculation of integer powers when the base is 1. The patch
identifies power operations with an integer base of 1, and replace them
with a constant 1. The conversion takes place in eval_intrinsic().
Such a transform is logical, but I'm not certain I'm doing it in the
most appropriate place. I picked something small, so my glaring mistakes
could be easily identified... ;)
Then, of course, we get into the issue of whether or not other known
transforms should be applied, such as for real and complex types.
This patch also modifies the test suite slightly, by removing the
complex power tests from power.f90, and creating a new cpower.f90 test
that, at this time, fails, likely due to the complex-specific PR 17603.
The test suite is not very comprehensive, testing a few specific cases
but not general correctness. Combing integer, real, and complex tests
can cloud results. I'm willing to propose (as an example) test case
examples for ** operator tests, providing better coverage and granularity.
..Scott
2004-11-01 Scott Robert Ladd <scott.ladd@coyotegulch.com>
* gcc/fortran/arith.c (eval_intrinsic): Added transform from power
of integer 1 to a constant of 1
* gcc/testsuite/gfortran.fortran-torture/execute/power.f90:
Removed complex power tests to cpower.f90
* gcc/testsuite/gfortran.fortran-torture/execute/cpower.f90:
Complex power tests
Index: MAINTAINERS
===================================================================
RCS file: /cvs/gcc/gcc/MAINTAINERS,v
retrieving revision 1.380
diff -u -3 -p -r1.380 MAINTAINERS
--- MAINTAINERS 20 Oct 2004 07:50:06 -0000 1.380
+++ MAINTAINERS 1 Nov 2004 19:37:03 -0000
@@ -247,7 +247,11 @@ Matthias Klose doko@debian.org
Jeff Knaggs jknaggs@redhat.com
Michael Koch konqueror@gmx.de
Matt Kraai kraai@alumni.cmu.edu
+<<<<<<< MAINTAINERS
+Scott Robert Ladd scott.ladd@coyotegulch.com
+=======
Aaron W. LaFramboise aaronavay62@aaronwl.com
+>>>>>>> 1.380
Marc Lehmann pcg@goof.com
Alan Lehotsky apl@alum.mit.edu
James Lemke jim@wasabisystems.com
Index: gcc/fortran/arith.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fortran/arith.c,v
retrieving revision 1.17
diff -u -3 -p -r1.17 arith.c
--- gcc/fortran/arith.c 28 Oct 2004 21:43:46 -0000 1.17
+++ gcc/fortran/arith.c 1 Nov 2004 19:37:09 -0000
@@ -1633,6 +1633,19 @@ eval_intrinsic (gfc_intrinsic_op operato
gfc_internal_error ("eval_intrinsic(): Bad operator");
}
+ /* Simplify power operation to constant if first op1 is 1 */
+ if (operator == INTRINSIC_POWER && op1->ts.type == BT_INTEGER)
+ {
+ if (mpz_cmp_si (op1->value.integer,1) == 0)
+ {
+ result = gfc_get_expr ();
+ *result = *op1;
+ gfc_free_expr (op1);
+ gfc_free_expr (op2);
+ return result;
+ }
+ }
+
/* Try to combine the operators. */
if (operator == INTRINSIC_POWER && op2->ts.type != BT_INTEGER)
goto runtime;
Index: gcc/testsuite/gfortran.fortran-torture/execute/cpower.f90
===================================================================
RCS file: gcc/testsuite/gfortran.fortran-torture/execute/cpower.f90
diff -N gcc/testsuite/gfortran.fortran-torture/execute/cpower.f90
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ gcc/testsuite/gfortran.fortran-torture/execute/cpower.f90 1 Nov 2004 19:37:23 -0000
@@ -0,0 +1,19 @@
+! Program to test the power (**) operator
+program testpow
+ implicit none
+ real(kind=4) :: two
+ complex(kind=4) :: c, z
+ real, parameter :: del = 0.0001
+
+ c = (2.0, 3.0)
+ z = c ** 2
+ if (abs(z - (-5.0, 12.0)) .gt. del) call abort
+
+ z = c ** 7
+ if (abs(z - (6554.0, 4449.0)) .gt. del) call abort
+
+ two = 2.0
+ c = (2.0, 3.0)
+ c = c ** two
+ if (abs(c - (-5.0, 12.0)) .gt. del) call abort
+end program
Index: gcc/testsuite/gfortran.fortran-torture/execute/power.f90
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/gfortran.fortran-torture/execute/power.f90,v
retrieving revision 1.3
diff -u -3 -p -r1.3 power.f90
--- gcc/testsuite/gfortran.fortran-torture/execute/power.f90 19 May 2004 00:34:57 -0000 1.3
+++ gcc/testsuite/gfortran.fortran-torture/execute/power.f90 1 Nov 2004 19:37:24 -0000
@@ -3,7 +3,6 @@ program testpow
implicit none
real(kind=4) r, s, two
real(kind=8) :: q
- complex(kind=4) :: c, z
real, parameter :: del = 0.0001
integer i, j
@@ -33,12 +32,6 @@ program testpow
j = i ** (-11)
if (abs (j - (-1)) .gt. del) call abort
- c = (2.0, 3.0)
- z = c ** 2
- if (abs(z - (-5.0, 12.0)) .gt. del) call abort
- z = c ** 7
- if (abs(z - (6554.0, 4449.0)) .gt. del) call abort
-
two = 2.0
r = two ** 1
@@ -69,7 +62,4 @@ program testpow
i = -3
r = two ** i
if (abs (r - 0.125) .gt. del) call abort
- c = (2.0, 3.0)
- c = c ** two
- if (abs(c - (-5.0, 12.0)) .gt. del) call abort
end program