Bug 30533 - [4.1 only] minval, maxval missing for kind=1 and kind=2
Summary: [4.1 only] minval, maxval missing for kind=1 and kind=2
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: libfortran (show other bugs)
Version: 4.3.0
: P3 normal
Target Milestone: ---
Assignee: Thomas Koenig
URL: http://gcc.gnu.org/ml/gcc-patches/200...
Keywords: rejects-valid
Depends on: 30765
Blocks:
  Show dependency treegraph
 
Reported: 2007-01-21 23:03 UTC by Thomas Koenig
Modified: 2007-02-28 21:37 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2007-01-29 22:42:14


Attachments
patch for minval and maxval (548 bytes, patch)
2007-01-31 21:07 UTC, Thomas Koenig
Details | Diff
patch (1.88 KB, patch)
2007-02-11 19:42 UTC, Thomas Koenig
Details | Diff
combined patch for this and PR 30765 (4.05 KB, patch)
2007-02-12 20:21 UTC, Thomas Koenig
Details | Diff
Test case (343 bytes, text/plain)
2007-02-12 20:23 UTC, Thomas Koenig
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Koenig 2007-01-21 23:03:18 UTC
Yet another missing intrinsic kind...

Also watch out for PR 30512 when fixing this.

$ cat minval-1.f90
program main
  integer(kind=1), allocatable :: a(:,:)
  integer(kind=2), allocatable :: b(:,:)
  allocate (a(0:-1,1:1))
  allocate (b(0:-1,1:1))
  print *,maxval(a,dim=1) ,minval(a,dim=1)
  print *,maxval(b,dim=1) ,minval(b,dim=1)
end program main
$ gfortran minval-1.f90
/tmp/ccOKvSb7.o: In function `MAIN__':
minval-1.f90:(.text+0x17f): undefined reference to `_gfortran_maxval_i1'
minval-1.f90:(.text+0x20e): undefined reference to `_gfortran_minval_i1'
minval-1.f90:(.text+0x2e1): undefined reference to `_gfortran_maxval_i2'
minval-1.f90:(.text+0x371): undefined reference to `_gfortran_minval_i2'
collect2: ld returned 1 exit status
Comment 1 Francois-Xavier Coudert 2007-01-23 13:26:59 UTC
matmul also has this problem:

$ cat a.f90 
  integer(kind=1) :: x(2,2), y(2,2), i
  integer :: z(2,2)

  print *, matmul(x,y)
  !pack
  !unpack
  print *, maxval(x,dim=2), minval(x,dim=2)
  print *, (1.2,0.2)**i
  print *, sum(x), product(y)
  y = transpose(x)
  y = transpose(z)
  end
$ gfortran a.f90   
/tmp/ccWGjYiw.o: In function `MAIN__':
a.f90:(.text+0x139): undefined reference to `_gfortran_matmul_i1'
a.f90:(.text+0x2ba): undefined reference to `_gfortran_maxval_i1'
a.f90:(.text+0x39d): undefined reference to `_gfortran_minval_i1'
collect2: ld returned 1 exit status
Comment 2 Thomas Koenig 2007-01-29 22:42:14 UTC
For maxval, the usual method of converting the
arguments to default integer kind will have an
"interesting" side effect with an all-false mask:
The value will be a conversion of the default integer
minimum value (soon to be 0x8000000000 after the fix
for PR 30512 goes in) to kind=1 or kind=2.
Definitely not recommended (this will probably be 0x00
or 0x0000)l

The best solution is to generate new maxval_i[12].c files,
which will be better for performance anyway.
Comment 3 Thomas Koenig 2007-01-31 21:07:22 UTC
Created attachment 12990 [details]
patch for minval and maxval

Here's a solution for minval and maxval.

I'm not yet sure how to deal with matmul, wether by
converting its arguments or by creating kind=1 and
kind=2 versions.
Comment 4 Francois-Xavier Coudert 2007-02-07 08:09:57 UTC
(In reply to comment #3)
> I'm not yet sure how to deal with matmul, wether by
> converting its arguments or by creating kind=1 and
> kind=2 versions.

I think converting wil have a huge performance hit, so we'd better havec kind=1 and kind=2 versions.
Comment 5 Thomas Koenig 2007-02-07 20:08:00 UTC
> I think converting wil have a huge performance hit, so we'd better havec kind=1
> and kind=2 versions.

I agree, here's a patch to do this.

For speed reasons, we should also reverse the conversions
through the intrinsics that only make one pass through the data
(such as sum, product, or minmaxloc).

Index: Makefile.am
===================================================================
--- Makefile.am (revision 121423)
+++ Makefile.am (working copy)
@@ -176,6 +176,8 @@ generated/maxloc1_8_r16.c \
 generated/maxloc1_16_r16.c

 i_maxval_c= \
+generated/maxval_i1.c \
+generated/maxval_i2.c \
 generated/maxval_i4.c \
 generated/maxval_i8.c \
 generated/maxval_i16.c \
@@ -231,6 +233,8 @@ generated/minloc1_8_r16.c \
 generated/minloc1_16_r16.c

 i_minval_c= \
+generated/minval_i1.c \
+generated/minval_i2.c \
 generated/minval_i4.c \
 generated/minval_i8.c \
 generated/minval_i16.c \
Index: libgfortran.h
===================================================================
--- libgfortran.h       (revision 121423)
+++ libgfortran.h       (working copy)
@@ -224,6 +224,10 @@ internal_proto(l8_to_l4_offset);
 #define GFOR_POINTER_L8_TO_L4(p8) \
   (l8_to_l4_offset + (GFC_LOGICAL_4 *)(p8))

+#define GFC_INTEGER_1_HUGE \
+  (GFC_INTEGER_1)((((GFC_UINTEGER_1)1) << 7) - 1)
+#define GFC_INTEGER_2_HUGE \
+  (GFC_INTEGER_1)((((GFC_UINTEGER_1)1) << 15) - 1)
 #define GFC_INTEGER_4_HUGE \
   (GFC_INTEGER_4)((((GFC_UINTEGER_4)1) << 31) - 1)
 #define GFC_INTEGER_8_HUGE \
@@ -283,6 +287,8 @@ struct {\
 /* Commonly used array descriptor types.  */
 typedef GFC_ARRAY_DESCRIPTOR (GFC_MAX_DIMENSIONS, void) gfc_array_void;
 typedef GFC_ARRAY_DESCRIPTOR (GFC_MAX_DIMENSIONS, char) gfc_array_char;
+typedef GFC_ARRAY_DESCRIPTOR (GFC_MAX_DIMENSIONS, GFC_INTEGER_1) gfc_array_i1;
+typedef GFC_ARRAY_DESCRIPTOR (GFC_MAX_DIMENSIONS, GFC_INTEGER_2) gfc_array_i2;
 typedef GFC_ARRAY_DESCRIPTOR (GFC_MAX_DIMENSIONS, GFC_INTEGER_4) gfc_array_i4;
 typedef GFC_ARRAY_DESCRIPTOR (GFC_MAX_DIMENSIONS, GFC_INTEGER_8) gfc_array_i8;
 #ifdef HAVE_GFC_INTEGER_16
Comment 6 Thomas Koenig 2007-02-10 19:57:45 UTC
sum is also missing:

$ cat sum.f90
program main
  integer(kind=1), dimension(2,2) :: a
  a = 1
  print *,sum(a,dim=2)
end program main
$ gfortran sum.f90
/tmp/ccQgrJa3.o: In function `MAIN__':
sum.f90:(.text+0x126): undefined reference to `_gfortran_sum_i1'
collect2: ld returned 1 exit status
Comment 7 Thomas Koenig 2007-02-11 19:42:54 UTC
Created attachment 13036 [details]
patch

This fixes the missing intrinsics, and removes type conversion
from minloc.

This also reverses http://gcc.gnu.org/ml/gcc-cvs/2007-02/msg00353.html
(PR 30765).
Comment 8 Thomas Koenig 2007-02-12 20:21:34 UTC
Created attachment 13044 [details]
combined patch for this and PR 30765

Regression-test is OK, file generation is OK.
Comment 9 Thomas Koenig 2007-02-12 20:23:11 UTC
Created attachment 13045 [details]
Test case

Test case.

I'll be away for a few days, I'll submit it as a proper patch then.
Comment 10 Thomas Koenig 2007-02-12 20:25:20 UTC
(In reply to comment #8)
> Created an attachment (id=13044) [edit]
> combined patch for this and PR 30765
> 
> Regression-test is OK, file generation is OK.


I found and fixed the typo for i_any_c, it's a wonder this
didn't break anything.
Comment 11 Thomas Koenig 2007-02-19 20:49:40 UTC
Subject: Bug 30533

Author: tkoenig
Date: Mon Feb 19 20:49:10 2007
New Revision: 122137

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=122137
Log:
2007-02-19  Thomas Koenig  <Thomas.Koenig@online.de>

	PR libfortran/30533
	PR libfortran/30765
	* Makefile.am: Add $(srcdir) too all files in generated/.
	(i_maxloc0_c): Add maxloc0_4_i1.c, maxloc0_8_i1.c,
	maxloc0_16_i1.c, maxloc0_4_i2.c, maxloc0_8_i2.c and
	maxloc0_16_i2.c.
	(i_maxloc1_c): Add maxloc1_4_i1.c, maxloc1_8_i1.c,
	maxloc1_16_i1.c, maxloc1_4_i2.c, maxloc1_8_i2.c and
	maxloc1_16_i2.c.
	(i_maxval_c): Add maxval_i1.c and maxval_i2.c.
	(i_minloc0_c):  Add minloc0_4_i1.c, minloc0_8_i1.c,
	minloc0_16_i1.c, minloc0_4_i2.c, minloc0_8_i2.c and
	minloc0_16_i2.c.
	(i_minloc_1.c): Add minloc1_4_i1.c, minloc1_8_i1.c,
	minloc1_16_i1.c, minloc1_4_i2.c, minloc1_8_i2.c and
	minloc1_16_i2.c.
	(i_minval_c):  Add minval_i1.c and minval_i2.c.
	(i_sum_c):  Add sum_i1.c and sum_i2.c.
	(i_product_c):  Add product_i1.c and product_i2.c.
	(i_matmul_c):  Add matmul_i1.c and matmul_i2.c.
	(gfor_built_specific_src):  Remove $(srcdir) from target.
	(gfor_bulit_specific2_src):  Likewise.
	Makefile.in:  Regenerated.
	libgfortran.h:  Add GFC_INTEGER_1_HUGE and GFC_INTEGER_2_HUGE.
	Add gfc_array_i1 and gfc_array_i2.
	* generated/matmul_i1.c: New file.
	* generated/matmul_i2.c: New file.
	* generated/maxloc0_16_i1.c: New file.
	* generated/maxloc0_16_i2.c: New file.
	* generated/maxloc0_4_i1.c: New file.
	* generated/maxloc0_4_i2.c: New file.
	* generated/maxloc0_8_i1.c: New file.
	* generated/maxloc0_8_i2.c: New file.
	* generated/maxloc1_16_i1.c: New file.
	* generated/maxloc1_16_i2.c: New file.
	* generated/maxloc1_4_i1.c: New file.
	* generated/maxloc1_4_i2.c: New file.
	* generated/maxloc1_8_i1.c: New file.
	* generated/maxloc1_8_i2.c: New file.
	* generated/maxval_i1.c: New file.
	* generated/maxval_i2.c: New file.
	* generated/minloc0_16_i1.c: New file.
	* generated/minloc0_16_i2.c: New file.
	* generated/minloc0_4_i1.c: New file.
	* generated/minloc0_4_i2.c: New file.
	* generated/minloc0_8_i1.c: New file.
	* generated/minloc0_8_i2.c: New file.
	* generated/minloc1_16_i1.c: New file.
	* generated/minloc1_16_i2.c: New file.
	* generated/minloc1_4_i1.c: New file.
	* generated/minloc1_4_i2.c: New file.
	* generated/minloc1_8_i1.c: New file.
	* generated/minloc1_8_i2.c: New file.
	* generated/minval_i1.c: New file.
	* generated/minval_i2.c: New file.
	* generated/product_i1.c: New file.
	* generated/product_i2.c: New file.
	* generated/sum_i1.c: New file.
	* generated/sum_i2.c: New file.

2007-02-19  Thomas Koenig  <Thomas.Koenig@online.de>

	PR libfortran/30533
	* fortran/iresolve.c(gfc_resolve_maxloc):  Remove coercion of
	argument to default integer.
	(gfc_resolve_minloc):  Likewise.

2007-02-19  Thomas Koenig  <Thomas.Koenig@online.de>

	PR libfortran/30533
	* gfortran.dg/intrinsic_intkinds_1.f90:  New test.



Added:
    trunk/gcc/testsuite/gfortran.dg/intrinsic_intkinds_1.f90
    trunk/libgfortran/generated/matmul_i1.c
    trunk/libgfortran/generated/matmul_i2.c
    trunk/libgfortran/generated/maxloc0_16_i1.c
    trunk/libgfortran/generated/maxloc0_16_i2.c
    trunk/libgfortran/generated/maxloc0_4_i1.c
    trunk/libgfortran/generated/maxloc0_4_i2.c
    trunk/libgfortran/generated/maxloc0_8_i1.c
    trunk/libgfortran/generated/maxloc0_8_i2.c
    trunk/libgfortran/generated/maxloc1_16_i1.c
    trunk/libgfortran/generated/maxloc1_16_i2.c
    trunk/libgfortran/generated/maxloc1_4_i1.c
    trunk/libgfortran/generated/maxloc1_4_i2.c
    trunk/libgfortran/generated/maxloc1_8_i1.c
    trunk/libgfortran/generated/maxloc1_8_i2.c
    trunk/libgfortran/generated/maxval_i1.c
    trunk/libgfortran/generated/maxval_i2.c
    trunk/libgfortran/generated/minloc0_16_i1.c
    trunk/libgfortran/generated/minloc0_16_i2.c
    trunk/libgfortran/generated/minloc0_4_i1.c
    trunk/libgfortran/generated/minloc0_4_i2.c
    trunk/libgfortran/generated/minloc0_8_i1.c
    trunk/libgfortran/generated/minloc0_8_i2.c
    trunk/libgfortran/generated/minloc1_16_i1.c
    trunk/libgfortran/generated/minloc1_16_i2.c
    trunk/libgfortran/generated/minloc1_4_i1.c
    trunk/libgfortran/generated/minloc1_4_i2.c
    trunk/libgfortran/generated/minloc1_8_i1.c
    trunk/libgfortran/generated/minloc1_8_i2.c
    trunk/libgfortran/generated/minval_i1.c
    trunk/libgfortran/generated/minval_i2.c
    trunk/libgfortran/generated/product_i1.c
    trunk/libgfortran/generated/product_i2.c
    trunk/libgfortran/generated/sum_i1.c
    trunk/libgfortran/generated/sum_i2.c
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/iresolve.c
    trunk/gcc/testsuite/ChangeLog
    trunk/libgfortran/ChangeLog
    trunk/libgfortran/Makefile.am
    trunk/libgfortran/Makefile.in
    trunk/libgfortran/libgfortran.h

Comment 12 Thomas Koenig 2007-02-28 21:36:51 UTC
Subject: Bug 30533

Author: tkoenig
Date: Wed Feb 28 21:36:31 2007
New Revision: 122412

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=122412
Log:
2007-02-28  Thomas Koenig  <Thomas.Koenig@online.de>

	Backport from trunk
	PR fortran/30869
	PR libfortran/30533
        PR libfortran/30765
	* match.c(gfc_match_iterator):  Remove conflict between
	loop variable and pointer.
	* fortran/iresolve.c(gfc_resolve_maxloc):  Remove coercion of
	argument to default integer.
        (gfc_resolve_minloc):  Likewise.

2007-02-28  Thomas Koenig  <Thomas.Koenig@online.de>

	Backport from trunk
	PR libfortran/30533
        PR libfortran/30765
	* Makefile.am: Add $(srcdir) too all files in generated/.
	(i_maxloc0_c): Add maxloc0_4_i1.c, maxloc0_8_i1.c,
	maxloc0_16_i1.c, maxloc0_4_i2.c, maxloc0_8_i2.c and
	maxloc0_16_i2.c.
	(i_maxloc1_c): Add maxloc1_4_i1.c, maxloc1_8_i1.c,
	maxloc1_16_i1.c, maxloc1_4_i2.c, maxloc1_8_i2.c and
	maxloc1_16_i2.c.
	(i_maxval_c): Add maxval_i1.c and maxval_i2.c.
	(i_minloc0_c):  Add minloc0_4_i1.c, minloc0_8_i1.c,
	minloc0_16_i1.c, minloc0_4_i2.c, minloc0_8_i2.c and
	minloc0_16_i2.c.
	(i_minloc_1.c): Add minloc1_4_i1.c, minloc1_8_i1.c,
	minloc1_16_i1.c, minloc1_4_i2.c, minloc1_8_i2.c and
	minloc1_16_i2.c.
	(i_minval_c):  Add minval_i1.c and minval_i2.c.
	(i_sum_c):  Add sum_i1.c and sum_i2.c.
	(i_product_c):  Add product_i1.c and product_i2.c.
	(i_matmul_c):  Add matmul_i1.c and matmul_i2.c.
	(gfor_built_specific_src):  Remove $(srcdir) from target.
	(gfor_bulit_specific2_src):  Likewise.
	Use $(M4) instead of m4.
	Makefile.in:  Regenerated.
	libgfortran.h:  Add GFC_INTEGER_1_HUGE and GFC_INTEGER_2_HUGE.
	Add gfc_array_i1 and gfc_array_i2.
	* generated/matmul_i1.c: New file.
	* generated/matmul_i2.c: New file.
	* generated/maxloc0_16_i1.c: New file.
	* generated/maxloc0_16_i2.c: New file.
	* generated/maxloc0_4_i1.c: New file.
	* generated/maxloc0_4_i2.c: New file.
	* generated/maxloc0_8_i1.c: New file.
	* generated/maxloc0_8_i2.c: New file.
	* generated/maxloc1_16_i1.c: New file.
	* generated/maxloc1_16_i2.c: New file.
	* generated/maxloc1_4_i1.c: New file.
	* generated/maxloc1_4_i2.c: New file.
	* generated/maxloc1_8_i1.c: New file.
	* generated/maxloc1_8_i2.c: New file.
	* generated/maxval_i1.c: New file.
	* generated/maxval_i2.c: New file.
	* generated/minloc0_16_i1.c: New file.
	* generated/minloc0_16_i2.c: New file.
	* generated/minloc0_4_i1.c: New file.
	* generated/minloc0_4_i2.c: New file.
	* generated/minloc0_8_i1.c: New file.
	* generated/minloc0_8_i2.c: New file.
	* generated/minloc1_16_i1.c: New file.
	* generated/minloc1_16_i2.c: New file.
	* generated/minloc1_4_i1.c: New file.
	* generated/minloc1_4_i2.c: New file.
	* generated/minloc1_8_i1.c: New file.
	* generated/minloc1_8_i2.c: New file.
	* generated/minval_i1.c: New file.
	* generated/minval_i2.c: New file.
	* generated/product_i1.c: New file.
	* generated/product_i2.c: New file.
	* generated/sum_i1.c: New file.
	* generated/sum_i2.c: New file.

2007-02-28  Thomas Koenig  <Thomas.Koenig@online.de>

	Backport from trunk
	PR fortran/30869
	PR libfortran/30533
        PR libfortran/30765
	* gfortran.dg/intrinsic_intkinds_1.f90:  New test.
	* gfortran.dg/do_pointer_1.f90:  New test.



Added:
    branches/gcc-4_2-branch/gcc/testsuite/gfortran.dg/do_pointer_1.f90
    branches/gcc-4_2-branch/gcc/testsuite/gfortran.dg/intrinsic_intkinds_1.f90
    branches/gcc-4_2-branch/libgfortran/generated/matmul_i1.c
    branches/gcc-4_2-branch/libgfortran/generated/matmul_i2.c
    branches/gcc-4_2-branch/libgfortran/generated/maxloc0_16_i1.c
    branches/gcc-4_2-branch/libgfortran/generated/maxloc0_16_i2.c
    branches/gcc-4_2-branch/libgfortran/generated/maxloc0_4_i1.c
    branches/gcc-4_2-branch/libgfortran/generated/maxloc0_4_i2.c
    branches/gcc-4_2-branch/libgfortran/generated/maxloc0_8_i1.c
    branches/gcc-4_2-branch/libgfortran/generated/maxloc0_8_i2.c
    branches/gcc-4_2-branch/libgfortran/generated/maxloc1_16_i1.c
    branches/gcc-4_2-branch/libgfortran/generated/maxloc1_16_i2.c
    branches/gcc-4_2-branch/libgfortran/generated/maxloc1_4_i1.c
    branches/gcc-4_2-branch/libgfortran/generated/maxloc1_4_i2.c
    branches/gcc-4_2-branch/libgfortran/generated/maxloc1_8_i1.c
    branches/gcc-4_2-branch/libgfortran/generated/maxloc1_8_i2.c
    branches/gcc-4_2-branch/libgfortran/generated/maxval_i1.c
    branches/gcc-4_2-branch/libgfortran/generated/maxval_i2.c
    branches/gcc-4_2-branch/libgfortran/generated/minloc0_16_i1.c
    branches/gcc-4_2-branch/libgfortran/generated/minloc0_16_i2.c
    branches/gcc-4_2-branch/libgfortran/generated/minloc0_4_i1.c
    branches/gcc-4_2-branch/libgfortran/generated/minloc0_4_i2.c
    branches/gcc-4_2-branch/libgfortran/generated/minloc0_8_i1.c
    branches/gcc-4_2-branch/libgfortran/generated/minloc0_8_i2.c
    branches/gcc-4_2-branch/libgfortran/generated/minloc1_16_i1.c
    branches/gcc-4_2-branch/libgfortran/generated/minloc1_16_i2.c
    branches/gcc-4_2-branch/libgfortran/generated/minloc1_4_i1.c
    branches/gcc-4_2-branch/libgfortran/generated/minloc1_4_i2.c
    branches/gcc-4_2-branch/libgfortran/generated/minloc1_8_i1.c
    branches/gcc-4_2-branch/libgfortran/generated/minloc1_8_i2.c
    branches/gcc-4_2-branch/libgfortran/generated/minval_i1.c
    branches/gcc-4_2-branch/libgfortran/generated/minval_i2.c
    branches/gcc-4_2-branch/libgfortran/generated/product_i1.c
    branches/gcc-4_2-branch/libgfortran/generated/product_i2.c
    branches/gcc-4_2-branch/libgfortran/generated/sum_i1.c
    branches/gcc-4_2-branch/libgfortran/generated/sum_i2.c
Modified:
    branches/gcc-4_2-branch/gcc/fortran/ChangeLog
    branches/gcc-4_2-branch/gcc/fortran/iresolve.c
    branches/gcc-4_2-branch/gcc/fortran/match.c
    branches/gcc-4_2-branch/gcc/testsuite/ChangeLog
    branches/gcc-4_2-branch/libgfortran/ChangeLog
    branches/gcc-4_2-branch/libgfortran/Makefile.am
    branches/gcc-4_2-branch/libgfortran/Makefile.in
    branches/gcc-4_2-branch/libgfortran/libgfortran.h

Comment 13 Thomas Koenig 2007-02-28 21:37:22 UTC
Fixed on 4.2.  Closing.