From: Thomas Koenig <tkoenig@netcologne.de>
To: "fortran@gcc.gnu.org" <fortran@gcc.gnu.org>,
gcc-patches <gcc-patches@gcc.gnu.org>
Subject: [patch, fortran] Fix PR 66111
Date: Tue, 12 May 2015 20:10:00 -0000 [thread overview]
Message-ID: <55525D6A.8050106@netcologne.de> (raw)
[-- Attachment #1: Type: text/plain, Size: 578 bytes --]
Hello world,
this patch fixes a regression from the inline matmul patch by
not inlining a case that is not yet handled, namely vector
subscripts.
Regression-tested. OK for trunk?
Regards
Thomas
2015-05-12 Thomas Koenig <tkoenig@gcc.gnu.org>
PR fortran/66111
* frontend-passes.c (has_dimen_vector_ref): New function.
(inline_matmul_assign): Use it to return early in case
of unhandled vector subscripts.
2015-05-12 Thomas Koenig <tkoenig@gcc.gnu.org>
PR fortran/66111
* gfortran.dg/inline_matmul_10.f90: New test.
[-- Attachment #2: p1.diff --]
[-- Type: text/x-patch, Size: 1116 bytes --]
Index: frontend-passes.c
===================================================================
--- frontend-passes.c (Revision 222984)
+++ frontend-passes.c (Arbeitskopie)
@@ -2680,7 +2680,26 @@ scalarized_expr (gfc_expr *e_in, gfc_expr **index,
return e;
}
+/* Helper function to check for a dimen vector as subscript. */
+static bool
+has_dimen_vector_ref (gfc_expr *e)
+{
+ gfc_array_ref *ar;
+ int i;
+
+ ar = gfc_find_array_ref (e);
+ gcc_assert (ar);
+ if (ar->type == AR_FULL)
+ return false;
+
+ for (i=0; i<ar->dimen; i++)
+ if (ar->dimen_type[i] == DIMEN_VECTOR)
+ return true;
+
+ return false;
+}
+
/* Inline assignments of the form c = matmul(a,b).
Handle only the cases currently where b and c are rank-two arrays.
@@ -2752,6 +2771,10 @@ inline_matmul_assign (gfc_code **c, int *walk_subt
|| matrix_b->expr_type != EXPR_VARIABLE)
return 0;
+ if (has_dimen_vector_ref (expr1) ||
+ has_dimen_vector_ref (matrix_a) || has_dimen_vector_ref (matrix_b))
+ return 0;
+
if (matrix_a->rank == 2)
m_case = matrix_b->rank == 1 ? A2B1 : A2B2;
else
[-- Attachment #3: inline_matmul_10.f90 --]
[-- Type: text/x-fortran, Size: 1004 bytes --]
! { dg-do run }
! { dg-options "-ffrontend-optimize" }
! PR 66111 - this used to ICE with matmul inlining.
! Original test case by Mikael Morin.
implicit none
integer, parameter :: n = 4
integer, dimension(n, n) :: a, b, c
integer, dimension(n*n) :: p, res, res2
integer, dimension(n) :: v
integer :: i
p = [ +59, -53, +47, -43, &
-37, +31, -29, +23, &
+19, -17, +13, -11, &
- 7, + 5, - 3, + 2 ]
a = reshape(p, shape(a))
b = reshape([(i, i=1, size(a))], shape(b))
v = [ 3, 1, 2, 4]
c = matmul(a, b)
res = [ + 14, - 22, + 16, - 22, &
+150, -158, +128, -138, &
+286, -294, +240, -254, &
+422, -430, +352, -370 ]
!print *,c
if (any(c /= reshape(res, shape(c)))) call abort
c(:,v) = matmul(a, b)
if (any(c(:,v) /= reshape(res, shape(c)))) call abort
c(v,:) = matmul(a, b)
if (any(c(v,:) /= reshape(res, shape(c)))) call abort
c = matmul(a(:,v),b(v,:))
if (any(c /= reshape(res, shape(c)))) call abort
end
next reply other threads:[~2015-05-12 20:07 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-05-12 20:10 Thomas Koenig [this message]
2015-05-12 21:28 ` Mikael Morin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=55525D6A.8050106@netcologne.de \
--to=tkoenig@netcologne.de \
--cc=fortran@gcc.gnu.org \
--cc=gcc-patches@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).