[gcc(refs/users/mikael/heads/refactor_descriptor_v08)] Régénération fichiers générés

Mikael Morin mikael@gcc.gnu.org
Mon Sep 15 13:38:49 GMT 2025


https://gcc.gnu.org/g:9bb106cdf6b1316d83f5dd61cac69c8a48be9365

commit 9bb106cdf6b1316d83f5dd61cac69c8a48be9365
Author: Mikael Morin <mikael@gcc.gnu.org>
Date:   Sun Sep 14 21:52:21 2025 +0200

    Régénération fichiers générés

Diff:
---
 libgfortran/generated/cshift0_c10.c      |   2 +-
 libgfortran/generated/cshift0_c16.c      |   2 +-
 libgfortran/generated/cshift0_c17.c      |   2 +-
 libgfortran/generated/cshift0_c4.c       |   2 +-
 libgfortran/generated/cshift0_c8.c       |   2 +-
 libgfortran/generated/cshift0_i1.c       |   2 +-
 libgfortran/generated/cshift0_i16.c      |   2 +-
 libgfortran/generated/cshift0_i2.c       |   2 +-
 libgfortran/generated/cshift0_i4.c       |   2 +-
 libgfortran/generated/cshift0_i8.c       |   2 +-
 libgfortran/generated/cshift0_r10.c      |   2 +-
 libgfortran/generated/cshift0_r16.c      |   2 +-
 libgfortran/generated/cshift0_r17.c      |   2 +-
 libgfortran/generated/cshift0_r4.c       |   2 +-
 libgfortran/generated/cshift0_r8.c       |   2 +-
 libgfortran/generated/cshift1_16.c       |   2 +-
 libgfortran/generated/cshift1_16_c10.c   |   2 +-
 libgfortran/generated/cshift1_16_c16.c   |   2 +-
 libgfortran/generated/cshift1_16_c17.c   |   2 +-
 libgfortran/generated/cshift1_16_c4.c    |   2 +-
 libgfortran/generated/cshift1_16_c8.c    |   2 +-
 libgfortran/generated/cshift1_16_i1.c    |   2 +-
 libgfortran/generated/cshift1_16_i16.c   |   2 +-
 libgfortran/generated/cshift1_16_i2.c    |   2 +-
 libgfortran/generated/cshift1_16_i4.c    |   2 +-
 libgfortran/generated/cshift1_16_i8.c    |   2 +-
 libgfortran/generated/cshift1_16_r10.c   |   2 +-
 libgfortran/generated/cshift1_16_r16.c   |   2 +-
 libgfortran/generated/cshift1_16_r17.c   |   2 +-
 libgfortran/generated/cshift1_16_r4.c    |   2 +-
 libgfortran/generated/cshift1_16_r8.c    |   2 +-
 libgfortran/generated/cshift1_4.c        |   2 +-
 libgfortran/generated/cshift1_4_c10.c    |   2 +-
 libgfortran/generated/cshift1_4_c16.c    |   2 +-
 libgfortran/generated/cshift1_4_c17.c    |   2 +-
 libgfortran/generated/cshift1_4_c4.c     |   2 +-
 libgfortran/generated/cshift1_4_c8.c     |   2 +-
 libgfortran/generated/cshift1_4_i1.c     |   2 +-
 libgfortran/generated/cshift1_4_i16.c    |   2 +-
 libgfortran/generated/cshift1_4_i2.c     |   2 +-
 libgfortran/generated/cshift1_4_i4.c     |   2 +-
 libgfortran/generated/cshift1_4_i8.c     |   2 +-
 libgfortran/generated/cshift1_4_r10.c    |   2 +-
 libgfortran/generated/cshift1_4_r16.c    |   2 +-
 libgfortran/generated/cshift1_4_r17.c    |   2 +-
 libgfortran/generated/cshift1_4_r4.c     |   2 +-
 libgfortran/generated/cshift1_4_r8.c     |   2 +-
 libgfortran/generated/cshift1_8.c        |   2 +-
 libgfortran/generated/cshift1_8_c10.c    |   2 +-
 libgfortran/generated/cshift1_8_c16.c    |   2 +-
 libgfortran/generated/cshift1_8_c17.c    |   2 +-
 libgfortran/generated/cshift1_8_c4.c     |   2 +-
 libgfortran/generated/cshift1_8_c8.c     |   2 +-
 libgfortran/generated/cshift1_8_i1.c     |   2 +-
 libgfortran/generated/cshift1_8_i16.c    |   2 +-
 libgfortran/generated/cshift1_8_i2.c     |   2 +-
 libgfortran/generated/cshift1_8_i4.c     |   2 +-
 libgfortran/generated/cshift1_8_i8.c     |   2 +-
 libgfortran/generated/cshift1_8_r10.c    |   2 +-
 libgfortran/generated/cshift1_8_r16.c    |   2 +-
 libgfortran/generated/cshift1_8_r17.c    |   2 +-
 libgfortran/generated/cshift1_8_r4.c     |   2 +-
 libgfortran/generated/cshift1_8_r8.c     |   2 +-
 libgfortran/generated/findloc1_c10.c     |   4 +-
 libgfortran/generated/findloc1_c16.c     |   4 +-
 libgfortran/generated/findloc1_c17.c     |   4 +-
 libgfortran/generated/findloc1_c4.c      |   4 +-
 libgfortran/generated/findloc1_c8.c      |   4 +-
 libgfortran/generated/findloc1_i1.c      |   4 +-
 libgfortran/generated/findloc1_i16.c     |   4 +-
 libgfortran/generated/findloc1_i2.c      |   4 +-
 libgfortran/generated/findloc1_i4.c      |   4 +-
 libgfortran/generated/findloc1_i8.c      |   4 +-
 libgfortran/generated/findloc1_r10.c     |   4 +-
 libgfortran/generated/findloc1_r16.c     |   4 +-
 libgfortran/generated/findloc1_r17.c     |   4 +-
 libgfortran/generated/findloc1_r4.c      |   4 +-
 libgfortran/generated/findloc1_r8.c      |   4 +-
 libgfortran/generated/findloc1_s1.c      |   4 +-
 libgfortran/generated/findloc1_s4.c      |   4 +-
 libgfortran/generated/matmul_c10.c       | 255 +++++++++++++++++--------------
 libgfortran/generated/matmul_c16.c       | 255 +++++++++++++++++--------------
 libgfortran/generated/matmul_c17.c       | 255 +++++++++++++++++--------------
 libgfortran/generated/matmul_c4.c        | 255 +++++++++++++++++--------------
 libgfortran/generated/matmul_c8.c        | 255 +++++++++++++++++--------------
 libgfortran/generated/matmul_i1.c        | 255 +++++++++++++++++--------------
 libgfortran/generated/matmul_i16.c       | 255 +++++++++++++++++--------------
 libgfortran/generated/matmul_i2.c        | 255 +++++++++++++++++--------------
 libgfortran/generated/matmul_i4.c        | 255 +++++++++++++++++--------------
 libgfortran/generated/matmul_i8.c        | 255 +++++++++++++++++--------------
 libgfortran/generated/matmul_r10.c       | 255 +++++++++++++++++--------------
 libgfortran/generated/matmul_r16.c       | 255 +++++++++++++++++--------------
 libgfortran/generated/matmul_r17.c       | 255 +++++++++++++++++--------------
 libgfortran/generated/matmul_r4.c        | 255 +++++++++++++++++--------------
 libgfortran/generated/matmul_r8.c        | 255 +++++++++++++++++--------------
 libgfortran/generated/matmulavx128_c10.c | 102 +++++++------
 libgfortran/generated/matmulavx128_c16.c | 102 +++++++------
 libgfortran/generated/matmulavx128_c17.c | 102 +++++++------
 libgfortran/generated/matmulavx128_c4.c  | 102 +++++++------
 libgfortran/generated/matmulavx128_c8.c  | 102 +++++++------
 libgfortran/generated/matmulavx128_i1.c  | 102 +++++++------
 libgfortran/generated/matmulavx128_i16.c | 102 +++++++------
 libgfortran/generated/matmulavx128_i2.c  | 102 +++++++------
 libgfortran/generated/matmulavx128_i4.c  | 102 +++++++------
 libgfortran/generated/matmulavx128_i8.c  | 102 +++++++------
 libgfortran/generated/matmulavx128_r10.c | 102 +++++++------
 libgfortran/generated/matmulavx128_r16.c | 102 +++++++------
 libgfortran/generated/matmulavx128_r17.c | 102 +++++++------
 libgfortran/generated/matmulavx128_r4.c  | 102 +++++++------
 libgfortran/generated/matmulavx128_r8.c  | 102 +++++++------
 110 files changed, 3037 insertions(+), 2512 deletions(-)

diff --git a/libgfortran/generated/cshift0_c10.c b/libgfortran/generated/cshift0_c10.c
index f7e2947aaf9d..3908c5b693f3 100644
--- a/libgfortran/generated/cshift0_c10.c
+++ b/libgfortran/generated/cshift0_c10.c
@@ -190,7 +190,7 @@ cshift0_c10 (gfc_array_c10 *ret, const gfc_array_c10 *array, ptrdiff_t shift,
 	  /* Otherwise, we will have to perform the copy one element at
 	     a time.  */
 	  GFC_COMPLEX_10 *dest = rptr;
-	  const GFC_COMPLEX_10 *src = (const GFC_COMPLEX_10 *) (((char*)sptr) + shift * soffset);
+	  const GFC_COMPLEX_10 *src = PTR_ADD_OFFSET (sptr, shift * soffset);
 
 	  for (n = 0; n < len - shift; n++)
 	    {
diff --git a/libgfortran/generated/cshift0_c16.c b/libgfortran/generated/cshift0_c16.c
index 5326c1fb2833..962c009f3568 100644
--- a/libgfortran/generated/cshift0_c16.c
+++ b/libgfortran/generated/cshift0_c16.c
@@ -190,7 +190,7 @@ cshift0_c16 (gfc_array_c16 *ret, const gfc_array_c16 *array, ptrdiff_t shift,
 	  /* Otherwise, we will have to perform the copy one element at
 	     a time.  */
 	  GFC_COMPLEX_16 *dest = rptr;
-	  const GFC_COMPLEX_16 *src = (const GFC_COMPLEX_16 *) (((char*)sptr) + shift * soffset);
+	  const GFC_COMPLEX_16 *src = PTR_ADD_OFFSET (sptr, shift * soffset);
 
 	  for (n = 0; n < len - shift; n++)
 	    {
diff --git a/libgfortran/generated/cshift0_c17.c b/libgfortran/generated/cshift0_c17.c
index 3309c8dfe96b..ebe965efcb5d 100644
--- a/libgfortran/generated/cshift0_c17.c
+++ b/libgfortran/generated/cshift0_c17.c
@@ -190,7 +190,7 @@ cshift0_c17 (gfc_array_c17 *ret, const gfc_array_c17 *array, ptrdiff_t shift,
 	  /* Otherwise, we will have to perform the copy one element at
 	     a time.  */
 	  GFC_COMPLEX_17 *dest = rptr;
-	  const GFC_COMPLEX_17 *src = (const GFC_COMPLEX_17 *) (((char*)sptr) + shift * soffset);
+	  const GFC_COMPLEX_17 *src = PTR_ADD_OFFSET (sptr, shift * soffset);
 
 	  for (n = 0; n < len - shift; n++)
 	    {
diff --git a/libgfortran/generated/cshift0_c4.c b/libgfortran/generated/cshift0_c4.c
index 64090375ba00..71758c0aed18 100644
--- a/libgfortran/generated/cshift0_c4.c
+++ b/libgfortran/generated/cshift0_c4.c
@@ -190,7 +190,7 @@ cshift0_c4 (gfc_array_c4 *ret, const gfc_array_c4 *array, ptrdiff_t shift,
 	  /* Otherwise, we will have to perform the copy one element at
 	     a time.  */
 	  GFC_COMPLEX_4 *dest = rptr;
-	  const GFC_COMPLEX_4 *src = (const GFC_COMPLEX_4 *) (((char*)sptr) + shift * soffset);
+	  const GFC_COMPLEX_4 *src = PTR_ADD_OFFSET (sptr, shift * soffset);
 
 	  for (n = 0; n < len - shift; n++)
 	    {
diff --git a/libgfortran/generated/cshift0_c8.c b/libgfortran/generated/cshift0_c8.c
index 756c0bb2bea2..1b9bff6e7627 100644
--- a/libgfortran/generated/cshift0_c8.c
+++ b/libgfortran/generated/cshift0_c8.c
@@ -190,7 +190,7 @@ cshift0_c8 (gfc_array_c8 *ret, const gfc_array_c8 *array, ptrdiff_t shift,
 	  /* Otherwise, we will have to perform the copy one element at
 	     a time.  */
 	  GFC_COMPLEX_8 *dest = rptr;
-	  const GFC_COMPLEX_8 *src = (const GFC_COMPLEX_8 *) (((char*)sptr) + shift * soffset);
+	  const GFC_COMPLEX_8 *src = PTR_ADD_OFFSET (sptr, shift * soffset);
 
 	  for (n = 0; n < len - shift; n++)
 	    {
diff --git a/libgfortran/generated/cshift0_i1.c b/libgfortran/generated/cshift0_i1.c
index e2bfebd2ece0..c34a72e8612f 100644
--- a/libgfortran/generated/cshift0_i1.c
+++ b/libgfortran/generated/cshift0_i1.c
@@ -190,7 +190,7 @@ cshift0_i1 (gfc_array_i1 *ret, const gfc_array_i1 *array, ptrdiff_t shift,
 	  /* Otherwise, we will have to perform the copy one element at
 	     a time.  */
 	  GFC_INTEGER_1 *dest = rptr;
-	  const GFC_INTEGER_1 *src = (const GFC_INTEGER_1 *) (((char*)sptr) + shift * soffset);
+	  const GFC_INTEGER_1 *src = PTR_ADD_OFFSET (sptr, shift * soffset);
 
 	  for (n = 0; n < len - shift; n++)
 	    {
diff --git a/libgfortran/generated/cshift0_i16.c b/libgfortran/generated/cshift0_i16.c
index b34d12a0bef3..01b502f5c538 100644
--- a/libgfortran/generated/cshift0_i16.c
+++ b/libgfortran/generated/cshift0_i16.c
@@ -190,7 +190,7 @@ cshift0_i16 (gfc_array_i16 *ret, const gfc_array_i16 *array, ptrdiff_t shift,
 	  /* Otherwise, we will have to perform the copy one element at
 	     a time.  */
 	  GFC_INTEGER_16 *dest = rptr;
-	  const GFC_INTEGER_16 *src = (const GFC_INTEGER_16 *) (((char*)sptr) + shift * soffset);
+	  const GFC_INTEGER_16 *src = PTR_ADD_OFFSET (sptr, shift * soffset);
 
 	  for (n = 0; n < len - shift; n++)
 	    {
diff --git a/libgfortran/generated/cshift0_i2.c b/libgfortran/generated/cshift0_i2.c
index 07b975a34236..743cb6ececda 100644
--- a/libgfortran/generated/cshift0_i2.c
+++ b/libgfortran/generated/cshift0_i2.c
@@ -190,7 +190,7 @@ cshift0_i2 (gfc_array_i2 *ret, const gfc_array_i2 *array, ptrdiff_t shift,
 	  /* Otherwise, we will have to perform the copy one element at
 	     a time.  */
 	  GFC_INTEGER_2 *dest = rptr;
-	  const GFC_INTEGER_2 *src = (const GFC_INTEGER_2 *) (((char*)sptr) + shift * soffset);
+	  const GFC_INTEGER_2 *src = PTR_ADD_OFFSET (sptr, shift * soffset);
 
 	  for (n = 0; n < len - shift; n++)
 	    {
diff --git a/libgfortran/generated/cshift0_i4.c b/libgfortran/generated/cshift0_i4.c
index 28ca14c35f3b..ccd1d2424a25 100644
--- a/libgfortran/generated/cshift0_i4.c
+++ b/libgfortran/generated/cshift0_i4.c
@@ -190,7 +190,7 @@ cshift0_i4 (gfc_array_i4 *ret, const gfc_array_i4 *array, ptrdiff_t shift,
 	  /* Otherwise, we will have to perform the copy one element at
 	     a time.  */
 	  GFC_INTEGER_4 *dest = rptr;
-	  const GFC_INTEGER_4 *src = (const GFC_INTEGER_4 *) (((char*)sptr) + shift * soffset);
+	  const GFC_INTEGER_4 *src = PTR_ADD_OFFSET (sptr, shift * soffset);
 
 	  for (n = 0; n < len - shift; n++)
 	    {
diff --git a/libgfortran/generated/cshift0_i8.c b/libgfortran/generated/cshift0_i8.c
index 76f6f5aac62b..defbb1149c08 100644
--- a/libgfortran/generated/cshift0_i8.c
+++ b/libgfortran/generated/cshift0_i8.c
@@ -190,7 +190,7 @@ cshift0_i8 (gfc_array_i8 *ret, const gfc_array_i8 *array, ptrdiff_t shift,
 	  /* Otherwise, we will have to perform the copy one element at
 	     a time.  */
 	  GFC_INTEGER_8 *dest = rptr;
-	  const GFC_INTEGER_8 *src = (const GFC_INTEGER_8 *) (((char*)sptr) + shift * soffset);
+	  const GFC_INTEGER_8 *src = PTR_ADD_OFFSET (sptr, shift * soffset);
 
 	  for (n = 0; n < len - shift; n++)
 	    {
diff --git a/libgfortran/generated/cshift0_r10.c b/libgfortran/generated/cshift0_r10.c
index 7b4406d3bad8..f40e42627e9e 100644
--- a/libgfortran/generated/cshift0_r10.c
+++ b/libgfortran/generated/cshift0_r10.c
@@ -190,7 +190,7 @@ cshift0_r10 (gfc_array_r10 *ret, const gfc_array_r10 *array, ptrdiff_t shift,
 	  /* Otherwise, we will have to perform the copy one element at
 	     a time.  */
 	  GFC_REAL_10 *dest = rptr;
-	  const GFC_REAL_10 *src = (const GFC_REAL_10 *) (((char*)sptr) + shift * soffset);
+	  const GFC_REAL_10 *src = PTR_ADD_OFFSET (sptr, shift * soffset);
 
 	  for (n = 0; n < len - shift; n++)
 	    {
diff --git a/libgfortran/generated/cshift0_r16.c b/libgfortran/generated/cshift0_r16.c
index fea3900f3368..cbd98f3e44fd 100644
--- a/libgfortran/generated/cshift0_r16.c
+++ b/libgfortran/generated/cshift0_r16.c
@@ -190,7 +190,7 @@ cshift0_r16 (gfc_array_r16 *ret, const gfc_array_r16 *array, ptrdiff_t shift,
 	  /* Otherwise, we will have to perform the copy one element at
 	     a time.  */
 	  GFC_REAL_16 *dest = rptr;
-	  const GFC_REAL_16 *src = (const GFC_REAL_16 *) (((char*)sptr) + shift * soffset);
+	  const GFC_REAL_16 *src = PTR_ADD_OFFSET (sptr, shift * soffset);
 
 	  for (n = 0; n < len - shift; n++)
 	    {
diff --git a/libgfortran/generated/cshift0_r17.c b/libgfortran/generated/cshift0_r17.c
index e4a056d7d146..a854dffc68c7 100644
--- a/libgfortran/generated/cshift0_r17.c
+++ b/libgfortran/generated/cshift0_r17.c
@@ -190,7 +190,7 @@ cshift0_r17 (gfc_array_r17 *ret, const gfc_array_r17 *array, ptrdiff_t shift,
 	  /* Otherwise, we will have to perform the copy one element at
 	     a time.  */
 	  GFC_REAL_17 *dest = rptr;
-	  const GFC_REAL_17 *src = (const GFC_REAL_17 *) (((char*)sptr) + shift * soffset);
+	  const GFC_REAL_17 *src = PTR_ADD_OFFSET (sptr, shift * soffset);
 
 	  for (n = 0; n < len - shift; n++)
 	    {
diff --git a/libgfortran/generated/cshift0_r4.c b/libgfortran/generated/cshift0_r4.c
index 82f8182a17fa..cb4b93062dad 100644
--- a/libgfortran/generated/cshift0_r4.c
+++ b/libgfortran/generated/cshift0_r4.c
@@ -190,7 +190,7 @@ cshift0_r4 (gfc_array_r4 *ret, const gfc_array_r4 *array, ptrdiff_t shift,
 	  /* Otherwise, we will have to perform the copy one element at
 	     a time.  */
 	  GFC_REAL_4 *dest = rptr;
-	  const GFC_REAL_4 *src = (const GFC_REAL_4 *) (((char*)sptr) + shift * soffset);
+	  const GFC_REAL_4 *src = PTR_ADD_OFFSET (sptr, shift * soffset);
 
 	  for (n = 0; n < len - shift; n++)
 	    {
diff --git a/libgfortran/generated/cshift0_r8.c b/libgfortran/generated/cshift0_r8.c
index 08da8bb81c73..8f5a67bffcc6 100644
--- a/libgfortran/generated/cshift0_r8.c
+++ b/libgfortran/generated/cshift0_r8.c
@@ -190,7 +190,7 @@ cshift0_r8 (gfc_array_r8 *ret, const gfc_array_r8 *array, ptrdiff_t shift,
 	  /* Otherwise, we will have to perform the copy one element at
 	     a time.  */
 	  GFC_REAL_8 *dest = rptr;
-	  const GFC_REAL_8 *src = (const GFC_REAL_8 *) (((char*)sptr) + shift * soffset);
+	  const GFC_REAL_8 *src = PTR_ADD_OFFSET (sptr, shift * soffset);
 
 	  for (n = 0; n < len - shift; n++)
 	    {
diff --git a/libgfortran/generated/cshift1_16.c b/libgfortran/generated/cshift1_16.c
index 80e1a9ccb5a0..d7fc6012339e 100644
--- a/libgfortran/generated/cshift1_16.c
+++ b/libgfortran/generated/cshift1_16.c
@@ -263,7 +263,7 @@ cshift1 (gfc_array_char * const restrict ret,
 	    sh += len;
 	}
 
-      src = &sptr[sh * soffset];
+      src = PTR_ADD_OFFSET (sptr, sh * soffset);
       dest = rptr;
       if (soffset == size && roffset == size)
       {
diff --git a/libgfortran/generated/cshift1_16_c10.c b/libgfortran/generated/cshift1_16_c10.c
index 82d97fda8317..d77f41b29ad8 100644
--- a/libgfortran/generated/cshift1_16_c10.c
+++ b/libgfortran/generated/cshift1_16_c10.c
@@ -133,7 +133,7 @@ cshift1_16_c10 (gfc_array_c10 * const restrict ret,
 	  if (sh < 0)
             sh += len;
 	}
-      src = (const GFC_COMPLEX_10 *) (((char*)sptr) + sh * soffset);
+      src = PTR_ADD_OFFSET (sptr, sh * soffset);
       dest = rptr;
       if (soffset == sizeof (GFC_COMPLEX_10) && roffset == sizeof (GFC_COMPLEX_10))
 	{
diff --git a/libgfortran/generated/cshift1_16_c16.c b/libgfortran/generated/cshift1_16_c16.c
index 2f4c6b47d882..bbbb8534e2cd 100644
--- a/libgfortran/generated/cshift1_16_c16.c
+++ b/libgfortran/generated/cshift1_16_c16.c
@@ -133,7 +133,7 @@ cshift1_16_c16 (gfc_array_c16 * const restrict ret,
 	  if (sh < 0)
             sh += len;
 	}
-      src = (const GFC_COMPLEX_16 *) (((char*)sptr) + sh * soffset);
+      src = PTR_ADD_OFFSET (sptr, sh * soffset);
       dest = rptr;
       if (soffset == sizeof (GFC_COMPLEX_16) && roffset == sizeof (GFC_COMPLEX_16))
 	{
diff --git a/libgfortran/generated/cshift1_16_c17.c b/libgfortran/generated/cshift1_16_c17.c
index 154021e50ee1..97473a49a4e9 100644
--- a/libgfortran/generated/cshift1_16_c17.c
+++ b/libgfortran/generated/cshift1_16_c17.c
@@ -133,7 +133,7 @@ cshift1_16_c17 (gfc_array_c17 * const restrict ret,
 	  if (sh < 0)
             sh += len;
 	}
-      src = (const GFC_COMPLEX_17 *) (((char*)sptr) + sh * soffset);
+      src = PTR_ADD_OFFSET (sptr, sh * soffset);
       dest = rptr;
       if (soffset == sizeof (GFC_COMPLEX_17) && roffset == sizeof (GFC_COMPLEX_17))
 	{
diff --git a/libgfortran/generated/cshift1_16_c4.c b/libgfortran/generated/cshift1_16_c4.c
index a14bf888bc04..a4016c2fa6f4 100644
--- a/libgfortran/generated/cshift1_16_c4.c
+++ b/libgfortran/generated/cshift1_16_c4.c
@@ -133,7 +133,7 @@ cshift1_16_c4 (gfc_array_c4 * const restrict ret,
 	  if (sh < 0)
             sh += len;
 	}
-      src = (const GFC_COMPLEX_4 *) (((char*)sptr) + sh * soffset);
+      src = PTR_ADD_OFFSET (sptr, sh * soffset);
       dest = rptr;
       if (soffset == sizeof (GFC_COMPLEX_4) && roffset == sizeof (GFC_COMPLEX_4))
 	{
diff --git a/libgfortran/generated/cshift1_16_c8.c b/libgfortran/generated/cshift1_16_c8.c
index 6ae7f93ec3a4..c80ec8a44ffe 100644
--- a/libgfortran/generated/cshift1_16_c8.c
+++ b/libgfortran/generated/cshift1_16_c8.c
@@ -133,7 +133,7 @@ cshift1_16_c8 (gfc_array_c8 * const restrict ret,
 	  if (sh < 0)
             sh += len;
 	}
-      src = (const GFC_COMPLEX_8 *) (((char*)sptr) + sh * soffset);
+      src = PTR_ADD_OFFSET (sptr, sh * soffset);
       dest = rptr;
       if (soffset == sizeof (GFC_COMPLEX_8) && roffset == sizeof (GFC_COMPLEX_8))
 	{
diff --git a/libgfortran/generated/cshift1_16_i1.c b/libgfortran/generated/cshift1_16_i1.c
index f1027f85028d..c245f56ac116 100644
--- a/libgfortran/generated/cshift1_16_i1.c
+++ b/libgfortran/generated/cshift1_16_i1.c
@@ -133,7 +133,7 @@ cshift1_16_i1 (gfc_array_i1 * const restrict ret,
 	  if (sh < 0)
             sh += len;
 	}
-      src = (const GFC_INTEGER_1 *) (((char*)sptr) + sh * soffset);
+      src = PTR_ADD_OFFSET (sptr, sh * soffset);
       dest = rptr;
       if (soffset == sizeof (GFC_INTEGER_1) && roffset == sizeof (GFC_INTEGER_1))
 	{
diff --git a/libgfortran/generated/cshift1_16_i16.c b/libgfortran/generated/cshift1_16_i16.c
index 29b24d5ad8af..aa98c12b1df2 100644
--- a/libgfortran/generated/cshift1_16_i16.c
+++ b/libgfortran/generated/cshift1_16_i16.c
@@ -133,7 +133,7 @@ cshift1_16_i16 (gfc_array_i16 * const restrict ret,
 	  if (sh < 0)
             sh += len;
 	}
-      src = (const GFC_INTEGER_16 *) (((char*)sptr) + sh * soffset);
+      src = PTR_ADD_OFFSET (sptr, sh * soffset);
       dest = rptr;
       if (soffset == sizeof (GFC_INTEGER_16) && roffset == sizeof (GFC_INTEGER_16))
 	{
diff --git a/libgfortran/generated/cshift1_16_i2.c b/libgfortran/generated/cshift1_16_i2.c
index 27f38b6428b1..2b7faeb2b22d 100644
--- a/libgfortran/generated/cshift1_16_i2.c
+++ b/libgfortran/generated/cshift1_16_i2.c
@@ -133,7 +133,7 @@ cshift1_16_i2 (gfc_array_i2 * const restrict ret,
 	  if (sh < 0)
             sh += len;
 	}
-      src = (const GFC_INTEGER_2 *) (((char*)sptr) + sh * soffset);
+      src = PTR_ADD_OFFSET (sptr, sh * soffset);
       dest = rptr;
       if (soffset == sizeof (GFC_INTEGER_2) && roffset == sizeof (GFC_INTEGER_2))
 	{
diff --git a/libgfortran/generated/cshift1_16_i4.c b/libgfortran/generated/cshift1_16_i4.c
index 4c1026a5bdec..682217316680 100644
--- a/libgfortran/generated/cshift1_16_i4.c
+++ b/libgfortran/generated/cshift1_16_i4.c
@@ -133,7 +133,7 @@ cshift1_16_i4 (gfc_array_i4 * const restrict ret,
 	  if (sh < 0)
             sh += len;
 	}
-      src = (const GFC_INTEGER_4 *) (((char*)sptr) + sh * soffset);
+      src = PTR_ADD_OFFSET (sptr, sh * soffset);
       dest = rptr;
       if (soffset == sizeof (GFC_INTEGER_4) && roffset == sizeof (GFC_INTEGER_4))
 	{
diff --git a/libgfortran/generated/cshift1_16_i8.c b/libgfortran/generated/cshift1_16_i8.c
index e887c3e6d64a..151776087f68 100644
--- a/libgfortran/generated/cshift1_16_i8.c
+++ b/libgfortran/generated/cshift1_16_i8.c
@@ -133,7 +133,7 @@ cshift1_16_i8 (gfc_array_i8 * const restrict ret,
 	  if (sh < 0)
             sh += len;
 	}
-      src = (const GFC_INTEGER_8 *) (((char*)sptr) + sh * soffset);
+      src = PTR_ADD_OFFSET (sptr, sh * soffset);
       dest = rptr;
       if (soffset == sizeof (GFC_INTEGER_8) && roffset == sizeof (GFC_INTEGER_8))
 	{
diff --git a/libgfortran/generated/cshift1_16_r10.c b/libgfortran/generated/cshift1_16_r10.c
index ba4671d2522c..5fadbd9e56b8 100644
--- a/libgfortran/generated/cshift1_16_r10.c
+++ b/libgfortran/generated/cshift1_16_r10.c
@@ -133,7 +133,7 @@ cshift1_16_r10 (gfc_array_r10 * const restrict ret,
 	  if (sh < 0)
             sh += len;
 	}
-      src = (const GFC_REAL_10 *) (((char*)sptr) + sh * soffset);
+      src = PTR_ADD_OFFSET (sptr, sh * soffset);
       dest = rptr;
       if (soffset == sizeof (GFC_REAL_10) && roffset == sizeof (GFC_REAL_10))
 	{
diff --git a/libgfortran/generated/cshift1_16_r16.c b/libgfortran/generated/cshift1_16_r16.c
index b37066485799..bddc6beeb9d3 100644
--- a/libgfortran/generated/cshift1_16_r16.c
+++ b/libgfortran/generated/cshift1_16_r16.c
@@ -133,7 +133,7 @@ cshift1_16_r16 (gfc_array_r16 * const restrict ret,
 	  if (sh < 0)
             sh += len;
 	}
-      src = (const GFC_REAL_16 *) (((char*)sptr) + sh * soffset);
+      src = PTR_ADD_OFFSET (sptr, sh * soffset);
       dest = rptr;
       if (soffset == sizeof (GFC_REAL_16) && roffset == sizeof (GFC_REAL_16))
 	{
diff --git a/libgfortran/generated/cshift1_16_r17.c b/libgfortran/generated/cshift1_16_r17.c
index 0503312a6fac..20a2b6c5d5d8 100644
--- a/libgfortran/generated/cshift1_16_r17.c
+++ b/libgfortran/generated/cshift1_16_r17.c
@@ -133,7 +133,7 @@ cshift1_16_r17 (gfc_array_r17 * const restrict ret,
 	  if (sh < 0)
             sh += len;
 	}
-      src = (const GFC_REAL_17 *) (((char*)sptr) + sh * soffset);
+      src = PTR_ADD_OFFSET (sptr, sh * soffset);
       dest = rptr;
       if (soffset == sizeof (GFC_REAL_17) && roffset == sizeof (GFC_REAL_17))
 	{
diff --git a/libgfortran/generated/cshift1_16_r4.c b/libgfortran/generated/cshift1_16_r4.c
index 8fa510861ca9..8b95aecda015 100644
--- a/libgfortran/generated/cshift1_16_r4.c
+++ b/libgfortran/generated/cshift1_16_r4.c
@@ -133,7 +133,7 @@ cshift1_16_r4 (gfc_array_r4 * const restrict ret,
 	  if (sh < 0)
             sh += len;
 	}
-      src = (const GFC_REAL_4 *) (((char*)sptr) + sh * soffset);
+      src = PTR_ADD_OFFSET (sptr, sh * soffset);
       dest = rptr;
       if (soffset == sizeof (GFC_REAL_4) && roffset == sizeof (GFC_REAL_4))
 	{
diff --git a/libgfortran/generated/cshift1_16_r8.c b/libgfortran/generated/cshift1_16_r8.c
index d6382f0925eb..5ebf723ce54f 100644
--- a/libgfortran/generated/cshift1_16_r8.c
+++ b/libgfortran/generated/cshift1_16_r8.c
@@ -133,7 +133,7 @@ cshift1_16_r8 (gfc_array_r8 * const restrict ret,
 	  if (sh < 0)
             sh += len;
 	}
-      src = (const GFC_REAL_8 *) (((char*)sptr) + sh * soffset);
+      src = PTR_ADD_OFFSET (sptr, sh * soffset);
       dest = rptr;
       if (soffset == sizeof (GFC_REAL_8) && roffset == sizeof (GFC_REAL_8))
 	{
diff --git a/libgfortran/generated/cshift1_4.c b/libgfortran/generated/cshift1_4.c
index 72bea1b83913..ec92dbc48cda 100644
--- a/libgfortran/generated/cshift1_4.c
+++ b/libgfortran/generated/cshift1_4.c
@@ -263,7 +263,7 @@ cshift1 (gfc_array_char * const restrict ret,
 	    sh += len;
 	}
 
-      src = &sptr[sh * soffset];
+      src = PTR_ADD_OFFSET (sptr, sh * soffset);
       dest = rptr;
       if (soffset == size && roffset == size)
       {
diff --git a/libgfortran/generated/cshift1_4_c10.c b/libgfortran/generated/cshift1_4_c10.c
index c941af142198..84d5163ece3b 100644
--- a/libgfortran/generated/cshift1_4_c10.c
+++ b/libgfortran/generated/cshift1_4_c10.c
@@ -133,7 +133,7 @@ cshift1_4_c10 (gfc_array_c10 * const restrict ret,
 	  if (sh < 0)
             sh += len;
 	}
-      src = (const GFC_COMPLEX_10 *) (((char*)sptr) + sh * soffset);
+      src = PTR_ADD_OFFSET (sptr, sh * soffset);
       dest = rptr;
       if (soffset == sizeof (GFC_COMPLEX_10) && roffset == sizeof (GFC_COMPLEX_10))
 	{
diff --git a/libgfortran/generated/cshift1_4_c16.c b/libgfortran/generated/cshift1_4_c16.c
index 498d632b4ee4..4b5f36b9dbef 100644
--- a/libgfortran/generated/cshift1_4_c16.c
+++ b/libgfortran/generated/cshift1_4_c16.c
@@ -133,7 +133,7 @@ cshift1_4_c16 (gfc_array_c16 * const restrict ret,
 	  if (sh < 0)
             sh += len;
 	}
-      src = (const GFC_COMPLEX_16 *) (((char*)sptr) + sh * soffset);
+      src = PTR_ADD_OFFSET (sptr, sh * soffset);
       dest = rptr;
       if (soffset == sizeof (GFC_COMPLEX_16) && roffset == sizeof (GFC_COMPLEX_16))
 	{
diff --git a/libgfortran/generated/cshift1_4_c17.c b/libgfortran/generated/cshift1_4_c17.c
index ad132772e73e..311a4c615057 100644
--- a/libgfortran/generated/cshift1_4_c17.c
+++ b/libgfortran/generated/cshift1_4_c17.c
@@ -133,7 +133,7 @@ cshift1_4_c17 (gfc_array_c17 * const restrict ret,
 	  if (sh < 0)
             sh += len;
 	}
-      src = (const GFC_COMPLEX_17 *) (((char*)sptr) + sh * soffset);
+      src = PTR_ADD_OFFSET (sptr, sh * soffset);
       dest = rptr;
       if (soffset == sizeof (GFC_COMPLEX_17) && roffset == sizeof (GFC_COMPLEX_17))
 	{
diff --git a/libgfortran/generated/cshift1_4_c4.c b/libgfortran/generated/cshift1_4_c4.c
index 595d6607288b..13d64a7ca90e 100644
--- a/libgfortran/generated/cshift1_4_c4.c
+++ b/libgfortran/generated/cshift1_4_c4.c
@@ -133,7 +133,7 @@ cshift1_4_c4 (gfc_array_c4 * const restrict ret,
 	  if (sh < 0)
             sh += len;
 	}
-      src = (const GFC_COMPLEX_4 *) (((char*)sptr) + sh * soffset);
+      src = PTR_ADD_OFFSET (sptr, sh * soffset);
       dest = rptr;
       if (soffset == sizeof (GFC_COMPLEX_4) && roffset == sizeof (GFC_COMPLEX_4))
 	{
diff --git a/libgfortran/generated/cshift1_4_c8.c b/libgfortran/generated/cshift1_4_c8.c
index 09b33f219a77..aa2911aef027 100644
--- a/libgfortran/generated/cshift1_4_c8.c
+++ b/libgfortran/generated/cshift1_4_c8.c
@@ -133,7 +133,7 @@ cshift1_4_c8 (gfc_array_c8 * const restrict ret,
 	  if (sh < 0)
             sh += len;
 	}
-      src = (const GFC_COMPLEX_8 *) (((char*)sptr) + sh * soffset);
+      src = PTR_ADD_OFFSET (sptr, sh * soffset);
       dest = rptr;
       if (soffset == sizeof (GFC_COMPLEX_8) && roffset == sizeof (GFC_COMPLEX_8))
 	{
diff --git a/libgfortran/generated/cshift1_4_i1.c b/libgfortran/generated/cshift1_4_i1.c
index cbba837c1bf0..a3925ad7b10f 100644
--- a/libgfortran/generated/cshift1_4_i1.c
+++ b/libgfortran/generated/cshift1_4_i1.c
@@ -133,7 +133,7 @@ cshift1_4_i1 (gfc_array_i1 * const restrict ret,
 	  if (sh < 0)
             sh += len;
 	}
-      src = (const GFC_INTEGER_1 *) (((char*)sptr) + sh * soffset);
+      src = PTR_ADD_OFFSET (sptr, sh * soffset);
       dest = rptr;
       if (soffset == sizeof (GFC_INTEGER_1) && roffset == sizeof (GFC_INTEGER_1))
 	{
diff --git a/libgfortran/generated/cshift1_4_i16.c b/libgfortran/generated/cshift1_4_i16.c
index fd0ab4fd2bb7..a9b2006054fc 100644
--- a/libgfortran/generated/cshift1_4_i16.c
+++ b/libgfortran/generated/cshift1_4_i16.c
@@ -133,7 +133,7 @@ cshift1_4_i16 (gfc_array_i16 * const restrict ret,
 	  if (sh < 0)
             sh += len;
 	}
-      src = (const GFC_INTEGER_16 *) (((char*)sptr) + sh * soffset);
+      src = PTR_ADD_OFFSET (sptr, sh * soffset);
       dest = rptr;
       if (soffset == sizeof (GFC_INTEGER_16) && roffset == sizeof (GFC_INTEGER_16))
 	{
diff --git a/libgfortran/generated/cshift1_4_i2.c b/libgfortran/generated/cshift1_4_i2.c
index 16e31cb72b70..42ab18268b40 100644
--- a/libgfortran/generated/cshift1_4_i2.c
+++ b/libgfortran/generated/cshift1_4_i2.c
@@ -133,7 +133,7 @@ cshift1_4_i2 (gfc_array_i2 * const restrict ret,
 	  if (sh < 0)
             sh += len;
 	}
-      src = (const GFC_INTEGER_2 *) (((char*)sptr) + sh * soffset);
+      src = PTR_ADD_OFFSET (sptr, sh * soffset);
       dest = rptr;
       if (soffset == sizeof (GFC_INTEGER_2) && roffset == sizeof (GFC_INTEGER_2))
 	{
diff --git a/libgfortran/generated/cshift1_4_i4.c b/libgfortran/generated/cshift1_4_i4.c
index 9808c8c3e2fd..9eb391c3e16c 100644
--- a/libgfortran/generated/cshift1_4_i4.c
+++ b/libgfortran/generated/cshift1_4_i4.c
@@ -133,7 +133,7 @@ cshift1_4_i4 (gfc_array_i4 * const restrict ret,
 	  if (sh < 0)
             sh += len;
 	}
-      src = (const GFC_INTEGER_4 *) (((char*)sptr) + sh * soffset);
+      src = PTR_ADD_OFFSET (sptr, sh * soffset);
       dest = rptr;
       if (soffset == sizeof (GFC_INTEGER_4) && roffset == sizeof (GFC_INTEGER_4))
 	{
diff --git a/libgfortran/generated/cshift1_4_i8.c b/libgfortran/generated/cshift1_4_i8.c
index 8d88732320ce..c4238ccb0f90 100644
--- a/libgfortran/generated/cshift1_4_i8.c
+++ b/libgfortran/generated/cshift1_4_i8.c
@@ -133,7 +133,7 @@ cshift1_4_i8 (gfc_array_i8 * const restrict ret,
 	  if (sh < 0)
             sh += len;
 	}
-      src = (const GFC_INTEGER_8 *) (((char*)sptr) + sh * soffset);
+      src = PTR_ADD_OFFSET (sptr, sh * soffset);
       dest = rptr;
       if (soffset == sizeof (GFC_INTEGER_8) && roffset == sizeof (GFC_INTEGER_8))
 	{
diff --git a/libgfortran/generated/cshift1_4_r10.c b/libgfortran/generated/cshift1_4_r10.c
index f389be10b00d..bdd0db006313 100644
--- a/libgfortran/generated/cshift1_4_r10.c
+++ b/libgfortran/generated/cshift1_4_r10.c
@@ -133,7 +133,7 @@ cshift1_4_r10 (gfc_array_r10 * const restrict ret,
 	  if (sh < 0)
             sh += len;
 	}
-      src = (const GFC_REAL_10 *) (((char*)sptr) + sh * soffset);
+      src = PTR_ADD_OFFSET (sptr, sh * soffset);
       dest = rptr;
       if (soffset == sizeof (GFC_REAL_10) && roffset == sizeof (GFC_REAL_10))
 	{
diff --git a/libgfortran/generated/cshift1_4_r16.c b/libgfortran/generated/cshift1_4_r16.c
index 2fa14a47e590..5b3a77da6580 100644
--- a/libgfortran/generated/cshift1_4_r16.c
+++ b/libgfortran/generated/cshift1_4_r16.c
@@ -133,7 +133,7 @@ cshift1_4_r16 (gfc_array_r16 * const restrict ret,
 	  if (sh < 0)
             sh += len;
 	}
-      src = (const GFC_REAL_16 *) (((char*)sptr) + sh * soffset);
+      src = PTR_ADD_OFFSET (sptr, sh * soffset);
       dest = rptr;
       if (soffset == sizeof (GFC_REAL_16) && roffset == sizeof (GFC_REAL_16))
 	{
diff --git a/libgfortran/generated/cshift1_4_r17.c b/libgfortran/generated/cshift1_4_r17.c
index 1458611a7f47..b9f14b466c1c 100644
--- a/libgfortran/generated/cshift1_4_r17.c
+++ b/libgfortran/generated/cshift1_4_r17.c
@@ -133,7 +133,7 @@ cshift1_4_r17 (gfc_array_r17 * const restrict ret,
 	  if (sh < 0)
             sh += len;
 	}
-      src = (const GFC_REAL_17 *) (((char*)sptr) + sh * soffset);
+      src = PTR_ADD_OFFSET (sptr, sh * soffset);
       dest = rptr;
       if (soffset == sizeof (GFC_REAL_17) && roffset == sizeof (GFC_REAL_17))
 	{
diff --git a/libgfortran/generated/cshift1_4_r4.c b/libgfortran/generated/cshift1_4_r4.c
index 6a1e307e5a79..5f5001f1327d 100644
--- a/libgfortran/generated/cshift1_4_r4.c
+++ b/libgfortran/generated/cshift1_4_r4.c
@@ -133,7 +133,7 @@ cshift1_4_r4 (gfc_array_r4 * const restrict ret,
 	  if (sh < 0)
             sh += len;
 	}
-      src = (const GFC_REAL_4 *) (((char*)sptr) + sh * soffset);
+      src = PTR_ADD_OFFSET (sptr, sh * soffset);
       dest = rptr;
       if (soffset == sizeof (GFC_REAL_4) && roffset == sizeof (GFC_REAL_4))
 	{
diff --git a/libgfortran/generated/cshift1_4_r8.c b/libgfortran/generated/cshift1_4_r8.c
index b8e7fcf8df64..34680890a632 100644
--- a/libgfortran/generated/cshift1_4_r8.c
+++ b/libgfortran/generated/cshift1_4_r8.c
@@ -133,7 +133,7 @@ cshift1_4_r8 (gfc_array_r8 * const restrict ret,
 	  if (sh < 0)
             sh += len;
 	}
-      src = (const GFC_REAL_8 *) (((char*)sptr) + sh * soffset);
+      src = PTR_ADD_OFFSET (sptr, sh * soffset);
       dest = rptr;
       if (soffset == sizeof (GFC_REAL_8) && roffset == sizeof (GFC_REAL_8))
 	{
diff --git a/libgfortran/generated/cshift1_8.c b/libgfortran/generated/cshift1_8.c
index c9e682afe42e..db8f0df9d19c 100644
--- a/libgfortran/generated/cshift1_8.c
+++ b/libgfortran/generated/cshift1_8.c
@@ -263,7 +263,7 @@ cshift1 (gfc_array_char * const restrict ret,
 	    sh += len;
 	}
 
-      src = &sptr[sh * soffset];
+      src = PTR_ADD_OFFSET (sptr, sh * soffset);
       dest = rptr;
       if (soffset == size && roffset == size)
       {
diff --git a/libgfortran/generated/cshift1_8_c10.c b/libgfortran/generated/cshift1_8_c10.c
index 618d2c54b3f2..051f11962f35 100644
--- a/libgfortran/generated/cshift1_8_c10.c
+++ b/libgfortran/generated/cshift1_8_c10.c
@@ -133,7 +133,7 @@ cshift1_8_c10 (gfc_array_c10 * const restrict ret,
 	  if (sh < 0)
             sh += len;
 	}
-      src = (const GFC_COMPLEX_10 *) (((char*)sptr) + sh * soffset);
+      src = PTR_ADD_OFFSET (sptr, sh * soffset);
       dest = rptr;
       if (soffset == sizeof (GFC_COMPLEX_10) && roffset == sizeof (GFC_COMPLEX_10))
 	{
diff --git a/libgfortran/generated/cshift1_8_c16.c b/libgfortran/generated/cshift1_8_c16.c
index 66b9848960d8..e4da26cf24d1 100644
--- a/libgfortran/generated/cshift1_8_c16.c
+++ b/libgfortran/generated/cshift1_8_c16.c
@@ -133,7 +133,7 @@ cshift1_8_c16 (gfc_array_c16 * const restrict ret,
 	  if (sh < 0)
             sh += len;
 	}
-      src = (const GFC_COMPLEX_16 *) (((char*)sptr) + sh * soffset);
+      src = PTR_ADD_OFFSET (sptr, sh * soffset);
       dest = rptr;
       if (soffset == sizeof (GFC_COMPLEX_16) && roffset == sizeof (GFC_COMPLEX_16))
 	{
diff --git a/libgfortran/generated/cshift1_8_c17.c b/libgfortran/generated/cshift1_8_c17.c
index 21d3709427c9..40a04791ac7f 100644
--- a/libgfortran/generated/cshift1_8_c17.c
+++ b/libgfortran/generated/cshift1_8_c17.c
@@ -133,7 +133,7 @@ cshift1_8_c17 (gfc_array_c17 * const restrict ret,
 	  if (sh < 0)
             sh += len;
 	}
-      src = (const GFC_COMPLEX_17 *) (((char*)sptr) + sh * soffset);
+      src = PTR_ADD_OFFSET (sptr, sh * soffset);
       dest = rptr;
       if (soffset == sizeof (GFC_COMPLEX_17) && roffset == sizeof (GFC_COMPLEX_17))
 	{
diff --git a/libgfortran/generated/cshift1_8_c4.c b/libgfortran/generated/cshift1_8_c4.c
index 0088bb7e966f..e74079f549ca 100644
--- a/libgfortran/generated/cshift1_8_c4.c
+++ b/libgfortran/generated/cshift1_8_c4.c
@@ -133,7 +133,7 @@ cshift1_8_c4 (gfc_array_c4 * const restrict ret,
 	  if (sh < 0)
             sh += len;
 	}
-      src = (const GFC_COMPLEX_4 *) (((char*)sptr) + sh * soffset);
+      src = PTR_ADD_OFFSET (sptr, sh * soffset);
       dest = rptr;
       if (soffset == sizeof (GFC_COMPLEX_4) && roffset == sizeof (GFC_COMPLEX_4))
 	{
diff --git a/libgfortran/generated/cshift1_8_c8.c b/libgfortran/generated/cshift1_8_c8.c
index 01a135da4f8f..f9e38a1c807b 100644
--- a/libgfortran/generated/cshift1_8_c8.c
+++ b/libgfortran/generated/cshift1_8_c8.c
@@ -133,7 +133,7 @@ cshift1_8_c8 (gfc_array_c8 * const restrict ret,
 	  if (sh < 0)
             sh += len;
 	}
-      src = (const GFC_COMPLEX_8 *) (((char*)sptr) + sh * soffset);
+      src = PTR_ADD_OFFSET (sptr, sh * soffset);
       dest = rptr;
       if (soffset == sizeof (GFC_COMPLEX_8) && roffset == sizeof (GFC_COMPLEX_8))
 	{
diff --git a/libgfortran/generated/cshift1_8_i1.c b/libgfortran/generated/cshift1_8_i1.c
index 4e306300402c..b2a0c5c436bd 100644
--- a/libgfortran/generated/cshift1_8_i1.c
+++ b/libgfortran/generated/cshift1_8_i1.c
@@ -133,7 +133,7 @@ cshift1_8_i1 (gfc_array_i1 * const restrict ret,
 	  if (sh < 0)
             sh += len;
 	}
-      src = (const GFC_INTEGER_1 *) (((char*)sptr) + sh * soffset);
+      src = PTR_ADD_OFFSET (sptr, sh * soffset);
       dest = rptr;
       if (soffset == sizeof (GFC_INTEGER_1) && roffset == sizeof (GFC_INTEGER_1))
 	{
diff --git a/libgfortran/generated/cshift1_8_i16.c b/libgfortran/generated/cshift1_8_i16.c
index 7dbd34b2b182..beaa7f9cf71d 100644
--- a/libgfortran/generated/cshift1_8_i16.c
+++ b/libgfortran/generated/cshift1_8_i16.c
@@ -133,7 +133,7 @@ cshift1_8_i16 (gfc_array_i16 * const restrict ret,
 	  if (sh < 0)
             sh += len;
 	}
-      src = (const GFC_INTEGER_16 *) (((char*)sptr) + sh * soffset);
+      src = PTR_ADD_OFFSET (sptr, sh * soffset);
       dest = rptr;
       if (soffset == sizeof (GFC_INTEGER_16) && roffset == sizeof (GFC_INTEGER_16))
 	{
diff --git a/libgfortran/generated/cshift1_8_i2.c b/libgfortran/generated/cshift1_8_i2.c
index 80eb2f58ecdb..80c19b9bd965 100644
--- a/libgfortran/generated/cshift1_8_i2.c
+++ b/libgfortran/generated/cshift1_8_i2.c
@@ -133,7 +133,7 @@ cshift1_8_i2 (gfc_array_i2 * const restrict ret,
 	  if (sh < 0)
             sh += len;
 	}
-      src = (const GFC_INTEGER_2 *) (((char*)sptr) + sh * soffset);
+      src = PTR_ADD_OFFSET (sptr, sh * soffset);
       dest = rptr;
       if (soffset == sizeof (GFC_INTEGER_2) && roffset == sizeof (GFC_INTEGER_2))
 	{
diff --git a/libgfortran/generated/cshift1_8_i4.c b/libgfortran/generated/cshift1_8_i4.c
index 48c4954abc56..fa7a43e18946 100644
--- a/libgfortran/generated/cshift1_8_i4.c
+++ b/libgfortran/generated/cshift1_8_i4.c
@@ -133,7 +133,7 @@ cshift1_8_i4 (gfc_array_i4 * const restrict ret,
 	  if (sh < 0)
             sh += len;
 	}
-      src = (const GFC_INTEGER_4 *) (((char*)sptr) + sh * soffset);
+      src = PTR_ADD_OFFSET (sptr, sh * soffset);
       dest = rptr;
       if (soffset == sizeof (GFC_INTEGER_4) && roffset == sizeof (GFC_INTEGER_4))
 	{
diff --git a/libgfortran/generated/cshift1_8_i8.c b/libgfortran/generated/cshift1_8_i8.c
index 16605311c5d4..db5dadae0f2e 100644
--- a/libgfortran/generated/cshift1_8_i8.c
+++ b/libgfortran/generated/cshift1_8_i8.c
@@ -133,7 +133,7 @@ cshift1_8_i8 (gfc_array_i8 * const restrict ret,
 	  if (sh < 0)
             sh += len;
 	}
-      src = (const GFC_INTEGER_8 *) (((char*)sptr) + sh * soffset);
+      src = PTR_ADD_OFFSET (sptr, sh * soffset);
       dest = rptr;
       if (soffset == sizeof (GFC_INTEGER_8) && roffset == sizeof (GFC_INTEGER_8))
 	{
diff --git a/libgfortran/generated/cshift1_8_r10.c b/libgfortran/generated/cshift1_8_r10.c
index ae92bbf2a505..74f47dd05543 100644
--- a/libgfortran/generated/cshift1_8_r10.c
+++ b/libgfortran/generated/cshift1_8_r10.c
@@ -133,7 +133,7 @@ cshift1_8_r10 (gfc_array_r10 * const restrict ret,
 	  if (sh < 0)
             sh += len;
 	}
-      src = (const GFC_REAL_10 *) (((char*)sptr) + sh * soffset);
+      src = PTR_ADD_OFFSET (sptr, sh * soffset);
       dest = rptr;
       if (soffset == sizeof (GFC_REAL_10) && roffset == sizeof (GFC_REAL_10))
 	{
diff --git a/libgfortran/generated/cshift1_8_r16.c b/libgfortran/generated/cshift1_8_r16.c
index 9bd82ecd220d..fdf7bbef1d7a 100644
--- a/libgfortran/generated/cshift1_8_r16.c
+++ b/libgfortran/generated/cshift1_8_r16.c
@@ -133,7 +133,7 @@ cshift1_8_r16 (gfc_array_r16 * const restrict ret,
 	  if (sh < 0)
             sh += len;
 	}
-      src = (const GFC_REAL_16 *) (((char*)sptr) + sh * soffset);
+      src = PTR_ADD_OFFSET (sptr, sh * soffset);
       dest = rptr;
       if (soffset == sizeof (GFC_REAL_16) && roffset == sizeof (GFC_REAL_16))
 	{
diff --git a/libgfortran/generated/cshift1_8_r17.c b/libgfortran/generated/cshift1_8_r17.c
index 8014b4491d19..fd91cb998d00 100644
--- a/libgfortran/generated/cshift1_8_r17.c
+++ b/libgfortran/generated/cshift1_8_r17.c
@@ -133,7 +133,7 @@ cshift1_8_r17 (gfc_array_r17 * const restrict ret,
 	  if (sh < 0)
             sh += len;
 	}
-      src = (const GFC_REAL_17 *) (((char*)sptr) + sh * soffset);
+      src = PTR_ADD_OFFSET (sptr, sh * soffset);
       dest = rptr;
       if (soffset == sizeof (GFC_REAL_17) && roffset == sizeof (GFC_REAL_17))
 	{
diff --git a/libgfortran/generated/cshift1_8_r4.c b/libgfortran/generated/cshift1_8_r4.c
index b62263c7f227..98f2277d5f61 100644
--- a/libgfortran/generated/cshift1_8_r4.c
+++ b/libgfortran/generated/cshift1_8_r4.c
@@ -133,7 +133,7 @@ cshift1_8_r4 (gfc_array_r4 * const restrict ret,
 	  if (sh < 0)
             sh += len;
 	}
-      src = (const GFC_REAL_4 *) (((char*)sptr) + sh * soffset);
+      src = PTR_ADD_OFFSET (sptr, sh * soffset);
       dest = rptr;
       if (soffset == sizeof (GFC_REAL_4) && roffset == sizeof (GFC_REAL_4))
 	{
diff --git a/libgfortran/generated/cshift1_8_r8.c b/libgfortran/generated/cshift1_8_r8.c
index 99d176fc8032..f7b5ecd119ca 100644
--- a/libgfortran/generated/cshift1_8_r8.c
+++ b/libgfortran/generated/cshift1_8_r8.c
@@ -133,7 +133,7 @@ cshift1_8_r8 (gfc_array_r8 * const restrict ret,
 	  if (sh < 0)
             sh += len;
 	}
-      src = (const GFC_REAL_8 *) (((char*)sptr) + sh * soffset);
+      src = PTR_ADD_OFFSET (sptr, sh * soffset);
       dest = rptr;
       if (soffset == sizeof (GFC_REAL_8) && roffset == sizeof (GFC_REAL_8))
 	{
diff --git a/libgfortran/generated/findloc1_c10.c b/libgfortran/generated/findloc1_c10.c
index 90bc1c5e86ec..cc099b689bd7 100644
--- a/libgfortran/generated/findloc1_c10.c
+++ b/libgfortran/generated/findloc1_c10.c
@@ -139,7 +139,7 @@ findloc1_c10 (gfc_array_index_type * const restrict retarray,
       result = 0;
       if (back)
 	{
-	  src = (const GFC_COMPLEX_10 * restrict) (((char*) base) + (len - 1) * delta);
+	  src = PTR_ADD_OFFSET (base, (len - 1) * delta);
 	  for (n = len; n > 0; n--)
 	    {
 	      if (*src == value)
@@ -325,7 +325,7 @@ mfindloc1_c10 (gfc_array_index_type * const restrict retarray,
       result = 0;
       if (back)
 	{
-	  src = (const GFC_COMPLEX_10 * restrict) (((char*)base) + (len - 1) * delta);
+	  src = PTR_ADD_OFFSET (base, (len - 1) * delta);
 	  msrc = mbase + (len - 1) * mdelta; 
 	  for (n = len; n > 0; n--)
 	    {
diff --git a/libgfortran/generated/findloc1_c16.c b/libgfortran/generated/findloc1_c16.c
index 3823bbb7c025..83cee88cb95d 100644
--- a/libgfortran/generated/findloc1_c16.c
+++ b/libgfortran/generated/findloc1_c16.c
@@ -139,7 +139,7 @@ findloc1_c16 (gfc_array_index_type * const restrict retarray,
       result = 0;
       if (back)
 	{
-	  src = (const GFC_COMPLEX_16 * restrict) (((char*) base) + (len - 1) * delta);
+	  src = PTR_ADD_OFFSET (base, (len - 1) * delta);
 	  for (n = len; n > 0; n--)
 	    {
 	      if (*src == value)
@@ -325,7 +325,7 @@ mfindloc1_c16 (gfc_array_index_type * const restrict retarray,
       result = 0;
       if (back)
 	{
-	  src = (const GFC_COMPLEX_16 * restrict) (((char*)base) + (len - 1) * delta);
+	  src = PTR_ADD_OFFSET (base, (len - 1) * delta);
 	  msrc = mbase + (len - 1) * mdelta; 
 	  for (n = len; n > 0; n--)
 	    {
diff --git a/libgfortran/generated/findloc1_c17.c b/libgfortran/generated/findloc1_c17.c
index 6039412b1d1f..c6392edcce34 100644
--- a/libgfortran/generated/findloc1_c17.c
+++ b/libgfortran/generated/findloc1_c17.c
@@ -139,7 +139,7 @@ findloc1_c17 (gfc_array_index_type * const restrict retarray,
       result = 0;
       if (back)
 	{
-	  src = (const GFC_COMPLEX_17 * restrict) (((char*) base) + (len - 1) * delta);
+	  src = PTR_ADD_OFFSET (base, (len - 1) * delta);
 	  for (n = len; n > 0; n--)
 	    {
 	      if (*src == value)
@@ -325,7 +325,7 @@ mfindloc1_c17 (gfc_array_index_type * const restrict retarray,
       result = 0;
       if (back)
 	{
-	  src = (const GFC_COMPLEX_17 * restrict) (((char*)base) + (len - 1) * delta);
+	  src = PTR_ADD_OFFSET (base, (len - 1) * delta);
 	  msrc = mbase + (len - 1) * mdelta; 
 	  for (n = len; n > 0; n--)
 	    {
diff --git a/libgfortran/generated/findloc1_c4.c b/libgfortran/generated/findloc1_c4.c
index 8907721eb429..be8551fc29aa 100644
--- a/libgfortran/generated/findloc1_c4.c
+++ b/libgfortran/generated/findloc1_c4.c
@@ -139,7 +139,7 @@ findloc1_c4 (gfc_array_index_type * const restrict retarray,
       result = 0;
       if (back)
 	{
-	  src = (const GFC_COMPLEX_4 * restrict) (((char*) base) + (len - 1) * delta);
+	  src = PTR_ADD_OFFSET (base, (len - 1) * delta);
 	  for (n = len; n > 0; n--)
 	    {
 	      if (*src == value)
@@ -325,7 +325,7 @@ mfindloc1_c4 (gfc_array_index_type * const restrict retarray,
       result = 0;
       if (back)
 	{
-	  src = (const GFC_COMPLEX_4 * restrict) (((char*)base) + (len - 1) * delta);
+	  src = PTR_ADD_OFFSET (base, (len - 1) * delta);
 	  msrc = mbase + (len - 1) * mdelta; 
 	  for (n = len; n > 0; n--)
 	    {
diff --git a/libgfortran/generated/findloc1_c8.c b/libgfortran/generated/findloc1_c8.c
index 8d0e2ac568e5..1bbef53695fa 100644
--- a/libgfortran/generated/findloc1_c8.c
+++ b/libgfortran/generated/findloc1_c8.c
@@ -139,7 +139,7 @@ findloc1_c8 (gfc_array_index_type * const restrict retarray,
       result = 0;
       if (back)
 	{
-	  src = (const GFC_COMPLEX_8 * restrict) (((char*) base) + (len - 1) * delta);
+	  src = PTR_ADD_OFFSET (base, (len - 1) * delta);
 	  for (n = len; n > 0; n--)
 	    {
 	      if (*src == value)
@@ -325,7 +325,7 @@ mfindloc1_c8 (gfc_array_index_type * const restrict retarray,
       result = 0;
       if (back)
 	{
-	  src = (const GFC_COMPLEX_8 * restrict) (((char*)base) + (len - 1) * delta);
+	  src = PTR_ADD_OFFSET (base, (len - 1) * delta);
 	  msrc = mbase + (len - 1) * mdelta; 
 	  for (n = len; n > 0; n--)
 	    {
diff --git a/libgfortran/generated/findloc1_i1.c b/libgfortran/generated/findloc1_i1.c
index 56de7e205772..7be40974e8a5 100644
--- a/libgfortran/generated/findloc1_i1.c
+++ b/libgfortran/generated/findloc1_i1.c
@@ -139,7 +139,7 @@ findloc1_i1 (gfc_array_index_type * const restrict retarray,
       result = 0;
       if (back)
 	{
-	  src = (const GFC_INTEGER_1 * restrict) (((char*) base) + (len - 1) * delta);
+	  src = PTR_ADD_OFFSET (base, (len - 1) * delta);
 	  for (n = len; n > 0; n--)
 	    {
 	      if (*src == value)
@@ -325,7 +325,7 @@ mfindloc1_i1 (gfc_array_index_type * const restrict retarray,
       result = 0;
       if (back)
 	{
-	  src = (const GFC_INTEGER_1 * restrict) (((char*)base) + (len - 1) * delta);
+	  src = PTR_ADD_OFFSET (base, (len - 1) * delta);
 	  msrc = mbase + (len - 1) * mdelta; 
 	  for (n = len; n > 0; n--)
 	    {
diff --git a/libgfortran/generated/findloc1_i16.c b/libgfortran/generated/findloc1_i16.c
index 5917ebfc7910..909a618201fa 100644
--- a/libgfortran/generated/findloc1_i16.c
+++ b/libgfortran/generated/findloc1_i16.c
@@ -139,7 +139,7 @@ findloc1_i16 (gfc_array_index_type * const restrict retarray,
       result = 0;
       if (back)
 	{
-	  src = (const GFC_INTEGER_16 * restrict) (((char*) base) + (len - 1) * delta);
+	  src = PTR_ADD_OFFSET (base, (len - 1) * delta);
 	  for (n = len; n > 0; n--)
 	    {
 	      if (*src == value)
@@ -325,7 +325,7 @@ mfindloc1_i16 (gfc_array_index_type * const restrict retarray,
       result = 0;
       if (back)
 	{
-	  src = (const GFC_INTEGER_16 * restrict) (((char*)base) + (len - 1) * delta);
+	  src = PTR_ADD_OFFSET (base, (len - 1) * delta);
 	  msrc = mbase + (len - 1) * mdelta; 
 	  for (n = len; n > 0; n--)
 	    {
diff --git a/libgfortran/generated/findloc1_i2.c b/libgfortran/generated/findloc1_i2.c
index bec080adf5a8..05f7604bf5c8 100644
--- a/libgfortran/generated/findloc1_i2.c
+++ b/libgfortran/generated/findloc1_i2.c
@@ -139,7 +139,7 @@ findloc1_i2 (gfc_array_index_type * const restrict retarray,
       result = 0;
       if (back)
 	{
-	  src = (const GFC_INTEGER_2 * restrict) (((char*) base) + (len - 1) * delta);
+	  src = PTR_ADD_OFFSET (base, (len - 1) * delta);
 	  for (n = len; n > 0; n--)
 	    {
 	      if (*src == value)
@@ -325,7 +325,7 @@ mfindloc1_i2 (gfc_array_index_type * const restrict retarray,
       result = 0;
       if (back)
 	{
-	  src = (const GFC_INTEGER_2 * restrict) (((char*)base) + (len - 1) * delta);
+	  src = PTR_ADD_OFFSET (base, (len - 1) * delta);
 	  msrc = mbase + (len - 1) * mdelta; 
 	  for (n = len; n > 0; n--)
 	    {
diff --git a/libgfortran/generated/findloc1_i4.c b/libgfortran/generated/findloc1_i4.c
index c82c2c86b5b2..07954ffc581d 100644
--- a/libgfortran/generated/findloc1_i4.c
+++ b/libgfortran/generated/findloc1_i4.c
@@ -139,7 +139,7 @@ findloc1_i4 (gfc_array_index_type * const restrict retarray,
       result = 0;
       if (back)
 	{
-	  src = (const GFC_INTEGER_4 * restrict) (((char*) base) + (len - 1) * delta);
+	  src = PTR_ADD_OFFSET (base, (len - 1) * delta);
 	  for (n = len; n > 0; n--)
 	    {
 	      if (*src == value)
@@ -325,7 +325,7 @@ mfindloc1_i4 (gfc_array_index_type * const restrict retarray,
       result = 0;
       if (back)
 	{
-	  src = (const GFC_INTEGER_4 * restrict) (((char*)base) + (len - 1) * delta);
+	  src = PTR_ADD_OFFSET (base, (len - 1) * delta);
 	  msrc = mbase + (len - 1) * mdelta; 
 	  for (n = len; n > 0; n--)
 	    {
diff --git a/libgfortran/generated/findloc1_i8.c b/libgfortran/generated/findloc1_i8.c
index 3c69005935d0..ed3f62b99f75 100644
--- a/libgfortran/generated/findloc1_i8.c
+++ b/libgfortran/generated/findloc1_i8.c
@@ -139,7 +139,7 @@ findloc1_i8 (gfc_array_index_type * const restrict retarray,
       result = 0;
       if (back)
 	{
-	  src = (const GFC_INTEGER_8 * restrict) (((char*) base) + (len - 1) * delta);
+	  src = PTR_ADD_OFFSET (base, (len - 1) * delta);
 	  for (n = len; n > 0; n--)
 	    {
 	      if (*src == value)
@@ -325,7 +325,7 @@ mfindloc1_i8 (gfc_array_index_type * const restrict retarray,
       result = 0;
       if (back)
 	{
-	  src = (const GFC_INTEGER_8 * restrict) (((char*)base) + (len - 1) * delta);
+	  src = PTR_ADD_OFFSET (base, (len - 1) * delta);
 	  msrc = mbase + (len - 1) * mdelta; 
 	  for (n = len; n > 0; n--)
 	    {
diff --git a/libgfortran/generated/findloc1_r10.c b/libgfortran/generated/findloc1_r10.c
index a3db95012cb0..738268678301 100644
--- a/libgfortran/generated/findloc1_r10.c
+++ b/libgfortran/generated/findloc1_r10.c
@@ -139,7 +139,7 @@ findloc1_r10 (gfc_array_index_type * const restrict retarray,
       result = 0;
       if (back)
 	{
-	  src = (const GFC_REAL_10 * restrict) (((char*) base) + (len - 1) * delta);
+	  src = PTR_ADD_OFFSET (base, (len - 1) * delta);
 	  for (n = len; n > 0; n--)
 	    {
 	      if (*src == value)
@@ -325,7 +325,7 @@ mfindloc1_r10 (gfc_array_index_type * const restrict retarray,
       result = 0;
       if (back)
 	{
-	  src = (const GFC_REAL_10 * restrict) (((char*)base) + (len - 1) * delta);
+	  src = PTR_ADD_OFFSET (base, (len - 1) * delta);
 	  msrc = mbase + (len - 1) * mdelta; 
 	  for (n = len; n > 0; n--)
 	    {
diff --git a/libgfortran/generated/findloc1_r16.c b/libgfortran/generated/findloc1_r16.c
index 0c29d3a9582c..7f9fa5ecfc3f 100644
--- a/libgfortran/generated/findloc1_r16.c
+++ b/libgfortran/generated/findloc1_r16.c
@@ -139,7 +139,7 @@ findloc1_r16 (gfc_array_index_type * const restrict retarray,
       result = 0;
       if (back)
 	{
-	  src = (const GFC_REAL_16 * restrict) (((char*) base) + (len - 1) * delta);
+	  src = PTR_ADD_OFFSET (base, (len - 1) * delta);
 	  for (n = len; n > 0; n--)
 	    {
 	      if (*src == value)
@@ -325,7 +325,7 @@ mfindloc1_r16 (gfc_array_index_type * const restrict retarray,
       result = 0;
       if (back)
 	{
-	  src = (const GFC_REAL_16 * restrict) (((char*)base) + (len - 1) * delta);
+	  src = PTR_ADD_OFFSET (base, (len - 1) * delta);
 	  msrc = mbase + (len - 1) * mdelta; 
 	  for (n = len; n > 0; n--)
 	    {
diff --git a/libgfortran/generated/findloc1_r17.c b/libgfortran/generated/findloc1_r17.c
index 2a5711a0fbbd..95a79ac93aff 100644
--- a/libgfortran/generated/findloc1_r17.c
+++ b/libgfortran/generated/findloc1_r17.c
@@ -139,7 +139,7 @@ findloc1_r17 (gfc_array_index_type * const restrict retarray,
       result = 0;
       if (back)
 	{
-	  src = (const GFC_REAL_17 * restrict) (((char*) base) + (len - 1) * delta);
+	  src = PTR_ADD_OFFSET (base, (len - 1) * delta);
 	  for (n = len; n > 0; n--)
 	    {
 	      if (*src == value)
@@ -325,7 +325,7 @@ mfindloc1_r17 (gfc_array_index_type * const restrict retarray,
       result = 0;
       if (back)
 	{
-	  src = (const GFC_REAL_17 * restrict) (((char*)base) + (len - 1) * delta);
+	  src = PTR_ADD_OFFSET (base, (len - 1) * delta);
 	  msrc = mbase + (len - 1) * mdelta; 
 	  for (n = len; n > 0; n--)
 	    {
diff --git a/libgfortran/generated/findloc1_r4.c b/libgfortran/generated/findloc1_r4.c
index 0bb9504951fc..f9d3f59341c9 100644
--- a/libgfortran/generated/findloc1_r4.c
+++ b/libgfortran/generated/findloc1_r4.c
@@ -139,7 +139,7 @@ findloc1_r4 (gfc_array_index_type * const restrict retarray,
       result = 0;
       if (back)
 	{
-	  src = (const GFC_REAL_4 * restrict) (((char*) base) + (len - 1) * delta);
+	  src = PTR_ADD_OFFSET (base, (len - 1) * delta);
 	  for (n = len; n > 0; n--)
 	    {
 	      if (*src == value)
@@ -325,7 +325,7 @@ mfindloc1_r4 (gfc_array_index_type * const restrict retarray,
       result = 0;
       if (back)
 	{
-	  src = (const GFC_REAL_4 * restrict) (((char*)base) + (len - 1) * delta);
+	  src = PTR_ADD_OFFSET (base, (len - 1) * delta);
 	  msrc = mbase + (len - 1) * mdelta; 
 	  for (n = len; n > 0; n--)
 	    {
diff --git a/libgfortran/generated/findloc1_r8.c b/libgfortran/generated/findloc1_r8.c
index 3a24334f66b8..83ad7544d5f0 100644
--- a/libgfortran/generated/findloc1_r8.c
+++ b/libgfortran/generated/findloc1_r8.c
@@ -139,7 +139,7 @@ findloc1_r8 (gfc_array_index_type * const restrict retarray,
       result = 0;
       if (back)
 	{
-	  src = (const GFC_REAL_8 * restrict) (((char*) base) + (len - 1) * delta);
+	  src = PTR_ADD_OFFSET (base, (len - 1) * delta);
 	  for (n = len; n > 0; n--)
 	    {
 	      if (*src == value)
@@ -325,7 +325,7 @@ mfindloc1_r8 (gfc_array_index_type * const restrict retarray,
       result = 0;
       if (back)
 	{
-	  src = (const GFC_REAL_8 * restrict) (((char*)base) + (len - 1) * delta);
+	  src = PTR_ADD_OFFSET (base, (len - 1) * delta);
 	  msrc = mbase + (len - 1) * mdelta; 
 	  for (n = len; n > 0; n--)
 	    {
diff --git a/libgfortran/generated/findloc1_s1.c b/libgfortran/generated/findloc1_s1.c
index f6979b9c73dd..a243e4606ac6 100644
--- a/libgfortran/generated/findloc1_s1.c
+++ b/libgfortran/generated/findloc1_s1.c
@@ -141,7 +141,7 @@ findloc1_s1 (gfc_array_index_type * const restrict retarray,
       result = 0;
       if (back)
 	{
-	  src = (const GFC_UINTEGER_1 * restrict) (((char*) base) + (len - 1) * delta);
+	  src = PTR_ADD_OFFSET (base, (len - 1) * delta);
 	  for (n = len; n > 0; n--)
 	    {
 	      if (compare_string (len_array, (char *) src, len_value, (char *) value) == 0)
@@ -327,7 +327,7 @@ mfindloc1_s1 (gfc_array_index_type * const restrict retarray,
       result = 0;
       if (back)
 	{
-	  src = (const GFC_UINTEGER_1 * restrict) (((char*)base) + (len - 1) * delta);
+	  src = PTR_ADD_OFFSET (base, (len - 1) * delta);
 	  msrc = mbase + (len - 1) * mdelta; 
 	  for (n = len; n > 0; n--)
 	    {
diff --git a/libgfortran/generated/findloc1_s4.c b/libgfortran/generated/findloc1_s4.c
index 652aa79abbfd..4214658bd007 100644
--- a/libgfortran/generated/findloc1_s4.c
+++ b/libgfortran/generated/findloc1_s4.c
@@ -141,7 +141,7 @@ findloc1_s4 (gfc_array_index_type * const restrict retarray,
       result = 0;
       if (back)
 	{
-	  src = (const GFC_UINTEGER_4 * restrict) (((char*) base) + (len - 1) * delta);
+	  src = PTR_ADD_OFFSET (base, (len - 1) * delta);
 	  for (n = len; n > 0; n--)
 	    {
 	      if (compare_string_char4 (len_array, src, len_value, value) == 0)
@@ -327,7 +327,7 @@ mfindloc1_s4 (gfc_array_index_type * const restrict retarray,
       result = 0;
       if (back)
 	{
-	  src = (const GFC_UINTEGER_4 * restrict) (((char*)base) + (len - 1) * delta);
+	  src = PTR_ADD_OFFSET (base, (len - 1) * delta);
 	  msrc = mbase + (len - 1) * mdelta; 
 	  for (n = len; n > 0; n--)
 	    {
diff --git a/libgfortran/generated/matmul_c10.c b/libgfortran/generated/matmul_c10.c
index 376401c5ab3f..f5c298aa0c4f 100644
--- a/libgfortran/generated/matmul_c10.c
+++ b/libgfortran/generated/matmul_c10.c
@@ -94,7 +94,8 @@ matmul_c10_avx (gfc_array_c10 * const restrict retarray,
 
   index_type rxstride, rystride, axstride, aystride, bxstride, bystride;
   index_type x, y, n, count, xcount, ycount;
-  index_type aystride_bytes, bystride_bytes, rystride_bytes;
+  index_type axstride_bytes, aystride_bytes, bxstride_bytes, bystride_bytes,
+	     rxstride_bytes, rystride_bytes;
 
   assert (GFC_DESCRIPTOR_RANK (a) == 2
           || GFC_DESCRIPTOR_RANK (b) == 2);
@@ -183,12 +184,13 @@ matmul_c10_avx (gfc_array_c10 * const restrict retarray,
 	 either as a row or a column matrix. We want both cases to
 	 work. */
       rxstride = rystride = GFC_DESCRIPTOR_STRIDE(retarray,0);
-      rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
+      rxstride_bytes = rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
     }
   else
     {
       rxstride = GFC_DESCRIPTOR_STRIDE(retarray,0);
       rystride = GFC_DESCRIPTOR_STRIDE(retarray,1);
+      rxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
       rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,1);
     }
 
@@ -197,6 +199,7 @@ matmul_c10_avx (gfc_array_c10 * const restrict retarray,
       /* Treat it as a a row matrix A[1,count]. */
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = 1;
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = sizeof (GFC_COMPLEX_10);
 
       xcount = 1;
@@ -206,6 +209,7 @@ matmul_c10_avx (gfc_array_c10 * const restrict retarray,
     {
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = GFC_DESCRIPTOR_STRIDE(a,1);
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,1);
 
       count = GFC_DESCRIPTOR_EXTENT(a,1);
@@ -224,17 +228,20 @@ matmul_c10_avx (gfc_array_c10 * const restrict retarray,
     {
       /* Treat it as a column matrix B[count,1] */
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
 
       /* bystride should never be used for 1-dimensional b.
          The value is only used for calculation of the
          memory by the buffer.  */
       bystride = 256;
+      bystride_bytes = 99999999;
       ycount = 1;
     }
   else
     {
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
       bystride = GFC_DESCRIPTOR_STRIDE(b,1);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
       bystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,1);
       ycount = GFC_DESCRIPTOR_EXTENT(b,1);
     }
@@ -294,12 +301,11 @@ matmul_c10_avx (gfc_array_c10 * const restrict retarray,
 
 	 from netlib.org, translated to C, and modified for matmul.m4.  */
 
-      const GFC_COMPLEX_10 *a, *b;
       GFC_COMPLEX_10 *c;
       const index_type m = xcount, n = ycount, k = count;
 
       /* System generated locals */
-      index_type a_dim1, b_dim1, c_dim1,
+      index_type a_dim1, b_dim1,
 		 i1, i2, i3, i4, i5, i6;
 
       /* Local variables */
@@ -309,25 +315,22 @@ matmul_c10_avx (gfc_array_c10 * const restrict retarray,
       index_type isec, jsec, lsec, uisec, ujsec, ulsec;
       GFC_COMPLEX_10 *t1;
 
-      a = abase;
-      b = bbase;
       c = retarray->base_addr;
 
       /* Parameter adjustments */
-      c_dim1 = rystride;
       a_dim1 = aystride;
       b_dim1 = bystride;
 
 #define A_ARRAY_ELEM(i,j) \
-    a[(i) + (j) * a_dim1]
+    (ARRAY_ELEM_AT_OFFSET (abase, (i) * sizeof (GFC_COMPLEX_10) + (j) * aystride_bytes))
 
 #define B_ARRAY_ELEM(i,j) \
-    b[(i) + (j) * b_dim1]
+    (ARRAY_ELEM_AT_OFFSET (bbase, (i) * sizeof (GFC_COMPLEX_10) + (j) * bystride_bytes))
 
 #define C_ARRAY_ELEM(i,j) \
-    c[(i) + (j) * c_dim1]
+    (ARRAY_ELEM_AT_OFFSET (c, (i) * sizeof (GFC_COMPLEX_10) + (j) * rystride_bytes))
 
-      /* Empty c first.  */
+      /* Empty result first.  */
       for (j=0; j<n; j++)
 	for (i=0; i<m; i++)
 	  C_ARRAY_ELEM (i, j) = (GFC_COMPLEX_10)0;
@@ -575,11 +578,11 @@ matmul_c10_avx (gfc_array_c10 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
-	      dest_y = &dest[y*rystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	      dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	      for (x = 0; x < xcount; x++)
 		{
-		  abase_x = &abase[x*axstride];
+		  abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 		  s = (GFC_COMPLEX_10) 0;
 		  for (n = 0; n < count; n++)
 		    s += abase_x[n] * bbase_y[n];
@@ -594,11 +597,11 @@ matmul_c10_avx (gfc_array_c10 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	      s = (GFC_COMPLEX_10) 0;
 	      for (n = 0; n < count; n++)
 		s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n];
-	      dest[y*rystride] = s;
+	      ARRAY_ELEM_AT_OFFSET (dest, y * rystride_bytes) = s;
 	    }
 	}
     }
@@ -609,10 +612,11 @@ matmul_c10_avx (gfc_array_c10 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	  s = (GFC_COMPLEX_10) 0;
 	  for (n = 0; n < count; n++)
-	    s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n*bxstride];
+	    s += GFC_DESCRIPTOR1_ELEM (a, n)
+	         * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
 	  GFC_DESCRIPTOR1_ELEM (retarray, y) = s;
 	}
     }
@@ -639,15 +643,16 @@ matmul_c10_avx (gfc_array_c10 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
-	  dest_y = &dest[y*rystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	  dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	  for (x = 0; x < xcount; x++)
 	    {
-	      abase_x = &abase[x*axstride];
+	      abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 	      s = (GFC_COMPLEX_10) 0;
 	      for (n = 0; n < count; n++)
-		s += abase_x[n*aystride] * bbase_y[n*bxstride];
-	      dest_y[x*rxstride] = s;
+		s += ARRAY_ELEM_AT_OFFSET (abase_x, n * aystride_bytes)
+		     * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
+	      ARRAY_ELEM_AT_OFFSET (dest_y, x * rxstride_bytes) = s;
 	    }
 	}
     }
@@ -674,7 +679,8 @@ matmul_c10_avx2 (gfc_array_c10 * const restrict retarray,
 
   index_type rxstride, rystride, axstride, aystride, bxstride, bystride;
   index_type x, y, n, count, xcount, ycount;
-  index_type aystride_bytes, bystride_bytes, rystride_bytes;
+  index_type axstride_bytes, aystride_bytes, bxstride_bytes, bystride_bytes,
+	     rxstride_bytes, rystride_bytes;
 
   assert (GFC_DESCRIPTOR_RANK (a) == 2
           || GFC_DESCRIPTOR_RANK (b) == 2);
@@ -763,12 +769,13 @@ matmul_c10_avx2 (gfc_array_c10 * const restrict retarray,
 	 either as a row or a column matrix. We want both cases to
 	 work. */
       rxstride = rystride = GFC_DESCRIPTOR_STRIDE(retarray,0);
-      rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
+      rxstride_bytes = rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
     }
   else
     {
       rxstride = GFC_DESCRIPTOR_STRIDE(retarray,0);
       rystride = GFC_DESCRIPTOR_STRIDE(retarray,1);
+      rxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
       rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,1);
     }
 
@@ -777,6 +784,7 @@ matmul_c10_avx2 (gfc_array_c10 * const restrict retarray,
       /* Treat it as a a row matrix A[1,count]. */
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = 1;
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = sizeof (GFC_COMPLEX_10);
 
       xcount = 1;
@@ -786,6 +794,7 @@ matmul_c10_avx2 (gfc_array_c10 * const restrict retarray,
     {
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = GFC_DESCRIPTOR_STRIDE(a,1);
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,1);
 
       count = GFC_DESCRIPTOR_EXTENT(a,1);
@@ -804,17 +813,20 @@ matmul_c10_avx2 (gfc_array_c10 * const restrict retarray,
     {
       /* Treat it as a column matrix B[count,1] */
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
 
       /* bystride should never be used for 1-dimensional b.
          The value is only used for calculation of the
          memory by the buffer.  */
       bystride = 256;
+      bystride_bytes = 99999999;
       ycount = 1;
     }
   else
     {
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
       bystride = GFC_DESCRIPTOR_STRIDE(b,1);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
       bystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,1);
       ycount = GFC_DESCRIPTOR_EXTENT(b,1);
     }
@@ -874,12 +886,11 @@ matmul_c10_avx2 (gfc_array_c10 * const restrict retarray,
 
 	 from netlib.org, translated to C, and modified for matmul.m4.  */
 
-      const GFC_COMPLEX_10 *a, *b;
       GFC_COMPLEX_10 *c;
       const index_type m = xcount, n = ycount, k = count;
 
       /* System generated locals */
-      index_type a_dim1, b_dim1, c_dim1,
+      index_type a_dim1, b_dim1,
 		 i1, i2, i3, i4, i5, i6;
 
       /* Local variables */
@@ -889,25 +900,22 @@ matmul_c10_avx2 (gfc_array_c10 * const restrict retarray,
       index_type isec, jsec, lsec, uisec, ujsec, ulsec;
       GFC_COMPLEX_10 *t1;
 
-      a = abase;
-      b = bbase;
       c = retarray->base_addr;
 
       /* Parameter adjustments */
-      c_dim1 = rystride;
       a_dim1 = aystride;
       b_dim1 = bystride;
 
 #define A_ARRAY_ELEM(i,j) \
-    a[(i) + (j) * a_dim1]
+    (ARRAY_ELEM_AT_OFFSET (abase, (i) * sizeof (GFC_COMPLEX_10) + (j) * aystride_bytes))
 
 #define B_ARRAY_ELEM(i,j) \
-    b[(i) + (j) * b_dim1]
+    (ARRAY_ELEM_AT_OFFSET (bbase, (i) * sizeof (GFC_COMPLEX_10) + (j) * bystride_bytes))
 
 #define C_ARRAY_ELEM(i,j) \
-    c[(i) + (j) * c_dim1]
+    (ARRAY_ELEM_AT_OFFSET (c, (i) * sizeof (GFC_COMPLEX_10) + (j) * rystride_bytes))
 
-      /* Empty c first.  */
+      /* Empty result first.  */
       for (j=0; j<n; j++)
 	for (i=0; i<m; i++)
 	  C_ARRAY_ELEM (i, j) = (GFC_COMPLEX_10)0;
@@ -1155,11 +1163,11 @@ matmul_c10_avx2 (gfc_array_c10 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
-	      dest_y = &dest[y*rystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	      dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	      for (x = 0; x < xcount; x++)
 		{
-		  abase_x = &abase[x*axstride];
+		  abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 		  s = (GFC_COMPLEX_10) 0;
 		  for (n = 0; n < count; n++)
 		    s += abase_x[n] * bbase_y[n];
@@ -1174,11 +1182,11 @@ matmul_c10_avx2 (gfc_array_c10 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	      s = (GFC_COMPLEX_10) 0;
 	      for (n = 0; n < count; n++)
 		s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n];
-	      dest[y*rystride] = s;
+	      ARRAY_ELEM_AT_OFFSET (dest, y * rystride_bytes) = s;
 	    }
 	}
     }
@@ -1189,10 +1197,11 @@ matmul_c10_avx2 (gfc_array_c10 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	  s = (GFC_COMPLEX_10) 0;
 	  for (n = 0; n < count; n++)
-	    s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n*bxstride];
+	    s += GFC_DESCRIPTOR1_ELEM (a, n)
+	         * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
 	  GFC_DESCRIPTOR1_ELEM (retarray, y) = s;
 	}
     }
@@ -1219,15 +1228,16 @@ matmul_c10_avx2 (gfc_array_c10 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
-	  dest_y = &dest[y*rystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	  dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	  for (x = 0; x < xcount; x++)
 	    {
-	      abase_x = &abase[x*axstride];
+	      abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 	      s = (GFC_COMPLEX_10) 0;
 	      for (n = 0; n < count; n++)
-		s += abase_x[n*aystride] * bbase_y[n*bxstride];
-	      dest_y[x*rxstride] = s;
+		s += ARRAY_ELEM_AT_OFFSET (abase_x, n * aystride_bytes)
+		     * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
+	      ARRAY_ELEM_AT_OFFSET (dest_y, x * rxstride_bytes) = s;
 	    }
 	}
     }
@@ -1254,7 +1264,8 @@ matmul_c10_avx512f (gfc_array_c10 * const restrict retarray,
 
   index_type rxstride, rystride, axstride, aystride, bxstride, bystride;
   index_type x, y, n, count, xcount, ycount;
-  index_type aystride_bytes, bystride_bytes, rystride_bytes;
+  index_type axstride_bytes, aystride_bytes, bxstride_bytes, bystride_bytes,
+	     rxstride_bytes, rystride_bytes;
 
   assert (GFC_DESCRIPTOR_RANK (a) == 2
           || GFC_DESCRIPTOR_RANK (b) == 2);
@@ -1343,12 +1354,13 @@ matmul_c10_avx512f (gfc_array_c10 * const restrict retarray,
 	 either as a row or a column matrix. We want both cases to
 	 work. */
       rxstride = rystride = GFC_DESCRIPTOR_STRIDE(retarray,0);
-      rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
+      rxstride_bytes = rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
     }
   else
     {
       rxstride = GFC_DESCRIPTOR_STRIDE(retarray,0);
       rystride = GFC_DESCRIPTOR_STRIDE(retarray,1);
+      rxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
       rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,1);
     }
 
@@ -1357,6 +1369,7 @@ matmul_c10_avx512f (gfc_array_c10 * const restrict retarray,
       /* Treat it as a a row matrix A[1,count]. */
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = 1;
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = sizeof (GFC_COMPLEX_10);
 
       xcount = 1;
@@ -1366,6 +1379,7 @@ matmul_c10_avx512f (gfc_array_c10 * const restrict retarray,
     {
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = GFC_DESCRIPTOR_STRIDE(a,1);
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,1);
 
       count = GFC_DESCRIPTOR_EXTENT(a,1);
@@ -1384,17 +1398,20 @@ matmul_c10_avx512f (gfc_array_c10 * const restrict retarray,
     {
       /* Treat it as a column matrix B[count,1] */
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
 
       /* bystride should never be used for 1-dimensional b.
          The value is only used for calculation of the
          memory by the buffer.  */
       bystride = 256;
+      bystride_bytes = 99999999;
       ycount = 1;
     }
   else
     {
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
       bystride = GFC_DESCRIPTOR_STRIDE(b,1);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
       bystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,1);
       ycount = GFC_DESCRIPTOR_EXTENT(b,1);
     }
@@ -1454,12 +1471,11 @@ matmul_c10_avx512f (gfc_array_c10 * const restrict retarray,
 
 	 from netlib.org, translated to C, and modified for matmul.m4.  */
 
-      const GFC_COMPLEX_10 *a, *b;
       GFC_COMPLEX_10 *c;
       const index_type m = xcount, n = ycount, k = count;
 
       /* System generated locals */
-      index_type a_dim1, b_dim1, c_dim1,
+      index_type a_dim1, b_dim1,
 		 i1, i2, i3, i4, i5, i6;
 
       /* Local variables */
@@ -1469,25 +1485,22 @@ matmul_c10_avx512f (gfc_array_c10 * const restrict retarray,
       index_type isec, jsec, lsec, uisec, ujsec, ulsec;
       GFC_COMPLEX_10 *t1;
 
-      a = abase;
-      b = bbase;
       c = retarray->base_addr;
 
       /* Parameter adjustments */
-      c_dim1 = rystride;
       a_dim1 = aystride;
       b_dim1 = bystride;
 
 #define A_ARRAY_ELEM(i,j) \
-    a[(i) + (j) * a_dim1]
+    (ARRAY_ELEM_AT_OFFSET (abase, (i) * sizeof (GFC_COMPLEX_10) + (j) * aystride_bytes))
 
 #define B_ARRAY_ELEM(i,j) \
-    b[(i) + (j) * b_dim1]
+    (ARRAY_ELEM_AT_OFFSET (bbase, (i) * sizeof (GFC_COMPLEX_10) + (j) * bystride_bytes))
 
 #define C_ARRAY_ELEM(i,j) \
-    c[(i) + (j) * c_dim1]
+    (ARRAY_ELEM_AT_OFFSET (c, (i) * sizeof (GFC_COMPLEX_10) + (j) * rystride_bytes))
 
-      /* Empty c first.  */
+      /* Empty result first.  */
       for (j=0; j<n; j++)
 	for (i=0; i<m; i++)
 	  C_ARRAY_ELEM (i, j) = (GFC_COMPLEX_10)0;
@@ -1735,11 +1748,11 @@ matmul_c10_avx512f (gfc_array_c10 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
-	      dest_y = &dest[y*rystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	      dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	      for (x = 0; x < xcount; x++)
 		{
-		  abase_x = &abase[x*axstride];
+		  abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 		  s = (GFC_COMPLEX_10) 0;
 		  for (n = 0; n < count; n++)
 		    s += abase_x[n] * bbase_y[n];
@@ -1754,11 +1767,11 @@ matmul_c10_avx512f (gfc_array_c10 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	      s = (GFC_COMPLEX_10) 0;
 	      for (n = 0; n < count; n++)
 		s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n];
-	      dest[y*rystride] = s;
+	      ARRAY_ELEM_AT_OFFSET (dest, y * rystride_bytes) = s;
 	    }
 	}
     }
@@ -1769,10 +1782,11 @@ matmul_c10_avx512f (gfc_array_c10 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	  s = (GFC_COMPLEX_10) 0;
 	  for (n = 0; n < count; n++)
-	    s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n*bxstride];
+	    s += GFC_DESCRIPTOR1_ELEM (a, n)
+	         * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
 	  GFC_DESCRIPTOR1_ELEM (retarray, y) = s;
 	}
     }
@@ -1799,15 +1813,16 @@ matmul_c10_avx512f (gfc_array_c10 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
-	  dest_y = &dest[y*rystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	  dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	  for (x = 0; x < xcount; x++)
 	    {
-	      abase_x = &abase[x*axstride];
+	      abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 	      s = (GFC_COMPLEX_10) 0;
 	      for (n = 0; n < count; n++)
-		s += abase_x[n*aystride] * bbase_y[n*bxstride];
-	      dest_y[x*rxstride] = s;
+		s += ARRAY_ELEM_AT_OFFSET (abase_x, n * aystride_bytes)
+		     * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
+	      ARRAY_ELEM_AT_OFFSET (dest_y, x * rxstride_bytes) = s;
 	    }
 	}
     }
@@ -1848,7 +1863,8 @@ matmul_c10_vanilla (gfc_array_c10 * const restrict retarray,
 
   index_type rxstride, rystride, axstride, aystride, bxstride, bystride;
   index_type x, y, n, count, xcount, ycount;
-  index_type aystride_bytes, bystride_bytes, rystride_bytes;
+  index_type axstride_bytes, aystride_bytes, bxstride_bytes, bystride_bytes,
+	     rxstride_bytes, rystride_bytes;
 
   assert (GFC_DESCRIPTOR_RANK (a) == 2
           || GFC_DESCRIPTOR_RANK (b) == 2);
@@ -1937,12 +1953,13 @@ matmul_c10_vanilla (gfc_array_c10 * const restrict retarray,
 	 either as a row or a column matrix. We want both cases to
 	 work. */
       rxstride = rystride = GFC_DESCRIPTOR_STRIDE(retarray,0);
-      rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
+      rxstride_bytes = rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
     }
   else
     {
       rxstride = GFC_DESCRIPTOR_STRIDE(retarray,0);
       rystride = GFC_DESCRIPTOR_STRIDE(retarray,1);
+      rxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
       rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,1);
     }
 
@@ -1951,6 +1968,7 @@ matmul_c10_vanilla (gfc_array_c10 * const restrict retarray,
       /* Treat it as a a row matrix A[1,count]. */
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = 1;
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = sizeof (GFC_COMPLEX_10);
 
       xcount = 1;
@@ -1960,6 +1978,7 @@ matmul_c10_vanilla (gfc_array_c10 * const restrict retarray,
     {
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = GFC_DESCRIPTOR_STRIDE(a,1);
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,1);
 
       count = GFC_DESCRIPTOR_EXTENT(a,1);
@@ -1978,17 +1997,20 @@ matmul_c10_vanilla (gfc_array_c10 * const restrict retarray,
     {
       /* Treat it as a column matrix B[count,1] */
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
 
       /* bystride should never be used for 1-dimensional b.
          The value is only used for calculation of the
          memory by the buffer.  */
       bystride = 256;
+      bystride_bytes = 99999999;
       ycount = 1;
     }
   else
     {
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
       bystride = GFC_DESCRIPTOR_STRIDE(b,1);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
       bystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,1);
       ycount = GFC_DESCRIPTOR_EXTENT(b,1);
     }
@@ -2048,12 +2070,11 @@ matmul_c10_vanilla (gfc_array_c10 * const restrict retarray,
 
 	 from netlib.org, translated to C, and modified for matmul.m4.  */
 
-      const GFC_COMPLEX_10 *a, *b;
       GFC_COMPLEX_10 *c;
       const index_type m = xcount, n = ycount, k = count;
 
       /* System generated locals */
-      index_type a_dim1, b_dim1, c_dim1,
+      index_type a_dim1, b_dim1,
 		 i1, i2, i3, i4, i5, i6;
 
       /* Local variables */
@@ -2063,25 +2084,22 @@ matmul_c10_vanilla (gfc_array_c10 * const restrict retarray,
       index_type isec, jsec, lsec, uisec, ujsec, ulsec;
       GFC_COMPLEX_10 *t1;
 
-      a = abase;
-      b = bbase;
       c = retarray->base_addr;
 
       /* Parameter adjustments */
-      c_dim1 = rystride;
       a_dim1 = aystride;
       b_dim1 = bystride;
 
 #define A_ARRAY_ELEM(i,j) \
-    a[(i) + (j) * a_dim1]
+    (ARRAY_ELEM_AT_OFFSET (abase, (i) * sizeof (GFC_COMPLEX_10) + (j) * aystride_bytes))
 
 #define B_ARRAY_ELEM(i,j) \
-    b[(i) + (j) * b_dim1]
+    (ARRAY_ELEM_AT_OFFSET (bbase, (i) * sizeof (GFC_COMPLEX_10) + (j) * bystride_bytes))
 
 #define C_ARRAY_ELEM(i,j) \
-    c[(i) + (j) * c_dim1]
+    (ARRAY_ELEM_AT_OFFSET (c, (i) * sizeof (GFC_COMPLEX_10) + (j) * rystride_bytes))
 
-      /* Empty c first.  */
+      /* Empty result first.  */
       for (j=0; j<n; j++)
 	for (i=0; i<m; i++)
 	  C_ARRAY_ELEM (i, j) = (GFC_COMPLEX_10)0;
@@ -2329,11 +2347,11 @@ matmul_c10_vanilla (gfc_array_c10 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
-	      dest_y = &dest[y*rystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	      dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	      for (x = 0; x < xcount; x++)
 		{
-		  abase_x = &abase[x*axstride];
+		  abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 		  s = (GFC_COMPLEX_10) 0;
 		  for (n = 0; n < count; n++)
 		    s += abase_x[n] * bbase_y[n];
@@ -2348,11 +2366,11 @@ matmul_c10_vanilla (gfc_array_c10 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	      s = (GFC_COMPLEX_10) 0;
 	      for (n = 0; n < count; n++)
 		s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n];
-	      dest[y*rystride] = s;
+	      ARRAY_ELEM_AT_OFFSET (dest, y * rystride_bytes) = s;
 	    }
 	}
     }
@@ -2363,10 +2381,11 @@ matmul_c10_vanilla (gfc_array_c10 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	  s = (GFC_COMPLEX_10) 0;
 	  for (n = 0; n < count; n++)
-	    s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n*bxstride];
+	    s += GFC_DESCRIPTOR1_ELEM (a, n)
+	         * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
 	  GFC_DESCRIPTOR1_ELEM (retarray, y) = s;
 	}
     }
@@ -2393,15 +2412,16 @@ matmul_c10_vanilla (gfc_array_c10 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
-	  dest_y = &dest[y*rystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	  dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	  for (x = 0; x < xcount; x++)
 	    {
-	      abase_x = &abase[x*axstride];
+	      abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 	      s = (GFC_COMPLEX_10) 0;
 	      for (n = 0; n < count; n++)
-		s += abase_x[n*aystride] * bbase_y[n*bxstride];
-	      dest_y[x*rxstride] = s;
+		s += ARRAY_ELEM_AT_OFFSET (abase_x, n * aystride_bytes)
+		     * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
+	      ARRAY_ELEM_AT_OFFSET (dest_y, x * rxstride_bytes) = s;
 	    }
 	}
     }
@@ -2501,7 +2521,8 @@ matmul_c10 (gfc_array_c10 * const restrict retarray,
 
   index_type rxstride, rystride, axstride, aystride, bxstride, bystride;
   index_type x, y, n, count, xcount, ycount;
-  index_type aystride_bytes, bystride_bytes, rystride_bytes;
+  index_type axstride_bytes, aystride_bytes, bxstride_bytes, bystride_bytes,
+	     rxstride_bytes, rystride_bytes;
 
   assert (GFC_DESCRIPTOR_RANK (a) == 2
           || GFC_DESCRIPTOR_RANK (b) == 2);
@@ -2590,12 +2611,13 @@ matmul_c10 (gfc_array_c10 * const restrict retarray,
 	 either as a row or a column matrix. We want both cases to
 	 work. */
       rxstride = rystride = GFC_DESCRIPTOR_STRIDE(retarray,0);
-      rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
+      rxstride_bytes = rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
     }
   else
     {
       rxstride = GFC_DESCRIPTOR_STRIDE(retarray,0);
       rystride = GFC_DESCRIPTOR_STRIDE(retarray,1);
+      rxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
       rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,1);
     }
 
@@ -2604,6 +2626,7 @@ matmul_c10 (gfc_array_c10 * const restrict retarray,
       /* Treat it as a a row matrix A[1,count]. */
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = 1;
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = sizeof (GFC_COMPLEX_10);
 
       xcount = 1;
@@ -2613,6 +2636,7 @@ matmul_c10 (gfc_array_c10 * const restrict retarray,
     {
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = GFC_DESCRIPTOR_STRIDE(a,1);
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,1);
 
       count = GFC_DESCRIPTOR_EXTENT(a,1);
@@ -2631,17 +2655,20 @@ matmul_c10 (gfc_array_c10 * const restrict retarray,
     {
       /* Treat it as a column matrix B[count,1] */
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
 
       /* bystride should never be used for 1-dimensional b.
          The value is only used for calculation of the
          memory by the buffer.  */
       bystride = 256;
+      bystride_bytes = 99999999;
       ycount = 1;
     }
   else
     {
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
       bystride = GFC_DESCRIPTOR_STRIDE(b,1);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
       bystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,1);
       ycount = GFC_DESCRIPTOR_EXTENT(b,1);
     }
@@ -2701,12 +2728,11 @@ matmul_c10 (gfc_array_c10 * const restrict retarray,
 
 	 from netlib.org, translated to C, and modified for matmul.m4.  */
 
-      const GFC_COMPLEX_10 *a, *b;
       GFC_COMPLEX_10 *c;
       const index_type m = xcount, n = ycount, k = count;
 
       /* System generated locals */
-      index_type a_dim1, b_dim1, c_dim1,
+      index_type a_dim1, b_dim1,
 		 i1, i2, i3, i4, i5, i6;
 
       /* Local variables */
@@ -2716,25 +2742,22 @@ matmul_c10 (gfc_array_c10 * const restrict retarray,
       index_type isec, jsec, lsec, uisec, ujsec, ulsec;
       GFC_COMPLEX_10 *t1;
 
-      a = abase;
-      b = bbase;
       c = retarray->base_addr;
 
       /* Parameter adjustments */
-      c_dim1 = rystride;
       a_dim1 = aystride;
       b_dim1 = bystride;
 
 #define A_ARRAY_ELEM(i,j) \
-    a[(i) + (j) * a_dim1]
+    (ARRAY_ELEM_AT_OFFSET (abase, (i) * sizeof (GFC_COMPLEX_10) + (j) * aystride_bytes))
 
 #define B_ARRAY_ELEM(i,j) \
-    b[(i) + (j) * b_dim1]
+    (ARRAY_ELEM_AT_OFFSET (bbase, (i) * sizeof (GFC_COMPLEX_10) + (j) * bystride_bytes))
 
 #define C_ARRAY_ELEM(i,j) \
-    c[(i) + (j) * c_dim1]
+    (ARRAY_ELEM_AT_OFFSET (c, (i) * sizeof (GFC_COMPLEX_10) + (j) * rystride_bytes))
 
-      /* Empty c first.  */
+      /* Empty result first.  */
       for (j=0; j<n; j++)
 	for (i=0; i<m; i++)
 	  C_ARRAY_ELEM (i, j) = (GFC_COMPLEX_10)0;
@@ -2982,11 +3005,11 @@ matmul_c10 (gfc_array_c10 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
-	      dest_y = &dest[y*rystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	      dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	      for (x = 0; x < xcount; x++)
 		{
-		  abase_x = &abase[x*axstride];
+		  abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 		  s = (GFC_COMPLEX_10) 0;
 		  for (n = 0; n < count; n++)
 		    s += abase_x[n] * bbase_y[n];
@@ -3001,11 +3024,11 @@ matmul_c10 (gfc_array_c10 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	      s = (GFC_COMPLEX_10) 0;
 	      for (n = 0; n < count; n++)
 		s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n];
-	      dest[y*rystride] = s;
+	      ARRAY_ELEM_AT_OFFSET (dest, y * rystride_bytes) = s;
 	    }
 	}
     }
@@ -3016,10 +3039,11 @@ matmul_c10 (gfc_array_c10 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	  s = (GFC_COMPLEX_10) 0;
 	  for (n = 0; n < count; n++)
-	    s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n*bxstride];
+	    s += GFC_DESCRIPTOR1_ELEM (a, n)
+	         * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
 	  GFC_DESCRIPTOR1_ELEM (retarray, y) = s;
 	}
     }
@@ -3046,15 +3070,16 @@ matmul_c10 (gfc_array_c10 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
-	  dest_y = &dest[y*rystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	  dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	  for (x = 0; x < xcount; x++)
 	    {
-	      abase_x = &abase[x*axstride];
+	      abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 	      s = (GFC_COMPLEX_10) 0;
 	      for (n = 0; n < count; n++)
-		s += abase_x[n*aystride] * bbase_y[n*bxstride];
-	      dest_y[x*rxstride] = s;
+		s += ARRAY_ELEM_AT_OFFSET (abase_x, n * aystride_bytes)
+		     * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
+	      ARRAY_ELEM_AT_OFFSET (dest_y, x * rxstride_bytes) = s;
 	    }
 	}
     }
diff --git a/libgfortran/generated/matmul_c16.c b/libgfortran/generated/matmul_c16.c
index fe2c0cb44fde..8d592540b553 100644
--- a/libgfortran/generated/matmul_c16.c
+++ b/libgfortran/generated/matmul_c16.c
@@ -94,7 +94,8 @@ matmul_c16_avx (gfc_array_c16 * const restrict retarray,
 
   index_type rxstride, rystride, axstride, aystride, bxstride, bystride;
   index_type x, y, n, count, xcount, ycount;
-  index_type aystride_bytes, bystride_bytes, rystride_bytes;
+  index_type axstride_bytes, aystride_bytes, bxstride_bytes, bystride_bytes,
+	     rxstride_bytes, rystride_bytes;
 
   assert (GFC_DESCRIPTOR_RANK (a) == 2
           || GFC_DESCRIPTOR_RANK (b) == 2);
@@ -183,12 +184,13 @@ matmul_c16_avx (gfc_array_c16 * const restrict retarray,
 	 either as a row or a column matrix. We want both cases to
 	 work. */
       rxstride = rystride = GFC_DESCRIPTOR_STRIDE(retarray,0);
-      rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
+      rxstride_bytes = rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
     }
   else
     {
       rxstride = GFC_DESCRIPTOR_STRIDE(retarray,0);
       rystride = GFC_DESCRIPTOR_STRIDE(retarray,1);
+      rxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
       rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,1);
     }
 
@@ -197,6 +199,7 @@ matmul_c16_avx (gfc_array_c16 * const restrict retarray,
       /* Treat it as a a row matrix A[1,count]. */
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = 1;
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = sizeof (GFC_COMPLEX_16);
 
       xcount = 1;
@@ -206,6 +209,7 @@ matmul_c16_avx (gfc_array_c16 * const restrict retarray,
     {
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = GFC_DESCRIPTOR_STRIDE(a,1);
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,1);
 
       count = GFC_DESCRIPTOR_EXTENT(a,1);
@@ -224,17 +228,20 @@ matmul_c16_avx (gfc_array_c16 * const restrict retarray,
     {
       /* Treat it as a column matrix B[count,1] */
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
 
       /* bystride should never be used for 1-dimensional b.
          The value is only used for calculation of the
          memory by the buffer.  */
       bystride = 256;
+      bystride_bytes = 99999999;
       ycount = 1;
     }
   else
     {
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
       bystride = GFC_DESCRIPTOR_STRIDE(b,1);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
       bystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,1);
       ycount = GFC_DESCRIPTOR_EXTENT(b,1);
     }
@@ -294,12 +301,11 @@ matmul_c16_avx (gfc_array_c16 * const restrict retarray,
 
 	 from netlib.org, translated to C, and modified for matmul.m4.  */
 
-      const GFC_COMPLEX_16 *a, *b;
       GFC_COMPLEX_16 *c;
       const index_type m = xcount, n = ycount, k = count;
 
       /* System generated locals */
-      index_type a_dim1, b_dim1, c_dim1,
+      index_type a_dim1, b_dim1,
 		 i1, i2, i3, i4, i5, i6;
 
       /* Local variables */
@@ -309,25 +315,22 @@ matmul_c16_avx (gfc_array_c16 * const restrict retarray,
       index_type isec, jsec, lsec, uisec, ujsec, ulsec;
       GFC_COMPLEX_16 *t1;
 
-      a = abase;
-      b = bbase;
       c = retarray->base_addr;
 
       /* Parameter adjustments */
-      c_dim1 = rystride;
       a_dim1 = aystride;
       b_dim1 = bystride;
 
 #define A_ARRAY_ELEM(i,j) \
-    a[(i) + (j) * a_dim1]
+    (ARRAY_ELEM_AT_OFFSET (abase, (i) * sizeof (GFC_COMPLEX_16) + (j) * aystride_bytes))
 
 #define B_ARRAY_ELEM(i,j) \
-    b[(i) + (j) * b_dim1]
+    (ARRAY_ELEM_AT_OFFSET (bbase, (i) * sizeof (GFC_COMPLEX_16) + (j) * bystride_bytes))
 
 #define C_ARRAY_ELEM(i,j) \
-    c[(i) + (j) * c_dim1]
+    (ARRAY_ELEM_AT_OFFSET (c, (i) * sizeof (GFC_COMPLEX_16) + (j) * rystride_bytes))
 
-      /* Empty c first.  */
+      /* Empty result first.  */
       for (j=0; j<n; j++)
 	for (i=0; i<m; i++)
 	  C_ARRAY_ELEM (i, j) = (GFC_COMPLEX_16)0;
@@ -575,11 +578,11 @@ matmul_c16_avx (gfc_array_c16 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
-	      dest_y = &dest[y*rystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	      dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	      for (x = 0; x < xcount; x++)
 		{
-		  abase_x = &abase[x*axstride];
+		  abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 		  s = (GFC_COMPLEX_16) 0;
 		  for (n = 0; n < count; n++)
 		    s += abase_x[n] * bbase_y[n];
@@ -594,11 +597,11 @@ matmul_c16_avx (gfc_array_c16 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	      s = (GFC_COMPLEX_16) 0;
 	      for (n = 0; n < count; n++)
 		s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n];
-	      dest[y*rystride] = s;
+	      ARRAY_ELEM_AT_OFFSET (dest, y * rystride_bytes) = s;
 	    }
 	}
     }
@@ -609,10 +612,11 @@ matmul_c16_avx (gfc_array_c16 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	  s = (GFC_COMPLEX_16) 0;
 	  for (n = 0; n < count; n++)
-	    s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n*bxstride];
+	    s += GFC_DESCRIPTOR1_ELEM (a, n)
+	         * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
 	  GFC_DESCRIPTOR1_ELEM (retarray, y) = s;
 	}
     }
@@ -639,15 +643,16 @@ matmul_c16_avx (gfc_array_c16 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
-	  dest_y = &dest[y*rystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	  dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	  for (x = 0; x < xcount; x++)
 	    {
-	      abase_x = &abase[x*axstride];
+	      abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 	      s = (GFC_COMPLEX_16) 0;
 	      for (n = 0; n < count; n++)
-		s += abase_x[n*aystride] * bbase_y[n*bxstride];
-	      dest_y[x*rxstride] = s;
+		s += ARRAY_ELEM_AT_OFFSET (abase_x, n * aystride_bytes)
+		     * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
+	      ARRAY_ELEM_AT_OFFSET (dest_y, x * rxstride_bytes) = s;
 	    }
 	}
     }
@@ -674,7 +679,8 @@ matmul_c16_avx2 (gfc_array_c16 * const restrict retarray,
 
   index_type rxstride, rystride, axstride, aystride, bxstride, bystride;
   index_type x, y, n, count, xcount, ycount;
-  index_type aystride_bytes, bystride_bytes, rystride_bytes;
+  index_type axstride_bytes, aystride_bytes, bxstride_bytes, bystride_bytes,
+	     rxstride_bytes, rystride_bytes;
 
   assert (GFC_DESCRIPTOR_RANK (a) == 2
           || GFC_DESCRIPTOR_RANK (b) == 2);
@@ -763,12 +769,13 @@ matmul_c16_avx2 (gfc_array_c16 * const restrict retarray,
 	 either as a row or a column matrix. We want both cases to
 	 work. */
       rxstride = rystride = GFC_DESCRIPTOR_STRIDE(retarray,0);
-      rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
+      rxstride_bytes = rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
     }
   else
     {
       rxstride = GFC_DESCRIPTOR_STRIDE(retarray,0);
       rystride = GFC_DESCRIPTOR_STRIDE(retarray,1);
+      rxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
       rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,1);
     }
 
@@ -777,6 +784,7 @@ matmul_c16_avx2 (gfc_array_c16 * const restrict retarray,
       /* Treat it as a a row matrix A[1,count]. */
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = 1;
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = sizeof (GFC_COMPLEX_16);
 
       xcount = 1;
@@ -786,6 +794,7 @@ matmul_c16_avx2 (gfc_array_c16 * const restrict retarray,
     {
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = GFC_DESCRIPTOR_STRIDE(a,1);
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,1);
 
       count = GFC_DESCRIPTOR_EXTENT(a,1);
@@ -804,17 +813,20 @@ matmul_c16_avx2 (gfc_array_c16 * const restrict retarray,
     {
       /* Treat it as a column matrix B[count,1] */
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
 
       /* bystride should never be used for 1-dimensional b.
          The value is only used for calculation of the
          memory by the buffer.  */
       bystride = 256;
+      bystride_bytes = 99999999;
       ycount = 1;
     }
   else
     {
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
       bystride = GFC_DESCRIPTOR_STRIDE(b,1);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
       bystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,1);
       ycount = GFC_DESCRIPTOR_EXTENT(b,1);
     }
@@ -874,12 +886,11 @@ matmul_c16_avx2 (gfc_array_c16 * const restrict retarray,
 
 	 from netlib.org, translated to C, and modified for matmul.m4.  */
 
-      const GFC_COMPLEX_16 *a, *b;
       GFC_COMPLEX_16 *c;
       const index_type m = xcount, n = ycount, k = count;
 
       /* System generated locals */
-      index_type a_dim1, b_dim1, c_dim1,
+      index_type a_dim1, b_dim1,
 		 i1, i2, i3, i4, i5, i6;
 
       /* Local variables */
@@ -889,25 +900,22 @@ matmul_c16_avx2 (gfc_array_c16 * const restrict retarray,
       index_type isec, jsec, lsec, uisec, ujsec, ulsec;
       GFC_COMPLEX_16 *t1;
 
-      a = abase;
-      b = bbase;
       c = retarray->base_addr;
 
       /* Parameter adjustments */
-      c_dim1 = rystride;
       a_dim1 = aystride;
       b_dim1 = bystride;
 
 #define A_ARRAY_ELEM(i,j) \
-    a[(i) + (j) * a_dim1]
+    (ARRAY_ELEM_AT_OFFSET (abase, (i) * sizeof (GFC_COMPLEX_16) + (j) * aystride_bytes))
 
 #define B_ARRAY_ELEM(i,j) \
-    b[(i) + (j) * b_dim1]
+    (ARRAY_ELEM_AT_OFFSET (bbase, (i) * sizeof (GFC_COMPLEX_16) + (j) * bystride_bytes))
 
 #define C_ARRAY_ELEM(i,j) \
-    c[(i) + (j) * c_dim1]
+    (ARRAY_ELEM_AT_OFFSET (c, (i) * sizeof (GFC_COMPLEX_16) + (j) * rystride_bytes))
 
-      /* Empty c first.  */
+      /* Empty result first.  */
       for (j=0; j<n; j++)
 	for (i=0; i<m; i++)
 	  C_ARRAY_ELEM (i, j) = (GFC_COMPLEX_16)0;
@@ -1155,11 +1163,11 @@ matmul_c16_avx2 (gfc_array_c16 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
-	      dest_y = &dest[y*rystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	      dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	      for (x = 0; x < xcount; x++)
 		{
-		  abase_x = &abase[x*axstride];
+		  abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 		  s = (GFC_COMPLEX_16) 0;
 		  for (n = 0; n < count; n++)
 		    s += abase_x[n] * bbase_y[n];
@@ -1174,11 +1182,11 @@ matmul_c16_avx2 (gfc_array_c16 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	      s = (GFC_COMPLEX_16) 0;
 	      for (n = 0; n < count; n++)
 		s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n];
-	      dest[y*rystride] = s;
+	      ARRAY_ELEM_AT_OFFSET (dest, y * rystride_bytes) = s;
 	    }
 	}
     }
@@ -1189,10 +1197,11 @@ matmul_c16_avx2 (gfc_array_c16 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	  s = (GFC_COMPLEX_16) 0;
 	  for (n = 0; n < count; n++)
-	    s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n*bxstride];
+	    s += GFC_DESCRIPTOR1_ELEM (a, n)
+	         * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
 	  GFC_DESCRIPTOR1_ELEM (retarray, y) = s;
 	}
     }
@@ -1219,15 +1228,16 @@ matmul_c16_avx2 (gfc_array_c16 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
-	  dest_y = &dest[y*rystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	  dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	  for (x = 0; x < xcount; x++)
 	    {
-	      abase_x = &abase[x*axstride];
+	      abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 	      s = (GFC_COMPLEX_16) 0;
 	      for (n = 0; n < count; n++)
-		s += abase_x[n*aystride] * bbase_y[n*bxstride];
-	      dest_y[x*rxstride] = s;
+		s += ARRAY_ELEM_AT_OFFSET (abase_x, n * aystride_bytes)
+		     * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
+	      ARRAY_ELEM_AT_OFFSET (dest_y, x * rxstride_bytes) = s;
 	    }
 	}
     }
@@ -1254,7 +1264,8 @@ matmul_c16_avx512f (gfc_array_c16 * const restrict retarray,
 
   index_type rxstride, rystride, axstride, aystride, bxstride, bystride;
   index_type x, y, n, count, xcount, ycount;
-  index_type aystride_bytes, bystride_bytes, rystride_bytes;
+  index_type axstride_bytes, aystride_bytes, bxstride_bytes, bystride_bytes,
+	     rxstride_bytes, rystride_bytes;
 
   assert (GFC_DESCRIPTOR_RANK (a) == 2
           || GFC_DESCRIPTOR_RANK (b) == 2);
@@ -1343,12 +1354,13 @@ matmul_c16_avx512f (gfc_array_c16 * const restrict retarray,
 	 either as a row or a column matrix. We want both cases to
 	 work. */
       rxstride = rystride = GFC_DESCRIPTOR_STRIDE(retarray,0);
-      rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
+      rxstride_bytes = rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
     }
   else
     {
       rxstride = GFC_DESCRIPTOR_STRIDE(retarray,0);
       rystride = GFC_DESCRIPTOR_STRIDE(retarray,1);
+      rxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
       rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,1);
     }
 
@@ -1357,6 +1369,7 @@ matmul_c16_avx512f (gfc_array_c16 * const restrict retarray,
       /* Treat it as a a row matrix A[1,count]. */
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = 1;
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = sizeof (GFC_COMPLEX_16);
 
       xcount = 1;
@@ -1366,6 +1379,7 @@ matmul_c16_avx512f (gfc_array_c16 * const restrict retarray,
     {
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = GFC_DESCRIPTOR_STRIDE(a,1);
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,1);
 
       count = GFC_DESCRIPTOR_EXTENT(a,1);
@@ -1384,17 +1398,20 @@ matmul_c16_avx512f (gfc_array_c16 * const restrict retarray,
     {
       /* Treat it as a column matrix B[count,1] */
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
 
       /* bystride should never be used for 1-dimensional b.
          The value is only used for calculation of the
          memory by the buffer.  */
       bystride = 256;
+      bystride_bytes = 99999999;
       ycount = 1;
     }
   else
     {
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
       bystride = GFC_DESCRIPTOR_STRIDE(b,1);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
       bystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,1);
       ycount = GFC_DESCRIPTOR_EXTENT(b,1);
     }
@@ -1454,12 +1471,11 @@ matmul_c16_avx512f (gfc_array_c16 * const restrict retarray,
 
 	 from netlib.org, translated to C, and modified for matmul.m4.  */
 
-      const GFC_COMPLEX_16 *a, *b;
       GFC_COMPLEX_16 *c;
       const index_type m = xcount, n = ycount, k = count;
 
       /* System generated locals */
-      index_type a_dim1, b_dim1, c_dim1,
+      index_type a_dim1, b_dim1,
 		 i1, i2, i3, i4, i5, i6;
 
       /* Local variables */
@@ -1469,25 +1485,22 @@ matmul_c16_avx512f (gfc_array_c16 * const restrict retarray,
       index_type isec, jsec, lsec, uisec, ujsec, ulsec;
       GFC_COMPLEX_16 *t1;
 
-      a = abase;
-      b = bbase;
       c = retarray->base_addr;
 
       /* Parameter adjustments */
-      c_dim1 = rystride;
       a_dim1 = aystride;
       b_dim1 = bystride;
 
 #define A_ARRAY_ELEM(i,j) \
-    a[(i) + (j) * a_dim1]
+    (ARRAY_ELEM_AT_OFFSET (abase, (i) * sizeof (GFC_COMPLEX_16) + (j) * aystride_bytes))
 
 #define B_ARRAY_ELEM(i,j) \
-    b[(i) + (j) * b_dim1]
+    (ARRAY_ELEM_AT_OFFSET (bbase, (i) * sizeof (GFC_COMPLEX_16) + (j) * bystride_bytes))
 
 #define C_ARRAY_ELEM(i,j) \
-    c[(i) + (j) * c_dim1]
+    (ARRAY_ELEM_AT_OFFSET (c, (i) * sizeof (GFC_COMPLEX_16) + (j) * rystride_bytes))
 
-      /* Empty c first.  */
+      /* Empty result first.  */
       for (j=0; j<n; j++)
 	for (i=0; i<m; i++)
 	  C_ARRAY_ELEM (i, j) = (GFC_COMPLEX_16)0;
@@ -1735,11 +1748,11 @@ matmul_c16_avx512f (gfc_array_c16 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
-	      dest_y = &dest[y*rystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	      dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	      for (x = 0; x < xcount; x++)
 		{
-		  abase_x = &abase[x*axstride];
+		  abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 		  s = (GFC_COMPLEX_16) 0;
 		  for (n = 0; n < count; n++)
 		    s += abase_x[n] * bbase_y[n];
@@ -1754,11 +1767,11 @@ matmul_c16_avx512f (gfc_array_c16 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	      s = (GFC_COMPLEX_16) 0;
 	      for (n = 0; n < count; n++)
 		s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n];
-	      dest[y*rystride] = s;
+	      ARRAY_ELEM_AT_OFFSET (dest, y * rystride_bytes) = s;
 	    }
 	}
     }
@@ -1769,10 +1782,11 @@ matmul_c16_avx512f (gfc_array_c16 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	  s = (GFC_COMPLEX_16) 0;
 	  for (n = 0; n < count; n++)
-	    s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n*bxstride];
+	    s += GFC_DESCRIPTOR1_ELEM (a, n)
+	         * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
 	  GFC_DESCRIPTOR1_ELEM (retarray, y) = s;
 	}
     }
@@ -1799,15 +1813,16 @@ matmul_c16_avx512f (gfc_array_c16 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
-	  dest_y = &dest[y*rystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	  dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	  for (x = 0; x < xcount; x++)
 	    {
-	      abase_x = &abase[x*axstride];
+	      abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 	      s = (GFC_COMPLEX_16) 0;
 	      for (n = 0; n < count; n++)
-		s += abase_x[n*aystride] * bbase_y[n*bxstride];
-	      dest_y[x*rxstride] = s;
+		s += ARRAY_ELEM_AT_OFFSET (abase_x, n * aystride_bytes)
+		     * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
+	      ARRAY_ELEM_AT_OFFSET (dest_y, x * rxstride_bytes) = s;
 	    }
 	}
     }
@@ -1848,7 +1863,8 @@ matmul_c16_vanilla (gfc_array_c16 * const restrict retarray,
 
   index_type rxstride, rystride, axstride, aystride, bxstride, bystride;
   index_type x, y, n, count, xcount, ycount;
-  index_type aystride_bytes, bystride_bytes, rystride_bytes;
+  index_type axstride_bytes, aystride_bytes, bxstride_bytes, bystride_bytes,
+	     rxstride_bytes, rystride_bytes;
 
   assert (GFC_DESCRIPTOR_RANK (a) == 2
           || GFC_DESCRIPTOR_RANK (b) == 2);
@@ -1937,12 +1953,13 @@ matmul_c16_vanilla (gfc_array_c16 * const restrict retarray,
 	 either as a row or a column matrix. We want both cases to
 	 work. */
       rxstride = rystride = GFC_DESCRIPTOR_STRIDE(retarray,0);
-      rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
+      rxstride_bytes = rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
     }
   else
     {
       rxstride = GFC_DESCRIPTOR_STRIDE(retarray,0);
       rystride = GFC_DESCRIPTOR_STRIDE(retarray,1);
+      rxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
       rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,1);
     }
 
@@ -1951,6 +1968,7 @@ matmul_c16_vanilla (gfc_array_c16 * const restrict retarray,
       /* Treat it as a a row matrix A[1,count]. */
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = 1;
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = sizeof (GFC_COMPLEX_16);
 
       xcount = 1;
@@ -1960,6 +1978,7 @@ matmul_c16_vanilla (gfc_array_c16 * const restrict retarray,
     {
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = GFC_DESCRIPTOR_STRIDE(a,1);
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,1);
 
       count = GFC_DESCRIPTOR_EXTENT(a,1);
@@ -1978,17 +1997,20 @@ matmul_c16_vanilla (gfc_array_c16 * const restrict retarray,
     {
       /* Treat it as a column matrix B[count,1] */
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
 
       /* bystride should never be used for 1-dimensional b.
          The value is only used for calculation of the
          memory by the buffer.  */
       bystride = 256;
+      bystride_bytes = 99999999;
       ycount = 1;
     }
   else
     {
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
       bystride = GFC_DESCRIPTOR_STRIDE(b,1);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
       bystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,1);
       ycount = GFC_DESCRIPTOR_EXTENT(b,1);
     }
@@ -2048,12 +2070,11 @@ matmul_c16_vanilla (gfc_array_c16 * const restrict retarray,
 
 	 from netlib.org, translated to C, and modified for matmul.m4.  */
 
-      const GFC_COMPLEX_16 *a, *b;
       GFC_COMPLEX_16 *c;
       const index_type m = xcount, n = ycount, k = count;
 
       /* System generated locals */
-      index_type a_dim1, b_dim1, c_dim1,
+      index_type a_dim1, b_dim1,
 		 i1, i2, i3, i4, i5, i6;
 
       /* Local variables */
@@ -2063,25 +2084,22 @@ matmul_c16_vanilla (gfc_array_c16 * const restrict retarray,
       index_type isec, jsec, lsec, uisec, ujsec, ulsec;
       GFC_COMPLEX_16 *t1;
 
-      a = abase;
-      b = bbase;
       c = retarray->base_addr;
 
       /* Parameter adjustments */
-      c_dim1 = rystride;
       a_dim1 = aystride;
       b_dim1 = bystride;
 
 #define A_ARRAY_ELEM(i,j) \
-    a[(i) + (j) * a_dim1]
+    (ARRAY_ELEM_AT_OFFSET (abase, (i) * sizeof (GFC_COMPLEX_16) + (j) * aystride_bytes))
 
 #define B_ARRAY_ELEM(i,j) \
-    b[(i) + (j) * b_dim1]
+    (ARRAY_ELEM_AT_OFFSET (bbase, (i) * sizeof (GFC_COMPLEX_16) + (j) * bystride_bytes))
 
 #define C_ARRAY_ELEM(i,j) \
-    c[(i) + (j) * c_dim1]
+    (ARRAY_ELEM_AT_OFFSET (c, (i) * sizeof (GFC_COMPLEX_16) + (j) * rystride_bytes))
 
-      /* Empty c first.  */
+      /* Empty result first.  */
       for (j=0; j<n; j++)
 	for (i=0; i<m; i++)
 	  C_ARRAY_ELEM (i, j) = (GFC_COMPLEX_16)0;
@@ -2329,11 +2347,11 @@ matmul_c16_vanilla (gfc_array_c16 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
-	      dest_y = &dest[y*rystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	      dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	      for (x = 0; x < xcount; x++)
 		{
-		  abase_x = &abase[x*axstride];
+		  abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 		  s = (GFC_COMPLEX_16) 0;
 		  for (n = 0; n < count; n++)
 		    s += abase_x[n] * bbase_y[n];
@@ -2348,11 +2366,11 @@ matmul_c16_vanilla (gfc_array_c16 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	      s = (GFC_COMPLEX_16) 0;
 	      for (n = 0; n < count; n++)
 		s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n];
-	      dest[y*rystride] = s;
+	      ARRAY_ELEM_AT_OFFSET (dest, y * rystride_bytes) = s;
 	    }
 	}
     }
@@ -2363,10 +2381,11 @@ matmul_c16_vanilla (gfc_array_c16 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	  s = (GFC_COMPLEX_16) 0;
 	  for (n = 0; n < count; n++)
-	    s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n*bxstride];
+	    s += GFC_DESCRIPTOR1_ELEM (a, n)
+	         * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
 	  GFC_DESCRIPTOR1_ELEM (retarray, y) = s;
 	}
     }
@@ -2393,15 +2412,16 @@ matmul_c16_vanilla (gfc_array_c16 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
-	  dest_y = &dest[y*rystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	  dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	  for (x = 0; x < xcount; x++)
 	    {
-	      abase_x = &abase[x*axstride];
+	      abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 	      s = (GFC_COMPLEX_16) 0;
 	      for (n = 0; n < count; n++)
-		s += abase_x[n*aystride] * bbase_y[n*bxstride];
-	      dest_y[x*rxstride] = s;
+		s += ARRAY_ELEM_AT_OFFSET (abase_x, n * aystride_bytes)
+		     * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
+	      ARRAY_ELEM_AT_OFFSET (dest_y, x * rxstride_bytes) = s;
 	    }
 	}
     }
@@ -2501,7 +2521,8 @@ matmul_c16 (gfc_array_c16 * const restrict retarray,
 
   index_type rxstride, rystride, axstride, aystride, bxstride, bystride;
   index_type x, y, n, count, xcount, ycount;
-  index_type aystride_bytes, bystride_bytes, rystride_bytes;
+  index_type axstride_bytes, aystride_bytes, bxstride_bytes, bystride_bytes,
+	     rxstride_bytes, rystride_bytes;
 
   assert (GFC_DESCRIPTOR_RANK (a) == 2
           || GFC_DESCRIPTOR_RANK (b) == 2);
@@ -2590,12 +2611,13 @@ matmul_c16 (gfc_array_c16 * const restrict retarray,
 	 either as a row or a column matrix. We want both cases to
 	 work. */
       rxstride = rystride = GFC_DESCRIPTOR_STRIDE(retarray,0);
-      rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
+      rxstride_bytes = rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
     }
   else
     {
       rxstride = GFC_DESCRIPTOR_STRIDE(retarray,0);
       rystride = GFC_DESCRIPTOR_STRIDE(retarray,1);
+      rxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
       rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,1);
     }
 
@@ -2604,6 +2626,7 @@ matmul_c16 (gfc_array_c16 * const restrict retarray,
       /* Treat it as a a row matrix A[1,count]. */
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = 1;
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = sizeof (GFC_COMPLEX_16);
 
       xcount = 1;
@@ -2613,6 +2636,7 @@ matmul_c16 (gfc_array_c16 * const restrict retarray,
     {
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = GFC_DESCRIPTOR_STRIDE(a,1);
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,1);
 
       count = GFC_DESCRIPTOR_EXTENT(a,1);
@@ -2631,17 +2655,20 @@ matmul_c16 (gfc_array_c16 * const restrict retarray,
     {
       /* Treat it as a column matrix B[count,1] */
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
 
       /* bystride should never be used for 1-dimensional b.
          The value is only used for calculation of the
          memory by the buffer.  */
       bystride = 256;
+      bystride_bytes = 99999999;
       ycount = 1;
     }
   else
     {
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
       bystride = GFC_DESCRIPTOR_STRIDE(b,1);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
       bystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,1);
       ycount = GFC_DESCRIPTOR_EXTENT(b,1);
     }
@@ -2701,12 +2728,11 @@ matmul_c16 (gfc_array_c16 * const restrict retarray,
 
 	 from netlib.org, translated to C, and modified for matmul.m4.  */
 
-      const GFC_COMPLEX_16 *a, *b;
       GFC_COMPLEX_16 *c;
       const index_type m = xcount, n = ycount, k = count;
 
       /* System generated locals */
-      index_type a_dim1, b_dim1, c_dim1,
+      index_type a_dim1, b_dim1,
 		 i1, i2, i3, i4, i5, i6;
 
       /* Local variables */
@@ -2716,25 +2742,22 @@ matmul_c16 (gfc_array_c16 * const restrict retarray,
       index_type isec, jsec, lsec, uisec, ujsec, ulsec;
       GFC_COMPLEX_16 *t1;
 
-      a = abase;
-      b = bbase;
       c = retarray->base_addr;
 
       /* Parameter adjustments */
-      c_dim1 = rystride;
       a_dim1 = aystride;
       b_dim1 = bystride;
 
 #define A_ARRAY_ELEM(i,j) \
-    a[(i) + (j) * a_dim1]
+    (ARRAY_ELEM_AT_OFFSET (abase, (i) * sizeof (GFC_COMPLEX_16) + (j) * aystride_bytes))
 
 #define B_ARRAY_ELEM(i,j) \
-    b[(i) + (j) * b_dim1]
+    (ARRAY_ELEM_AT_OFFSET (bbase, (i) * sizeof (GFC_COMPLEX_16) + (j) * bystride_bytes))
 
 #define C_ARRAY_ELEM(i,j) \
-    c[(i) + (j) * c_dim1]
+    (ARRAY_ELEM_AT_OFFSET (c, (i) * sizeof (GFC_COMPLEX_16) + (j) * rystride_bytes))
 
-      /* Empty c first.  */
+      /* Empty result first.  */
       for (j=0; j<n; j++)
 	for (i=0; i<m; i++)
 	  C_ARRAY_ELEM (i, j) = (GFC_COMPLEX_16)0;
@@ -2982,11 +3005,11 @@ matmul_c16 (gfc_array_c16 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
-	      dest_y = &dest[y*rystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	      dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	      for (x = 0; x < xcount; x++)
 		{
-		  abase_x = &abase[x*axstride];
+		  abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 		  s = (GFC_COMPLEX_16) 0;
 		  for (n = 0; n < count; n++)
 		    s += abase_x[n] * bbase_y[n];
@@ -3001,11 +3024,11 @@ matmul_c16 (gfc_array_c16 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	      s = (GFC_COMPLEX_16) 0;
 	      for (n = 0; n < count; n++)
 		s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n];
-	      dest[y*rystride] = s;
+	      ARRAY_ELEM_AT_OFFSET (dest, y * rystride_bytes) = s;
 	    }
 	}
     }
@@ -3016,10 +3039,11 @@ matmul_c16 (gfc_array_c16 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	  s = (GFC_COMPLEX_16) 0;
 	  for (n = 0; n < count; n++)
-	    s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n*bxstride];
+	    s += GFC_DESCRIPTOR1_ELEM (a, n)
+	         * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
 	  GFC_DESCRIPTOR1_ELEM (retarray, y) = s;
 	}
     }
@@ -3046,15 +3070,16 @@ matmul_c16 (gfc_array_c16 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
-	  dest_y = &dest[y*rystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	  dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	  for (x = 0; x < xcount; x++)
 	    {
-	      abase_x = &abase[x*axstride];
+	      abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 	      s = (GFC_COMPLEX_16) 0;
 	      for (n = 0; n < count; n++)
-		s += abase_x[n*aystride] * bbase_y[n*bxstride];
-	      dest_y[x*rxstride] = s;
+		s += ARRAY_ELEM_AT_OFFSET (abase_x, n * aystride_bytes)
+		     * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
+	      ARRAY_ELEM_AT_OFFSET (dest_y, x * rxstride_bytes) = s;
 	    }
 	}
     }
diff --git a/libgfortran/generated/matmul_c17.c b/libgfortran/generated/matmul_c17.c
index 5e17e4057389..47b76385fb67 100644
--- a/libgfortran/generated/matmul_c17.c
+++ b/libgfortran/generated/matmul_c17.c
@@ -94,7 +94,8 @@ matmul_c17_avx (gfc_array_c17 * const restrict retarray,
 
   index_type rxstride, rystride, axstride, aystride, bxstride, bystride;
   index_type x, y, n, count, xcount, ycount;
-  index_type aystride_bytes, bystride_bytes, rystride_bytes;
+  index_type axstride_bytes, aystride_bytes, bxstride_bytes, bystride_bytes,
+	     rxstride_bytes, rystride_bytes;
 
   assert (GFC_DESCRIPTOR_RANK (a) == 2
           || GFC_DESCRIPTOR_RANK (b) == 2);
@@ -183,12 +184,13 @@ matmul_c17_avx (gfc_array_c17 * const restrict retarray,
 	 either as a row or a column matrix. We want both cases to
 	 work. */
       rxstride = rystride = GFC_DESCRIPTOR_STRIDE(retarray,0);
-      rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
+      rxstride_bytes = rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
     }
   else
     {
       rxstride = GFC_DESCRIPTOR_STRIDE(retarray,0);
       rystride = GFC_DESCRIPTOR_STRIDE(retarray,1);
+      rxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
       rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,1);
     }
 
@@ -197,6 +199,7 @@ matmul_c17_avx (gfc_array_c17 * const restrict retarray,
       /* Treat it as a a row matrix A[1,count]. */
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = 1;
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = sizeof (GFC_COMPLEX_17);
 
       xcount = 1;
@@ -206,6 +209,7 @@ matmul_c17_avx (gfc_array_c17 * const restrict retarray,
     {
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = GFC_DESCRIPTOR_STRIDE(a,1);
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,1);
 
       count = GFC_DESCRIPTOR_EXTENT(a,1);
@@ -224,17 +228,20 @@ matmul_c17_avx (gfc_array_c17 * const restrict retarray,
     {
       /* Treat it as a column matrix B[count,1] */
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
 
       /* bystride should never be used for 1-dimensional b.
          The value is only used for calculation of the
          memory by the buffer.  */
       bystride = 256;
+      bystride_bytes = 99999999;
       ycount = 1;
     }
   else
     {
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
       bystride = GFC_DESCRIPTOR_STRIDE(b,1);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
       bystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,1);
       ycount = GFC_DESCRIPTOR_EXTENT(b,1);
     }
@@ -294,12 +301,11 @@ matmul_c17_avx (gfc_array_c17 * const restrict retarray,
 
 	 from netlib.org, translated to C, and modified for matmul.m4.  */
 
-      const GFC_COMPLEX_17 *a, *b;
       GFC_COMPLEX_17 *c;
       const index_type m = xcount, n = ycount, k = count;
 
       /* System generated locals */
-      index_type a_dim1, b_dim1, c_dim1,
+      index_type a_dim1, b_dim1,
 		 i1, i2, i3, i4, i5, i6;
 
       /* Local variables */
@@ -309,25 +315,22 @@ matmul_c17_avx (gfc_array_c17 * const restrict retarray,
       index_type isec, jsec, lsec, uisec, ujsec, ulsec;
       GFC_COMPLEX_17 *t1;
 
-      a = abase;
-      b = bbase;
       c = retarray->base_addr;
 
       /* Parameter adjustments */
-      c_dim1 = rystride;
       a_dim1 = aystride;
       b_dim1 = bystride;
 
 #define A_ARRAY_ELEM(i,j) \
-    a[(i) + (j) * a_dim1]
+    (ARRAY_ELEM_AT_OFFSET (abase, (i) * sizeof (GFC_COMPLEX_17) + (j) * aystride_bytes))
 
 #define B_ARRAY_ELEM(i,j) \
-    b[(i) + (j) * b_dim1]
+    (ARRAY_ELEM_AT_OFFSET (bbase, (i) * sizeof (GFC_COMPLEX_17) + (j) * bystride_bytes))
 
 #define C_ARRAY_ELEM(i,j) \
-    c[(i) + (j) * c_dim1]
+    (ARRAY_ELEM_AT_OFFSET (c, (i) * sizeof (GFC_COMPLEX_17) + (j) * rystride_bytes))
 
-      /* Empty c first.  */
+      /* Empty result first.  */
       for (j=0; j<n; j++)
 	for (i=0; i<m; i++)
 	  C_ARRAY_ELEM (i, j) = (GFC_COMPLEX_17)0;
@@ -575,11 +578,11 @@ matmul_c17_avx (gfc_array_c17 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
-	      dest_y = &dest[y*rystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	      dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	      for (x = 0; x < xcount; x++)
 		{
-		  abase_x = &abase[x*axstride];
+		  abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 		  s = (GFC_COMPLEX_17) 0;
 		  for (n = 0; n < count; n++)
 		    s += abase_x[n] * bbase_y[n];
@@ -594,11 +597,11 @@ matmul_c17_avx (gfc_array_c17 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	      s = (GFC_COMPLEX_17) 0;
 	      for (n = 0; n < count; n++)
 		s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n];
-	      dest[y*rystride] = s;
+	      ARRAY_ELEM_AT_OFFSET (dest, y * rystride_bytes) = s;
 	    }
 	}
     }
@@ -609,10 +612,11 @@ matmul_c17_avx (gfc_array_c17 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	  s = (GFC_COMPLEX_17) 0;
 	  for (n = 0; n < count; n++)
-	    s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n*bxstride];
+	    s += GFC_DESCRIPTOR1_ELEM (a, n)
+	         * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
 	  GFC_DESCRIPTOR1_ELEM (retarray, y) = s;
 	}
     }
@@ -639,15 +643,16 @@ matmul_c17_avx (gfc_array_c17 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
-	  dest_y = &dest[y*rystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	  dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	  for (x = 0; x < xcount; x++)
 	    {
-	      abase_x = &abase[x*axstride];
+	      abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 	      s = (GFC_COMPLEX_17) 0;
 	      for (n = 0; n < count; n++)
-		s += abase_x[n*aystride] * bbase_y[n*bxstride];
-	      dest_y[x*rxstride] = s;
+		s += ARRAY_ELEM_AT_OFFSET (abase_x, n * aystride_bytes)
+		     * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
+	      ARRAY_ELEM_AT_OFFSET (dest_y, x * rxstride_bytes) = s;
 	    }
 	}
     }
@@ -674,7 +679,8 @@ matmul_c17_avx2 (gfc_array_c17 * const restrict retarray,
 
   index_type rxstride, rystride, axstride, aystride, bxstride, bystride;
   index_type x, y, n, count, xcount, ycount;
-  index_type aystride_bytes, bystride_bytes, rystride_bytes;
+  index_type axstride_bytes, aystride_bytes, bxstride_bytes, bystride_bytes,
+	     rxstride_bytes, rystride_bytes;
 
   assert (GFC_DESCRIPTOR_RANK (a) == 2
           || GFC_DESCRIPTOR_RANK (b) == 2);
@@ -763,12 +769,13 @@ matmul_c17_avx2 (gfc_array_c17 * const restrict retarray,
 	 either as a row or a column matrix. We want both cases to
 	 work. */
       rxstride = rystride = GFC_DESCRIPTOR_STRIDE(retarray,0);
-      rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
+      rxstride_bytes = rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
     }
   else
     {
       rxstride = GFC_DESCRIPTOR_STRIDE(retarray,0);
       rystride = GFC_DESCRIPTOR_STRIDE(retarray,1);
+      rxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
       rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,1);
     }
 
@@ -777,6 +784,7 @@ matmul_c17_avx2 (gfc_array_c17 * const restrict retarray,
       /* Treat it as a a row matrix A[1,count]. */
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = 1;
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = sizeof (GFC_COMPLEX_17);
 
       xcount = 1;
@@ -786,6 +794,7 @@ matmul_c17_avx2 (gfc_array_c17 * const restrict retarray,
     {
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = GFC_DESCRIPTOR_STRIDE(a,1);
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,1);
 
       count = GFC_DESCRIPTOR_EXTENT(a,1);
@@ -804,17 +813,20 @@ matmul_c17_avx2 (gfc_array_c17 * const restrict retarray,
     {
       /* Treat it as a column matrix B[count,1] */
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
 
       /* bystride should never be used for 1-dimensional b.
          The value is only used for calculation of the
          memory by the buffer.  */
       bystride = 256;
+      bystride_bytes = 99999999;
       ycount = 1;
     }
   else
     {
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
       bystride = GFC_DESCRIPTOR_STRIDE(b,1);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
       bystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,1);
       ycount = GFC_DESCRIPTOR_EXTENT(b,1);
     }
@@ -874,12 +886,11 @@ matmul_c17_avx2 (gfc_array_c17 * const restrict retarray,
 
 	 from netlib.org, translated to C, and modified for matmul.m4.  */
 
-      const GFC_COMPLEX_17 *a, *b;
       GFC_COMPLEX_17 *c;
       const index_type m = xcount, n = ycount, k = count;
 
       /* System generated locals */
-      index_type a_dim1, b_dim1, c_dim1,
+      index_type a_dim1, b_dim1,
 		 i1, i2, i3, i4, i5, i6;
 
       /* Local variables */
@@ -889,25 +900,22 @@ matmul_c17_avx2 (gfc_array_c17 * const restrict retarray,
       index_type isec, jsec, lsec, uisec, ujsec, ulsec;
       GFC_COMPLEX_17 *t1;
 
-      a = abase;
-      b = bbase;
       c = retarray->base_addr;
 
       /* Parameter adjustments */
-      c_dim1 = rystride;
       a_dim1 = aystride;
       b_dim1 = bystride;
 
 #define A_ARRAY_ELEM(i,j) \
-    a[(i) + (j) * a_dim1]
+    (ARRAY_ELEM_AT_OFFSET (abase, (i) * sizeof (GFC_COMPLEX_17) + (j) * aystride_bytes))
 
 #define B_ARRAY_ELEM(i,j) \
-    b[(i) + (j) * b_dim1]
+    (ARRAY_ELEM_AT_OFFSET (bbase, (i) * sizeof (GFC_COMPLEX_17) + (j) * bystride_bytes))
 
 #define C_ARRAY_ELEM(i,j) \
-    c[(i) + (j) * c_dim1]
+    (ARRAY_ELEM_AT_OFFSET (c, (i) * sizeof (GFC_COMPLEX_17) + (j) * rystride_bytes))
 
-      /* Empty c first.  */
+      /* Empty result first.  */
       for (j=0; j<n; j++)
 	for (i=0; i<m; i++)
 	  C_ARRAY_ELEM (i, j) = (GFC_COMPLEX_17)0;
@@ -1155,11 +1163,11 @@ matmul_c17_avx2 (gfc_array_c17 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
-	      dest_y = &dest[y*rystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	      dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	      for (x = 0; x < xcount; x++)
 		{
-		  abase_x = &abase[x*axstride];
+		  abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 		  s = (GFC_COMPLEX_17) 0;
 		  for (n = 0; n < count; n++)
 		    s += abase_x[n] * bbase_y[n];
@@ -1174,11 +1182,11 @@ matmul_c17_avx2 (gfc_array_c17 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	      s = (GFC_COMPLEX_17) 0;
 	      for (n = 0; n < count; n++)
 		s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n];
-	      dest[y*rystride] = s;
+	      ARRAY_ELEM_AT_OFFSET (dest, y * rystride_bytes) = s;
 	    }
 	}
     }
@@ -1189,10 +1197,11 @@ matmul_c17_avx2 (gfc_array_c17 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	  s = (GFC_COMPLEX_17) 0;
 	  for (n = 0; n < count; n++)
-	    s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n*bxstride];
+	    s += GFC_DESCRIPTOR1_ELEM (a, n)
+	         * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
 	  GFC_DESCRIPTOR1_ELEM (retarray, y) = s;
 	}
     }
@@ -1219,15 +1228,16 @@ matmul_c17_avx2 (gfc_array_c17 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
-	  dest_y = &dest[y*rystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	  dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	  for (x = 0; x < xcount; x++)
 	    {
-	      abase_x = &abase[x*axstride];
+	      abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 	      s = (GFC_COMPLEX_17) 0;
 	      for (n = 0; n < count; n++)
-		s += abase_x[n*aystride] * bbase_y[n*bxstride];
-	      dest_y[x*rxstride] = s;
+		s += ARRAY_ELEM_AT_OFFSET (abase_x, n * aystride_bytes)
+		     * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
+	      ARRAY_ELEM_AT_OFFSET (dest_y, x * rxstride_bytes) = s;
 	    }
 	}
     }
@@ -1254,7 +1264,8 @@ matmul_c17_avx512f (gfc_array_c17 * const restrict retarray,
 
   index_type rxstride, rystride, axstride, aystride, bxstride, bystride;
   index_type x, y, n, count, xcount, ycount;
-  index_type aystride_bytes, bystride_bytes, rystride_bytes;
+  index_type axstride_bytes, aystride_bytes, bxstride_bytes, bystride_bytes,
+	     rxstride_bytes, rystride_bytes;
 
   assert (GFC_DESCRIPTOR_RANK (a) == 2
           || GFC_DESCRIPTOR_RANK (b) == 2);
@@ -1343,12 +1354,13 @@ matmul_c17_avx512f (gfc_array_c17 * const restrict retarray,
 	 either as a row or a column matrix. We want both cases to
 	 work. */
       rxstride = rystride = GFC_DESCRIPTOR_STRIDE(retarray,0);
-      rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
+      rxstride_bytes = rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
     }
   else
     {
       rxstride = GFC_DESCRIPTOR_STRIDE(retarray,0);
       rystride = GFC_DESCRIPTOR_STRIDE(retarray,1);
+      rxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
       rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,1);
     }
 
@@ -1357,6 +1369,7 @@ matmul_c17_avx512f (gfc_array_c17 * const restrict retarray,
       /* Treat it as a a row matrix A[1,count]. */
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = 1;
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = sizeof (GFC_COMPLEX_17);
 
       xcount = 1;
@@ -1366,6 +1379,7 @@ matmul_c17_avx512f (gfc_array_c17 * const restrict retarray,
     {
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = GFC_DESCRIPTOR_STRIDE(a,1);
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,1);
 
       count = GFC_DESCRIPTOR_EXTENT(a,1);
@@ -1384,17 +1398,20 @@ matmul_c17_avx512f (gfc_array_c17 * const restrict retarray,
     {
       /* Treat it as a column matrix B[count,1] */
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
 
       /* bystride should never be used for 1-dimensional b.
          The value is only used for calculation of the
          memory by the buffer.  */
       bystride = 256;
+      bystride_bytes = 99999999;
       ycount = 1;
     }
   else
     {
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
       bystride = GFC_DESCRIPTOR_STRIDE(b,1);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
       bystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,1);
       ycount = GFC_DESCRIPTOR_EXTENT(b,1);
     }
@@ -1454,12 +1471,11 @@ matmul_c17_avx512f (gfc_array_c17 * const restrict retarray,
 
 	 from netlib.org, translated to C, and modified for matmul.m4.  */
 
-      const GFC_COMPLEX_17 *a, *b;
       GFC_COMPLEX_17 *c;
       const index_type m = xcount, n = ycount, k = count;
 
       /* System generated locals */
-      index_type a_dim1, b_dim1, c_dim1,
+      index_type a_dim1, b_dim1,
 		 i1, i2, i3, i4, i5, i6;
 
       /* Local variables */
@@ -1469,25 +1485,22 @@ matmul_c17_avx512f (gfc_array_c17 * const restrict retarray,
       index_type isec, jsec, lsec, uisec, ujsec, ulsec;
       GFC_COMPLEX_17 *t1;
 
-      a = abase;
-      b = bbase;
       c = retarray->base_addr;
 
       /* Parameter adjustments */
-      c_dim1 = rystride;
       a_dim1 = aystride;
       b_dim1 = bystride;
 
 #define A_ARRAY_ELEM(i,j) \
-    a[(i) + (j) * a_dim1]
+    (ARRAY_ELEM_AT_OFFSET (abase, (i) * sizeof (GFC_COMPLEX_17) + (j) * aystride_bytes))
 
 #define B_ARRAY_ELEM(i,j) \
-    b[(i) + (j) * b_dim1]
+    (ARRAY_ELEM_AT_OFFSET (bbase, (i) * sizeof (GFC_COMPLEX_17) + (j) * bystride_bytes))
 
 #define C_ARRAY_ELEM(i,j) \
-    c[(i) + (j) * c_dim1]
+    (ARRAY_ELEM_AT_OFFSET (c, (i) * sizeof (GFC_COMPLEX_17) + (j) * rystride_bytes))
 
-      /* Empty c first.  */
+      /* Empty result first.  */
       for (j=0; j<n; j++)
 	for (i=0; i<m; i++)
 	  C_ARRAY_ELEM (i, j) = (GFC_COMPLEX_17)0;
@@ -1735,11 +1748,11 @@ matmul_c17_avx512f (gfc_array_c17 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
-	      dest_y = &dest[y*rystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	      dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	      for (x = 0; x < xcount; x++)
 		{
-		  abase_x = &abase[x*axstride];
+		  abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 		  s = (GFC_COMPLEX_17) 0;
 		  for (n = 0; n < count; n++)
 		    s += abase_x[n] * bbase_y[n];
@@ -1754,11 +1767,11 @@ matmul_c17_avx512f (gfc_array_c17 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	      s = (GFC_COMPLEX_17) 0;
 	      for (n = 0; n < count; n++)
 		s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n];
-	      dest[y*rystride] = s;
+	      ARRAY_ELEM_AT_OFFSET (dest, y * rystride_bytes) = s;
 	    }
 	}
     }
@@ -1769,10 +1782,11 @@ matmul_c17_avx512f (gfc_array_c17 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	  s = (GFC_COMPLEX_17) 0;
 	  for (n = 0; n < count; n++)
-	    s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n*bxstride];
+	    s += GFC_DESCRIPTOR1_ELEM (a, n)
+	         * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
 	  GFC_DESCRIPTOR1_ELEM (retarray, y) = s;
 	}
     }
@@ -1799,15 +1813,16 @@ matmul_c17_avx512f (gfc_array_c17 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
-	  dest_y = &dest[y*rystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	  dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	  for (x = 0; x < xcount; x++)
 	    {
-	      abase_x = &abase[x*axstride];
+	      abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 	      s = (GFC_COMPLEX_17) 0;
 	      for (n = 0; n < count; n++)
-		s += abase_x[n*aystride] * bbase_y[n*bxstride];
-	      dest_y[x*rxstride] = s;
+		s += ARRAY_ELEM_AT_OFFSET (abase_x, n * aystride_bytes)
+		     * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
+	      ARRAY_ELEM_AT_OFFSET (dest_y, x * rxstride_bytes) = s;
 	    }
 	}
     }
@@ -1848,7 +1863,8 @@ matmul_c17_vanilla (gfc_array_c17 * const restrict retarray,
 
   index_type rxstride, rystride, axstride, aystride, bxstride, bystride;
   index_type x, y, n, count, xcount, ycount;
-  index_type aystride_bytes, bystride_bytes, rystride_bytes;
+  index_type axstride_bytes, aystride_bytes, bxstride_bytes, bystride_bytes,
+	     rxstride_bytes, rystride_bytes;
 
   assert (GFC_DESCRIPTOR_RANK (a) == 2
           || GFC_DESCRIPTOR_RANK (b) == 2);
@@ -1937,12 +1953,13 @@ matmul_c17_vanilla (gfc_array_c17 * const restrict retarray,
 	 either as a row or a column matrix. We want both cases to
 	 work. */
       rxstride = rystride = GFC_DESCRIPTOR_STRIDE(retarray,0);
-      rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
+      rxstride_bytes = rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
     }
   else
     {
       rxstride = GFC_DESCRIPTOR_STRIDE(retarray,0);
       rystride = GFC_DESCRIPTOR_STRIDE(retarray,1);
+      rxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
       rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,1);
     }
 
@@ -1951,6 +1968,7 @@ matmul_c17_vanilla (gfc_array_c17 * const restrict retarray,
       /* Treat it as a a row matrix A[1,count]. */
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = 1;
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = sizeof (GFC_COMPLEX_17);
 
       xcount = 1;
@@ -1960,6 +1978,7 @@ matmul_c17_vanilla (gfc_array_c17 * const restrict retarray,
     {
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = GFC_DESCRIPTOR_STRIDE(a,1);
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,1);
 
       count = GFC_DESCRIPTOR_EXTENT(a,1);
@@ -1978,17 +1997,20 @@ matmul_c17_vanilla (gfc_array_c17 * const restrict retarray,
     {
       /* Treat it as a column matrix B[count,1] */
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
 
       /* bystride should never be used for 1-dimensional b.
          The value is only used for calculation of the
          memory by the buffer.  */
       bystride = 256;
+      bystride_bytes = 99999999;
       ycount = 1;
     }
   else
     {
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
       bystride = GFC_DESCRIPTOR_STRIDE(b,1);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
       bystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,1);
       ycount = GFC_DESCRIPTOR_EXTENT(b,1);
     }
@@ -2048,12 +2070,11 @@ matmul_c17_vanilla (gfc_array_c17 * const restrict retarray,
 
 	 from netlib.org, translated to C, and modified for matmul.m4.  */
 
-      const GFC_COMPLEX_17 *a, *b;
       GFC_COMPLEX_17 *c;
       const index_type m = xcount, n = ycount, k = count;
 
       /* System generated locals */
-      index_type a_dim1, b_dim1, c_dim1,
+      index_type a_dim1, b_dim1,
 		 i1, i2, i3, i4, i5, i6;
 
       /* Local variables */
@@ -2063,25 +2084,22 @@ matmul_c17_vanilla (gfc_array_c17 * const restrict retarray,
       index_type isec, jsec, lsec, uisec, ujsec, ulsec;
       GFC_COMPLEX_17 *t1;
 
-      a = abase;
-      b = bbase;
       c = retarray->base_addr;
 
       /* Parameter adjustments */
-      c_dim1 = rystride;
       a_dim1 = aystride;
       b_dim1 = bystride;
 
 #define A_ARRAY_ELEM(i,j) \
-    a[(i) + (j) * a_dim1]
+    (ARRAY_ELEM_AT_OFFSET (abase, (i) * sizeof (GFC_COMPLEX_17) + (j) * aystride_bytes))
 
 #define B_ARRAY_ELEM(i,j) \
-    b[(i) + (j) * b_dim1]
+    (ARRAY_ELEM_AT_OFFSET (bbase, (i) * sizeof (GFC_COMPLEX_17) + (j) * bystride_bytes))
 
 #define C_ARRAY_ELEM(i,j) \
-    c[(i) + (j) * c_dim1]
+    (ARRAY_ELEM_AT_OFFSET (c, (i) * sizeof (GFC_COMPLEX_17) + (j) * rystride_bytes))
 
-      /* Empty c first.  */
+      /* Empty result first.  */
       for (j=0; j<n; j++)
 	for (i=0; i<m; i++)
 	  C_ARRAY_ELEM (i, j) = (GFC_COMPLEX_17)0;
@@ -2329,11 +2347,11 @@ matmul_c17_vanilla (gfc_array_c17 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
-	      dest_y = &dest[y*rystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	      dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	      for (x = 0; x < xcount; x++)
 		{
-		  abase_x = &abase[x*axstride];
+		  abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 		  s = (GFC_COMPLEX_17) 0;
 		  for (n = 0; n < count; n++)
 		    s += abase_x[n] * bbase_y[n];
@@ -2348,11 +2366,11 @@ matmul_c17_vanilla (gfc_array_c17 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	      s = (GFC_COMPLEX_17) 0;
 	      for (n = 0; n < count; n++)
 		s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n];
-	      dest[y*rystride] = s;
+	      ARRAY_ELEM_AT_OFFSET (dest, y * rystride_bytes) = s;
 	    }
 	}
     }
@@ -2363,10 +2381,11 @@ matmul_c17_vanilla (gfc_array_c17 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	  s = (GFC_COMPLEX_17) 0;
 	  for (n = 0; n < count; n++)
-	    s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n*bxstride];
+	    s += GFC_DESCRIPTOR1_ELEM (a, n)
+	         * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
 	  GFC_DESCRIPTOR1_ELEM (retarray, y) = s;
 	}
     }
@@ -2393,15 +2412,16 @@ matmul_c17_vanilla (gfc_array_c17 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
-	  dest_y = &dest[y*rystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	  dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	  for (x = 0; x < xcount; x++)
 	    {
-	      abase_x = &abase[x*axstride];
+	      abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 	      s = (GFC_COMPLEX_17) 0;
 	      for (n = 0; n < count; n++)
-		s += abase_x[n*aystride] * bbase_y[n*bxstride];
-	      dest_y[x*rxstride] = s;
+		s += ARRAY_ELEM_AT_OFFSET (abase_x, n * aystride_bytes)
+		     * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
+	      ARRAY_ELEM_AT_OFFSET (dest_y, x * rxstride_bytes) = s;
 	    }
 	}
     }
@@ -2501,7 +2521,8 @@ matmul_c17 (gfc_array_c17 * const restrict retarray,
 
   index_type rxstride, rystride, axstride, aystride, bxstride, bystride;
   index_type x, y, n, count, xcount, ycount;
-  index_type aystride_bytes, bystride_bytes, rystride_bytes;
+  index_type axstride_bytes, aystride_bytes, bxstride_bytes, bystride_bytes,
+	     rxstride_bytes, rystride_bytes;
 
   assert (GFC_DESCRIPTOR_RANK (a) == 2
           || GFC_DESCRIPTOR_RANK (b) == 2);
@@ -2590,12 +2611,13 @@ matmul_c17 (gfc_array_c17 * const restrict retarray,
 	 either as a row or a column matrix. We want both cases to
 	 work. */
       rxstride = rystride = GFC_DESCRIPTOR_STRIDE(retarray,0);
-      rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
+      rxstride_bytes = rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
     }
   else
     {
       rxstride = GFC_DESCRIPTOR_STRIDE(retarray,0);
       rystride = GFC_DESCRIPTOR_STRIDE(retarray,1);
+      rxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
       rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,1);
     }
 
@@ -2604,6 +2626,7 @@ matmul_c17 (gfc_array_c17 * const restrict retarray,
       /* Treat it as a a row matrix A[1,count]. */
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = 1;
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = sizeof (GFC_COMPLEX_17);
 
       xcount = 1;
@@ -2613,6 +2636,7 @@ matmul_c17 (gfc_array_c17 * const restrict retarray,
     {
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = GFC_DESCRIPTOR_STRIDE(a,1);
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,1);
 
       count = GFC_DESCRIPTOR_EXTENT(a,1);
@@ -2631,17 +2655,20 @@ matmul_c17 (gfc_array_c17 * const restrict retarray,
     {
       /* Treat it as a column matrix B[count,1] */
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
 
       /* bystride should never be used for 1-dimensional b.
          The value is only used for calculation of the
          memory by the buffer.  */
       bystride = 256;
+      bystride_bytes = 99999999;
       ycount = 1;
     }
   else
     {
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
       bystride = GFC_DESCRIPTOR_STRIDE(b,1);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
       bystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,1);
       ycount = GFC_DESCRIPTOR_EXTENT(b,1);
     }
@@ -2701,12 +2728,11 @@ matmul_c17 (gfc_array_c17 * const restrict retarray,
 
 	 from netlib.org, translated to C, and modified for matmul.m4.  */
 
-      const GFC_COMPLEX_17 *a, *b;
       GFC_COMPLEX_17 *c;
       const index_type m = xcount, n = ycount, k = count;
 
       /* System generated locals */
-      index_type a_dim1, b_dim1, c_dim1,
+      index_type a_dim1, b_dim1,
 		 i1, i2, i3, i4, i5, i6;
 
       /* Local variables */
@@ -2716,25 +2742,22 @@ matmul_c17 (gfc_array_c17 * const restrict retarray,
       index_type isec, jsec, lsec, uisec, ujsec, ulsec;
       GFC_COMPLEX_17 *t1;
 
-      a = abase;
-      b = bbase;
       c = retarray->base_addr;
 
       /* Parameter adjustments */
-      c_dim1 = rystride;
       a_dim1 = aystride;
       b_dim1 = bystride;
 
 #define A_ARRAY_ELEM(i,j) \
-    a[(i) + (j) * a_dim1]
+    (ARRAY_ELEM_AT_OFFSET (abase, (i) * sizeof (GFC_COMPLEX_17) + (j) * aystride_bytes))
 
 #define B_ARRAY_ELEM(i,j) \
-    b[(i) + (j) * b_dim1]
+    (ARRAY_ELEM_AT_OFFSET (bbase, (i) * sizeof (GFC_COMPLEX_17) + (j) * bystride_bytes))
 
 #define C_ARRAY_ELEM(i,j) \
-    c[(i) + (j) * c_dim1]
+    (ARRAY_ELEM_AT_OFFSET (c, (i) * sizeof (GFC_COMPLEX_17) + (j) * rystride_bytes))
 
-      /* Empty c first.  */
+      /* Empty result first.  */
       for (j=0; j<n; j++)
 	for (i=0; i<m; i++)
 	  C_ARRAY_ELEM (i, j) = (GFC_COMPLEX_17)0;
@@ -2982,11 +3005,11 @@ matmul_c17 (gfc_array_c17 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
-	      dest_y = &dest[y*rystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	      dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	      for (x = 0; x < xcount; x++)
 		{
-		  abase_x = &abase[x*axstride];
+		  abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 		  s = (GFC_COMPLEX_17) 0;
 		  for (n = 0; n < count; n++)
 		    s += abase_x[n] * bbase_y[n];
@@ -3001,11 +3024,11 @@ matmul_c17 (gfc_array_c17 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	      s = (GFC_COMPLEX_17) 0;
 	      for (n = 0; n < count; n++)
 		s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n];
-	      dest[y*rystride] = s;
+	      ARRAY_ELEM_AT_OFFSET (dest, y * rystride_bytes) = s;
 	    }
 	}
     }
@@ -3016,10 +3039,11 @@ matmul_c17 (gfc_array_c17 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	  s = (GFC_COMPLEX_17) 0;
 	  for (n = 0; n < count; n++)
-	    s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n*bxstride];
+	    s += GFC_DESCRIPTOR1_ELEM (a, n)
+	         * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
 	  GFC_DESCRIPTOR1_ELEM (retarray, y) = s;
 	}
     }
@@ -3046,15 +3070,16 @@ matmul_c17 (gfc_array_c17 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
-	  dest_y = &dest[y*rystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	  dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	  for (x = 0; x < xcount; x++)
 	    {
-	      abase_x = &abase[x*axstride];
+	      abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 	      s = (GFC_COMPLEX_17) 0;
 	      for (n = 0; n < count; n++)
-		s += abase_x[n*aystride] * bbase_y[n*bxstride];
-	      dest_y[x*rxstride] = s;
+		s += ARRAY_ELEM_AT_OFFSET (abase_x, n * aystride_bytes)
+		     * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
+	      ARRAY_ELEM_AT_OFFSET (dest_y, x * rxstride_bytes) = s;
 	    }
 	}
     }
diff --git a/libgfortran/generated/matmul_c4.c b/libgfortran/generated/matmul_c4.c
index a2db5a319832..afb9f4f1473d 100644
--- a/libgfortran/generated/matmul_c4.c
+++ b/libgfortran/generated/matmul_c4.c
@@ -94,7 +94,8 @@ matmul_c4_avx (gfc_array_c4 * const restrict retarray,
 
   index_type rxstride, rystride, axstride, aystride, bxstride, bystride;
   index_type x, y, n, count, xcount, ycount;
-  index_type aystride_bytes, bystride_bytes, rystride_bytes;
+  index_type axstride_bytes, aystride_bytes, bxstride_bytes, bystride_bytes,
+	     rxstride_bytes, rystride_bytes;
 
   assert (GFC_DESCRIPTOR_RANK (a) == 2
           || GFC_DESCRIPTOR_RANK (b) == 2);
@@ -183,12 +184,13 @@ matmul_c4_avx (gfc_array_c4 * const restrict retarray,
 	 either as a row or a column matrix. We want both cases to
 	 work. */
       rxstride = rystride = GFC_DESCRIPTOR_STRIDE(retarray,0);
-      rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
+      rxstride_bytes = rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
     }
   else
     {
       rxstride = GFC_DESCRIPTOR_STRIDE(retarray,0);
       rystride = GFC_DESCRIPTOR_STRIDE(retarray,1);
+      rxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
       rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,1);
     }
 
@@ -197,6 +199,7 @@ matmul_c4_avx (gfc_array_c4 * const restrict retarray,
       /* Treat it as a a row matrix A[1,count]. */
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = 1;
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = sizeof (GFC_COMPLEX_4);
 
       xcount = 1;
@@ -206,6 +209,7 @@ matmul_c4_avx (gfc_array_c4 * const restrict retarray,
     {
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = GFC_DESCRIPTOR_STRIDE(a,1);
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,1);
 
       count = GFC_DESCRIPTOR_EXTENT(a,1);
@@ -224,17 +228,20 @@ matmul_c4_avx (gfc_array_c4 * const restrict retarray,
     {
       /* Treat it as a column matrix B[count,1] */
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
 
       /* bystride should never be used for 1-dimensional b.
          The value is only used for calculation of the
          memory by the buffer.  */
       bystride = 256;
+      bystride_bytes = 99999999;
       ycount = 1;
     }
   else
     {
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
       bystride = GFC_DESCRIPTOR_STRIDE(b,1);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
       bystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,1);
       ycount = GFC_DESCRIPTOR_EXTENT(b,1);
     }
@@ -294,12 +301,11 @@ matmul_c4_avx (gfc_array_c4 * const restrict retarray,
 
 	 from netlib.org, translated to C, and modified for matmul.m4.  */
 
-      const GFC_COMPLEX_4 *a, *b;
       GFC_COMPLEX_4 *c;
       const index_type m = xcount, n = ycount, k = count;
 
       /* System generated locals */
-      index_type a_dim1, b_dim1, c_dim1,
+      index_type a_dim1, b_dim1,
 		 i1, i2, i3, i4, i5, i6;
 
       /* Local variables */
@@ -309,25 +315,22 @@ matmul_c4_avx (gfc_array_c4 * const restrict retarray,
       index_type isec, jsec, lsec, uisec, ujsec, ulsec;
       GFC_COMPLEX_4 *t1;
 
-      a = abase;
-      b = bbase;
       c = retarray->base_addr;
 
       /* Parameter adjustments */
-      c_dim1 = rystride;
       a_dim1 = aystride;
       b_dim1 = bystride;
 
 #define A_ARRAY_ELEM(i,j) \
-    a[(i) + (j) * a_dim1]
+    (ARRAY_ELEM_AT_OFFSET (abase, (i) * sizeof (GFC_COMPLEX_4) + (j) * aystride_bytes))
 
 #define B_ARRAY_ELEM(i,j) \
-    b[(i) + (j) * b_dim1]
+    (ARRAY_ELEM_AT_OFFSET (bbase, (i) * sizeof (GFC_COMPLEX_4) + (j) * bystride_bytes))
 
 #define C_ARRAY_ELEM(i,j) \
-    c[(i) + (j) * c_dim1]
+    (ARRAY_ELEM_AT_OFFSET (c, (i) * sizeof (GFC_COMPLEX_4) + (j) * rystride_bytes))
 
-      /* Empty c first.  */
+      /* Empty result first.  */
       for (j=0; j<n; j++)
 	for (i=0; i<m; i++)
 	  C_ARRAY_ELEM (i, j) = (GFC_COMPLEX_4)0;
@@ -575,11 +578,11 @@ matmul_c4_avx (gfc_array_c4 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
-	      dest_y = &dest[y*rystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	      dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	      for (x = 0; x < xcount; x++)
 		{
-		  abase_x = &abase[x*axstride];
+		  abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 		  s = (GFC_COMPLEX_4) 0;
 		  for (n = 0; n < count; n++)
 		    s += abase_x[n] * bbase_y[n];
@@ -594,11 +597,11 @@ matmul_c4_avx (gfc_array_c4 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	      s = (GFC_COMPLEX_4) 0;
 	      for (n = 0; n < count; n++)
 		s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n];
-	      dest[y*rystride] = s;
+	      ARRAY_ELEM_AT_OFFSET (dest, y * rystride_bytes) = s;
 	    }
 	}
     }
@@ -609,10 +612,11 @@ matmul_c4_avx (gfc_array_c4 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	  s = (GFC_COMPLEX_4) 0;
 	  for (n = 0; n < count; n++)
-	    s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n*bxstride];
+	    s += GFC_DESCRIPTOR1_ELEM (a, n)
+	         * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
 	  GFC_DESCRIPTOR1_ELEM (retarray, y) = s;
 	}
     }
@@ -639,15 +643,16 @@ matmul_c4_avx (gfc_array_c4 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
-	  dest_y = &dest[y*rystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	  dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	  for (x = 0; x < xcount; x++)
 	    {
-	      abase_x = &abase[x*axstride];
+	      abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 	      s = (GFC_COMPLEX_4) 0;
 	      for (n = 0; n < count; n++)
-		s += abase_x[n*aystride] * bbase_y[n*bxstride];
-	      dest_y[x*rxstride] = s;
+		s += ARRAY_ELEM_AT_OFFSET (abase_x, n * aystride_bytes)
+		     * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
+	      ARRAY_ELEM_AT_OFFSET (dest_y, x * rxstride_bytes) = s;
 	    }
 	}
     }
@@ -674,7 +679,8 @@ matmul_c4_avx2 (gfc_array_c4 * const restrict retarray,
 
   index_type rxstride, rystride, axstride, aystride, bxstride, bystride;
   index_type x, y, n, count, xcount, ycount;
-  index_type aystride_bytes, bystride_bytes, rystride_bytes;
+  index_type axstride_bytes, aystride_bytes, bxstride_bytes, bystride_bytes,
+	     rxstride_bytes, rystride_bytes;
 
   assert (GFC_DESCRIPTOR_RANK (a) == 2
           || GFC_DESCRIPTOR_RANK (b) == 2);
@@ -763,12 +769,13 @@ matmul_c4_avx2 (gfc_array_c4 * const restrict retarray,
 	 either as a row or a column matrix. We want both cases to
 	 work. */
       rxstride = rystride = GFC_DESCRIPTOR_STRIDE(retarray,0);
-      rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
+      rxstride_bytes = rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
     }
   else
     {
       rxstride = GFC_DESCRIPTOR_STRIDE(retarray,0);
       rystride = GFC_DESCRIPTOR_STRIDE(retarray,1);
+      rxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
       rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,1);
     }
 
@@ -777,6 +784,7 @@ matmul_c4_avx2 (gfc_array_c4 * const restrict retarray,
       /* Treat it as a a row matrix A[1,count]. */
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = 1;
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = sizeof (GFC_COMPLEX_4);
 
       xcount = 1;
@@ -786,6 +794,7 @@ matmul_c4_avx2 (gfc_array_c4 * const restrict retarray,
     {
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = GFC_DESCRIPTOR_STRIDE(a,1);
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,1);
 
       count = GFC_DESCRIPTOR_EXTENT(a,1);
@@ -804,17 +813,20 @@ matmul_c4_avx2 (gfc_array_c4 * const restrict retarray,
     {
       /* Treat it as a column matrix B[count,1] */
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
 
       /* bystride should never be used for 1-dimensional b.
          The value is only used for calculation of the
          memory by the buffer.  */
       bystride = 256;
+      bystride_bytes = 99999999;
       ycount = 1;
     }
   else
     {
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
       bystride = GFC_DESCRIPTOR_STRIDE(b,1);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
       bystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,1);
       ycount = GFC_DESCRIPTOR_EXTENT(b,1);
     }
@@ -874,12 +886,11 @@ matmul_c4_avx2 (gfc_array_c4 * const restrict retarray,
 
 	 from netlib.org, translated to C, and modified for matmul.m4.  */
 
-      const GFC_COMPLEX_4 *a, *b;
       GFC_COMPLEX_4 *c;
       const index_type m = xcount, n = ycount, k = count;
 
       /* System generated locals */
-      index_type a_dim1, b_dim1, c_dim1,
+      index_type a_dim1, b_dim1,
 		 i1, i2, i3, i4, i5, i6;
 
       /* Local variables */
@@ -889,25 +900,22 @@ matmul_c4_avx2 (gfc_array_c4 * const restrict retarray,
       index_type isec, jsec, lsec, uisec, ujsec, ulsec;
       GFC_COMPLEX_4 *t1;
 
-      a = abase;
-      b = bbase;
       c = retarray->base_addr;
 
       /* Parameter adjustments */
-      c_dim1 = rystride;
       a_dim1 = aystride;
       b_dim1 = bystride;
 
 #define A_ARRAY_ELEM(i,j) \
-    a[(i) + (j) * a_dim1]
+    (ARRAY_ELEM_AT_OFFSET (abase, (i) * sizeof (GFC_COMPLEX_4) + (j) * aystride_bytes))
 
 #define B_ARRAY_ELEM(i,j) \
-    b[(i) + (j) * b_dim1]
+    (ARRAY_ELEM_AT_OFFSET (bbase, (i) * sizeof (GFC_COMPLEX_4) + (j) * bystride_bytes))
 
 #define C_ARRAY_ELEM(i,j) \
-    c[(i) + (j) * c_dim1]
+    (ARRAY_ELEM_AT_OFFSET (c, (i) * sizeof (GFC_COMPLEX_4) + (j) * rystride_bytes))
 
-      /* Empty c first.  */
+      /* Empty result first.  */
       for (j=0; j<n; j++)
 	for (i=0; i<m; i++)
 	  C_ARRAY_ELEM (i, j) = (GFC_COMPLEX_4)0;
@@ -1155,11 +1163,11 @@ matmul_c4_avx2 (gfc_array_c4 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
-	      dest_y = &dest[y*rystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	      dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	      for (x = 0; x < xcount; x++)
 		{
-		  abase_x = &abase[x*axstride];
+		  abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 		  s = (GFC_COMPLEX_4) 0;
 		  for (n = 0; n < count; n++)
 		    s += abase_x[n] * bbase_y[n];
@@ -1174,11 +1182,11 @@ matmul_c4_avx2 (gfc_array_c4 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	      s = (GFC_COMPLEX_4) 0;
 	      for (n = 0; n < count; n++)
 		s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n];
-	      dest[y*rystride] = s;
+	      ARRAY_ELEM_AT_OFFSET (dest, y * rystride_bytes) = s;
 	    }
 	}
     }
@@ -1189,10 +1197,11 @@ matmul_c4_avx2 (gfc_array_c4 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	  s = (GFC_COMPLEX_4) 0;
 	  for (n = 0; n < count; n++)
-	    s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n*bxstride];
+	    s += GFC_DESCRIPTOR1_ELEM (a, n)
+	         * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
 	  GFC_DESCRIPTOR1_ELEM (retarray, y) = s;
 	}
     }
@@ -1219,15 +1228,16 @@ matmul_c4_avx2 (gfc_array_c4 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
-	  dest_y = &dest[y*rystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	  dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	  for (x = 0; x < xcount; x++)
 	    {
-	      abase_x = &abase[x*axstride];
+	      abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 	      s = (GFC_COMPLEX_4) 0;
 	      for (n = 0; n < count; n++)
-		s += abase_x[n*aystride] * bbase_y[n*bxstride];
-	      dest_y[x*rxstride] = s;
+		s += ARRAY_ELEM_AT_OFFSET (abase_x, n * aystride_bytes)
+		     * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
+	      ARRAY_ELEM_AT_OFFSET (dest_y, x * rxstride_bytes) = s;
 	    }
 	}
     }
@@ -1254,7 +1264,8 @@ matmul_c4_avx512f (gfc_array_c4 * const restrict retarray,
 
   index_type rxstride, rystride, axstride, aystride, bxstride, bystride;
   index_type x, y, n, count, xcount, ycount;
-  index_type aystride_bytes, bystride_bytes, rystride_bytes;
+  index_type axstride_bytes, aystride_bytes, bxstride_bytes, bystride_bytes,
+	     rxstride_bytes, rystride_bytes;
 
   assert (GFC_DESCRIPTOR_RANK (a) == 2
           || GFC_DESCRIPTOR_RANK (b) == 2);
@@ -1343,12 +1354,13 @@ matmul_c4_avx512f (gfc_array_c4 * const restrict retarray,
 	 either as a row or a column matrix. We want both cases to
 	 work. */
       rxstride = rystride = GFC_DESCRIPTOR_STRIDE(retarray,0);
-      rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
+      rxstride_bytes = rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
     }
   else
     {
       rxstride = GFC_DESCRIPTOR_STRIDE(retarray,0);
       rystride = GFC_DESCRIPTOR_STRIDE(retarray,1);
+      rxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
       rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,1);
     }
 
@@ -1357,6 +1369,7 @@ matmul_c4_avx512f (gfc_array_c4 * const restrict retarray,
       /* Treat it as a a row matrix A[1,count]. */
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = 1;
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = sizeof (GFC_COMPLEX_4);
 
       xcount = 1;
@@ -1366,6 +1379,7 @@ matmul_c4_avx512f (gfc_array_c4 * const restrict retarray,
     {
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = GFC_DESCRIPTOR_STRIDE(a,1);
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,1);
 
       count = GFC_DESCRIPTOR_EXTENT(a,1);
@@ -1384,17 +1398,20 @@ matmul_c4_avx512f (gfc_array_c4 * const restrict retarray,
     {
       /* Treat it as a column matrix B[count,1] */
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
 
       /* bystride should never be used for 1-dimensional b.
          The value is only used for calculation of the
          memory by the buffer.  */
       bystride = 256;
+      bystride_bytes = 99999999;
       ycount = 1;
     }
   else
     {
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
       bystride = GFC_DESCRIPTOR_STRIDE(b,1);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
       bystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,1);
       ycount = GFC_DESCRIPTOR_EXTENT(b,1);
     }
@@ -1454,12 +1471,11 @@ matmul_c4_avx512f (gfc_array_c4 * const restrict retarray,
 
 	 from netlib.org, translated to C, and modified for matmul.m4.  */
 
-      const GFC_COMPLEX_4 *a, *b;
       GFC_COMPLEX_4 *c;
       const index_type m = xcount, n = ycount, k = count;
 
       /* System generated locals */
-      index_type a_dim1, b_dim1, c_dim1,
+      index_type a_dim1, b_dim1,
 		 i1, i2, i3, i4, i5, i6;
 
       /* Local variables */
@@ -1469,25 +1485,22 @@ matmul_c4_avx512f (gfc_array_c4 * const restrict retarray,
       index_type isec, jsec, lsec, uisec, ujsec, ulsec;
       GFC_COMPLEX_4 *t1;
 
-      a = abase;
-      b = bbase;
       c = retarray->base_addr;
 
       /* Parameter adjustments */
-      c_dim1 = rystride;
       a_dim1 = aystride;
       b_dim1 = bystride;
 
 #define A_ARRAY_ELEM(i,j) \
-    a[(i) + (j) * a_dim1]
+    (ARRAY_ELEM_AT_OFFSET (abase, (i) * sizeof (GFC_COMPLEX_4) + (j) * aystride_bytes))
 
 #define B_ARRAY_ELEM(i,j) \
-    b[(i) + (j) * b_dim1]
+    (ARRAY_ELEM_AT_OFFSET (bbase, (i) * sizeof (GFC_COMPLEX_4) + (j) * bystride_bytes))
 
 #define C_ARRAY_ELEM(i,j) \
-    c[(i) + (j) * c_dim1]
+    (ARRAY_ELEM_AT_OFFSET (c, (i) * sizeof (GFC_COMPLEX_4) + (j) * rystride_bytes))
 
-      /* Empty c first.  */
+      /* Empty result first.  */
       for (j=0; j<n; j++)
 	for (i=0; i<m; i++)
 	  C_ARRAY_ELEM (i, j) = (GFC_COMPLEX_4)0;
@@ -1735,11 +1748,11 @@ matmul_c4_avx512f (gfc_array_c4 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
-	      dest_y = &dest[y*rystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	      dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	      for (x = 0; x < xcount; x++)
 		{
-		  abase_x = &abase[x*axstride];
+		  abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 		  s = (GFC_COMPLEX_4) 0;
 		  for (n = 0; n < count; n++)
 		    s += abase_x[n] * bbase_y[n];
@@ -1754,11 +1767,11 @@ matmul_c4_avx512f (gfc_array_c4 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	      s = (GFC_COMPLEX_4) 0;
 	      for (n = 0; n < count; n++)
 		s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n];
-	      dest[y*rystride] = s;
+	      ARRAY_ELEM_AT_OFFSET (dest, y * rystride_bytes) = s;
 	    }
 	}
     }
@@ -1769,10 +1782,11 @@ matmul_c4_avx512f (gfc_array_c4 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	  s = (GFC_COMPLEX_4) 0;
 	  for (n = 0; n < count; n++)
-	    s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n*bxstride];
+	    s += GFC_DESCRIPTOR1_ELEM (a, n)
+	         * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
 	  GFC_DESCRIPTOR1_ELEM (retarray, y) = s;
 	}
     }
@@ -1799,15 +1813,16 @@ matmul_c4_avx512f (gfc_array_c4 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
-	  dest_y = &dest[y*rystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	  dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	  for (x = 0; x < xcount; x++)
 	    {
-	      abase_x = &abase[x*axstride];
+	      abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 	      s = (GFC_COMPLEX_4) 0;
 	      for (n = 0; n < count; n++)
-		s += abase_x[n*aystride] * bbase_y[n*bxstride];
-	      dest_y[x*rxstride] = s;
+		s += ARRAY_ELEM_AT_OFFSET (abase_x, n * aystride_bytes)
+		     * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
+	      ARRAY_ELEM_AT_OFFSET (dest_y, x * rxstride_bytes) = s;
 	    }
 	}
     }
@@ -1848,7 +1863,8 @@ matmul_c4_vanilla (gfc_array_c4 * const restrict retarray,
 
   index_type rxstride, rystride, axstride, aystride, bxstride, bystride;
   index_type x, y, n, count, xcount, ycount;
-  index_type aystride_bytes, bystride_bytes, rystride_bytes;
+  index_type axstride_bytes, aystride_bytes, bxstride_bytes, bystride_bytes,
+	     rxstride_bytes, rystride_bytes;
 
   assert (GFC_DESCRIPTOR_RANK (a) == 2
           || GFC_DESCRIPTOR_RANK (b) == 2);
@@ -1937,12 +1953,13 @@ matmul_c4_vanilla (gfc_array_c4 * const restrict retarray,
 	 either as a row or a column matrix. We want both cases to
 	 work. */
       rxstride = rystride = GFC_DESCRIPTOR_STRIDE(retarray,0);
-      rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
+      rxstride_bytes = rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
     }
   else
     {
       rxstride = GFC_DESCRIPTOR_STRIDE(retarray,0);
       rystride = GFC_DESCRIPTOR_STRIDE(retarray,1);
+      rxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
       rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,1);
     }
 
@@ -1951,6 +1968,7 @@ matmul_c4_vanilla (gfc_array_c4 * const restrict retarray,
       /* Treat it as a a row matrix A[1,count]. */
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = 1;
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = sizeof (GFC_COMPLEX_4);
 
       xcount = 1;
@@ -1960,6 +1978,7 @@ matmul_c4_vanilla (gfc_array_c4 * const restrict retarray,
     {
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = GFC_DESCRIPTOR_STRIDE(a,1);
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,1);
 
       count = GFC_DESCRIPTOR_EXTENT(a,1);
@@ -1978,17 +1997,20 @@ matmul_c4_vanilla (gfc_array_c4 * const restrict retarray,
     {
       /* Treat it as a column matrix B[count,1] */
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
 
       /* bystride should never be used for 1-dimensional b.
          The value is only used for calculation of the
          memory by the buffer.  */
       bystride = 256;
+      bystride_bytes = 99999999;
       ycount = 1;
     }
   else
     {
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
       bystride = GFC_DESCRIPTOR_STRIDE(b,1);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
       bystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,1);
       ycount = GFC_DESCRIPTOR_EXTENT(b,1);
     }
@@ -2048,12 +2070,11 @@ matmul_c4_vanilla (gfc_array_c4 * const restrict retarray,
 
 	 from netlib.org, translated to C, and modified for matmul.m4.  */
 
-      const GFC_COMPLEX_4 *a, *b;
       GFC_COMPLEX_4 *c;
       const index_type m = xcount, n = ycount, k = count;
 
       /* System generated locals */
-      index_type a_dim1, b_dim1, c_dim1,
+      index_type a_dim1, b_dim1,
 		 i1, i2, i3, i4, i5, i6;
 
       /* Local variables */
@@ -2063,25 +2084,22 @@ matmul_c4_vanilla (gfc_array_c4 * const restrict retarray,
       index_type isec, jsec, lsec, uisec, ujsec, ulsec;
       GFC_COMPLEX_4 *t1;
 
-      a = abase;
-      b = bbase;
       c = retarray->base_addr;
 
       /* Parameter adjustments */
-      c_dim1 = rystride;
       a_dim1 = aystride;
       b_dim1 = bystride;
 
 #define A_ARRAY_ELEM(i,j) \
-    a[(i) + (j) * a_dim1]
+    (ARRAY_ELEM_AT_OFFSET (abase, (i) * sizeof (GFC_COMPLEX_4) + (j) * aystride_bytes))
 
 #define B_ARRAY_ELEM(i,j) \
-    b[(i) + (j) * b_dim1]
+    (ARRAY_ELEM_AT_OFFSET (bbase, (i) * sizeof (GFC_COMPLEX_4) + (j) * bystride_bytes))
 
 #define C_ARRAY_ELEM(i,j) \
-    c[(i) + (j) * c_dim1]
+    (ARRAY_ELEM_AT_OFFSET (c, (i) * sizeof (GFC_COMPLEX_4) + (j) * rystride_bytes))
 
-      /* Empty c first.  */
+      /* Empty result first.  */
       for (j=0; j<n; j++)
 	for (i=0; i<m; i++)
 	  C_ARRAY_ELEM (i, j) = (GFC_COMPLEX_4)0;
@@ -2329,11 +2347,11 @@ matmul_c4_vanilla (gfc_array_c4 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
-	      dest_y = &dest[y*rystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	      dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	      for (x = 0; x < xcount; x++)
 		{
-		  abase_x = &abase[x*axstride];
+		  abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 		  s = (GFC_COMPLEX_4) 0;
 		  for (n = 0; n < count; n++)
 		    s += abase_x[n] * bbase_y[n];
@@ -2348,11 +2366,11 @@ matmul_c4_vanilla (gfc_array_c4 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	      s = (GFC_COMPLEX_4) 0;
 	      for (n = 0; n < count; n++)
 		s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n];
-	      dest[y*rystride] = s;
+	      ARRAY_ELEM_AT_OFFSET (dest, y * rystride_bytes) = s;
 	    }
 	}
     }
@@ -2363,10 +2381,11 @@ matmul_c4_vanilla (gfc_array_c4 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	  s = (GFC_COMPLEX_4) 0;
 	  for (n = 0; n < count; n++)
-	    s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n*bxstride];
+	    s += GFC_DESCRIPTOR1_ELEM (a, n)
+	         * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
 	  GFC_DESCRIPTOR1_ELEM (retarray, y) = s;
 	}
     }
@@ -2393,15 +2412,16 @@ matmul_c4_vanilla (gfc_array_c4 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
-	  dest_y = &dest[y*rystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	  dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	  for (x = 0; x < xcount; x++)
 	    {
-	      abase_x = &abase[x*axstride];
+	      abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 	      s = (GFC_COMPLEX_4) 0;
 	      for (n = 0; n < count; n++)
-		s += abase_x[n*aystride] * bbase_y[n*bxstride];
-	      dest_y[x*rxstride] = s;
+		s += ARRAY_ELEM_AT_OFFSET (abase_x, n * aystride_bytes)
+		     * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
+	      ARRAY_ELEM_AT_OFFSET (dest_y, x * rxstride_bytes) = s;
 	    }
 	}
     }
@@ -2501,7 +2521,8 @@ matmul_c4 (gfc_array_c4 * const restrict retarray,
 
   index_type rxstride, rystride, axstride, aystride, bxstride, bystride;
   index_type x, y, n, count, xcount, ycount;
-  index_type aystride_bytes, bystride_bytes, rystride_bytes;
+  index_type axstride_bytes, aystride_bytes, bxstride_bytes, bystride_bytes,
+	     rxstride_bytes, rystride_bytes;
 
   assert (GFC_DESCRIPTOR_RANK (a) == 2
           || GFC_DESCRIPTOR_RANK (b) == 2);
@@ -2590,12 +2611,13 @@ matmul_c4 (gfc_array_c4 * const restrict retarray,
 	 either as a row or a column matrix. We want both cases to
 	 work. */
       rxstride = rystride = GFC_DESCRIPTOR_STRIDE(retarray,0);
-      rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
+      rxstride_bytes = rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
     }
   else
     {
       rxstride = GFC_DESCRIPTOR_STRIDE(retarray,0);
       rystride = GFC_DESCRIPTOR_STRIDE(retarray,1);
+      rxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
       rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,1);
     }
 
@@ -2604,6 +2626,7 @@ matmul_c4 (gfc_array_c4 * const restrict retarray,
       /* Treat it as a a row matrix A[1,count]. */
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = 1;
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = sizeof (GFC_COMPLEX_4);
 
       xcount = 1;
@@ -2613,6 +2636,7 @@ matmul_c4 (gfc_array_c4 * const restrict retarray,
     {
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = GFC_DESCRIPTOR_STRIDE(a,1);
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,1);
 
       count = GFC_DESCRIPTOR_EXTENT(a,1);
@@ -2631,17 +2655,20 @@ matmul_c4 (gfc_array_c4 * const restrict retarray,
     {
       /* Treat it as a column matrix B[count,1] */
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
 
       /* bystride should never be used for 1-dimensional b.
          The value is only used for calculation of the
          memory by the buffer.  */
       bystride = 256;
+      bystride_bytes = 99999999;
       ycount = 1;
     }
   else
     {
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
       bystride = GFC_DESCRIPTOR_STRIDE(b,1);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
       bystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,1);
       ycount = GFC_DESCRIPTOR_EXTENT(b,1);
     }
@@ -2701,12 +2728,11 @@ matmul_c4 (gfc_array_c4 * const restrict retarray,
 
 	 from netlib.org, translated to C, and modified for matmul.m4.  */
 
-      const GFC_COMPLEX_4 *a, *b;
       GFC_COMPLEX_4 *c;
       const index_type m = xcount, n = ycount, k = count;
 
       /* System generated locals */
-      index_type a_dim1, b_dim1, c_dim1,
+      index_type a_dim1, b_dim1,
 		 i1, i2, i3, i4, i5, i6;
 
       /* Local variables */
@@ -2716,25 +2742,22 @@ matmul_c4 (gfc_array_c4 * const restrict retarray,
       index_type isec, jsec, lsec, uisec, ujsec, ulsec;
       GFC_COMPLEX_4 *t1;
 
-      a = abase;
-      b = bbase;
       c = retarray->base_addr;
 
       /* Parameter adjustments */
-      c_dim1 = rystride;
       a_dim1 = aystride;
       b_dim1 = bystride;
 
 #define A_ARRAY_ELEM(i,j) \
-    a[(i) + (j) * a_dim1]
+    (ARRAY_ELEM_AT_OFFSET (abase, (i) * sizeof (GFC_COMPLEX_4) + (j) * aystride_bytes))
 
 #define B_ARRAY_ELEM(i,j) \
-    b[(i) + (j) * b_dim1]
+    (ARRAY_ELEM_AT_OFFSET (bbase, (i) * sizeof (GFC_COMPLEX_4) + (j) * bystride_bytes))
 
 #define C_ARRAY_ELEM(i,j) \
-    c[(i) + (j) * c_dim1]
+    (ARRAY_ELEM_AT_OFFSET (c, (i) * sizeof (GFC_COMPLEX_4) + (j) * rystride_bytes))
 
-      /* Empty c first.  */
+      /* Empty result first.  */
       for (j=0; j<n; j++)
 	for (i=0; i<m; i++)
 	  C_ARRAY_ELEM (i, j) = (GFC_COMPLEX_4)0;
@@ -2982,11 +3005,11 @@ matmul_c4 (gfc_array_c4 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
-	      dest_y = &dest[y*rystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	      dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	      for (x = 0; x < xcount; x++)
 		{
-		  abase_x = &abase[x*axstride];
+		  abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 		  s = (GFC_COMPLEX_4) 0;
 		  for (n = 0; n < count; n++)
 		    s += abase_x[n] * bbase_y[n];
@@ -3001,11 +3024,11 @@ matmul_c4 (gfc_array_c4 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	      s = (GFC_COMPLEX_4) 0;
 	      for (n = 0; n < count; n++)
 		s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n];
-	      dest[y*rystride] = s;
+	      ARRAY_ELEM_AT_OFFSET (dest, y * rystride_bytes) = s;
 	    }
 	}
     }
@@ -3016,10 +3039,11 @@ matmul_c4 (gfc_array_c4 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	  s = (GFC_COMPLEX_4) 0;
 	  for (n = 0; n < count; n++)
-	    s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n*bxstride];
+	    s += GFC_DESCRIPTOR1_ELEM (a, n)
+	         * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
 	  GFC_DESCRIPTOR1_ELEM (retarray, y) = s;
 	}
     }
@@ -3046,15 +3070,16 @@ matmul_c4 (gfc_array_c4 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
-	  dest_y = &dest[y*rystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	  dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	  for (x = 0; x < xcount; x++)
 	    {
-	      abase_x = &abase[x*axstride];
+	      abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 	      s = (GFC_COMPLEX_4) 0;
 	      for (n = 0; n < count; n++)
-		s += abase_x[n*aystride] * bbase_y[n*bxstride];
-	      dest_y[x*rxstride] = s;
+		s += ARRAY_ELEM_AT_OFFSET (abase_x, n * aystride_bytes)
+		     * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
+	      ARRAY_ELEM_AT_OFFSET (dest_y, x * rxstride_bytes) = s;
 	    }
 	}
     }
diff --git a/libgfortran/generated/matmul_c8.c b/libgfortran/generated/matmul_c8.c
index 5584c11f15d6..bc37144bfbbd 100644
--- a/libgfortran/generated/matmul_c8.c
+++ b/libgfortran/generated/matmul_c8.c
@@ -94,7 +94,8 @@ matmul_c8_avx (gfc_array_c8 * const restrict retarray,
 
   index_type rxstride, rystride, axstride, aystride, bxstride, bystride;
   index_type x, y, n, count, xcount, ycount;
-  index_type aystride_bytes, bystride_bytes, rystride_bytes;
+  index_type axstride_bytes, aystride_bytes, bxstride_bytes, bystride_bytes,
+	     rxstride_bytes, rystride_bytes;
 
   assert (GFC_DESCRIPTOR_RANK (a) == 2
           || GFC_DESCRIPTOR_RANK (b) == 2);
@@ -183,12 +184,13 @@ matmul_c8_avx (gfc_array_c8 * const restrict retarray,
 	 either as a row or a column matrix. We want both cases to
 	 work. */
       rxstride = rystride = GFC_DESCRIPTOR_STRIDE(retarray,0);
-      rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
+      rxstride_bytes = rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
     }
   else
     {
       rxstride = GFC_DESCRIPTOR_STRIDE(retarray,0);
       rystride = GFC_DESCRIPTOR_STRIDE(retarray,1);
+      rxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
       rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,1);
     }
 
@@ -197,6 +199,7 @@ matmul_c8_avx (gfc_array_c8 * const restrict retarray,
       /* Treat it as a a row matrix A[1,count]. */
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = 1;
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = sizeof (GFC_COMPLEX_8);
 
       xcount = 1;
@@ -206,6 +209,7 @@ matmul_c8_avx (gfc_array_c8 * const restrict retarray,
     {
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = GFC_DESCRIPTOR_STRIDE(a,1);
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,1);
 
       count = GFC_DESCRIPTOR_EXTENT(a,1);
@@ -224,17 +228,20 @@ matmul_c8_avx (gfc_array_c8 * const restrict retarray,
     {
       /* Treat it as a column matrix B[count,1] */
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
 
       /* bystride should never be used for 1-dimensional b.
          The value is only used for calculation of the
          memory by the buffer.  */
       bystride = 256;
+      bystride_bytes = 99999999;
       ycount = 1;
     }
   else
     {
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
       bystride = GFC_DESCRIPTOR_STRIDE(b,1);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
       bystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,1);
       ycount = GFC_DESCRIPTOR_EXTENT(b,1);
     }
@@ -294,12 +301,11 @@ matmul_c8_avx (gfc_array_c8 * const restrict retarray,
 
 	 from netlib.org, translated to C, and modified for matmul.m4.  */
 
-      const GFC_COMPLEX_8 *a, *b;
       GFC_COMPLEX_8 *c;
       const index_type m = xcount, n = ycount, k = count;
 
       /* System generated locals */
-      index_type a_dim1, b_dim1, c_dim1,
+      index_type a_dim1, b_dim1,
 		 i1, i2, i3, i4, i5, i6;
 
       /* Local variables */
@@ -309,25 +315,22 @@ matmul_c8_avx (gfc_array_c8 * const restrict retarray,
       index_type isec, jsec, lsec, uisec, ujsec, ulsec;
       GFC_COMPLEX_8 *t1;
 
-      a = abase;
-      b = bbase;
       c = retarray->base_addr;
 
       /* Parameter adjustments */
-      c_dim1 = rystride;
       a_dim1 = aystride;
       b_dim1 = bystride;
 
 #define A_ARRAY_ELEM(i,j) \
-    a[(i) + (j) * a_dim1]
+    (ARRAY_ELEM_AT_OFFSET (abase, (i) * sizeof (GFC_COMPLEX_8) + (j) * aystride_bytes))
 
 #define B_ARRAY_ELEM(i,j) \
-    b[(i) + (j) * b_dim1]
+    (ARRAY_ELEM_AT_OFFSET (bbase, (i) * sizeof (GFC_COMPLEX_8) + (j) * bystride_bytes))
 
 #define C_ARRAY_ELEM(i,j) \
-    c[(i) + (j) * c_dim1]
+    (ARRAY_ELEM_AT_OFFSET (c, (i) * sizeof (GFC_COMPLEX_8) + (j) * rystride_bytes))
 
-      /* Empty c first.  */
+      /* Empty result first.  */
       for (j=0; j<n; j++)
 	for (i=0; i<m; i++)
 	  C_ARRAY_ELEM (i, j) = (GFC_COMPLEX_8)0;
@@ -575,11 +578,11 @@ matmul_c8_avx (gfc_array_c8 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
-	      dest_y = &dest[y*rystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	      dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	      for (x = 0; x < xcount; x++)
 		{
-		  abase_x = &abase[x*axstride];
+		  abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 		  s = (GFC_COMPLEX_8) 0;
 		  for (n = 0; n < count; n++)
 		    s += abase_x[n] * bbase_y[n];
@@ -594,11 +597,11 @@ matmul_c8_avx (gfc_array_c8 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	      s = (GFC_COMPLEX_8) 0;
 	      for (n = 0; n < count; n++)
 		s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n];
-	      dest[y*rystride] = s;
+	      ARRAY_ELEM_AT_OFFSET (dest, y * rystride_bytes) = s;
 	    }
 	}
     }
@@ -609,10 +612,11 @@ matmul_c8_avx (gfc_array_c8 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	  s = (GFC_COMPLEX_8) 0;
 	  for (n = 0; n < count; n++)
-	    s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n*bxstride];
+	    s += GFC_DESCRIPTOR1_ELEM (a, n)
+	         * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
 	  GFC_DESCRIPTOR1_ELEM (retarray, y) = s;
 	}
     }
@@ -639,15 +643,16 @@ matmul_c8_avx (gfc_array_c8 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
-	  dest_y = &dest[y*rystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	  dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	  for (x = 0; x < xcount; x++)
 	    {
-	      abase_x = &abase[x*axstride];
+	      abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 	      s = (GFC_COMPLEX_8) 0;
 	      for (n = 0; n < count; n++)
-		s += abase_x[n*aystride] * bbase_y[n*bxstride];
-	      dest_y[x*rxstride] = s;
+		s += ARRAY_ELEM_AT_OFFSET (abase_x, n * aystride_bytes)
+		     * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
+	      ARRAY_ELEM_AT_OFFSET (dest_y, x * rxstride_bytes) = s;
 	    }
 	}
     }
@@ -674,7 +679,8 @@ matmul_c8_avx2 (gfc_array_c8 * const restrict retarray,
 
   index_type rxstride, rystride, axstride, aystride, bxstride, bystride;
   index_type x, y, n, count, xcount, ycount;
-  index_type aystride_bytes, bystride_bytes, rystride_bytes;
+  index_type axstride_bytes, aystride_bytes, bxstride_bytes, bystride_bytes,
+	     rxstride_bytes, rystride_bytes;
 
   assert (GFC_DESCRIPTOR_RANK (a) == 2
           || GFC_DESCRIPTOR_RANK (b) == 2);
@@ -763,12 +769,13 @@ matmul_c8_avx2 (gfc_array_c8 * const restrict retarray,
 	 either as a row or a column matrix. We want both cases to
 	 work. */
       rxstride = rystride = GFC_DESCRIPTOR_STRIDE(retarray,0);
-      rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
+      rxstride_bytes = rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
     }
   else
     {
       rxstride = GFC_DESCRIPTOR_STRIDE(retarray,0);
       rystride = GFC_DESCRIPTOR_STRIDE(retarray,1);
+      rxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
       rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,1);
     }
 
@@ -777,6 +784,7 @@ matmul_c8_avx2 (gfc_array_c8 * const restrict retarray,
       /* Treat it as a a row matrix A[1,count]. */
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = 1;
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = sizeof (GFC_COMPLEX_8);
 
       xcount = 1;
@@ -786,6 +794,7 @@ matmul_c8_avx2 (gfc_array_c8 * const restrict retarray,
     {
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = GFC_DESCRIPTOR_STRIDE(a,1);
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,1);
 
       count = GFC_DESCRIPTOR_EXTENT(a,1);
@@ -804,17 +813,20 @@ matmul_c8_avx2 (gfc_array_c8 * const restrict retarray,
     {
       /* Treat it as a column matrix B[count,1] */
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
 
       /* bystride should never be used for 1-dimensional b.
          The value is only used for calculation of the
          memory by the buffer.  */
       bystride = 256;
+      bystride_bytes = 99999999;
       ycount = 1;
     }
   else
     {
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
       bystride = GFC_DESCRIPTOR_STRIDE(b,1);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
       bystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,1);
       ycount = GFC_DESCRIPTOR_EXTENT(b,1);
     }
@@ -874,12 +886,11 @@ matmul_c8_avx2 (gfc_array_c8 * const restrict retarray,
 
 	 from netlib.org, translated to C, and modified for matmul.m4.  */
 
-      const GFC_COMPLEX_8 *a, *b;
       GFC_COMPLEX_8 *c;
       const index_type m = xcount, n = ycount, k = count;
 
       /* System generated locals */
-      index_type a_dim1, b_dim1, c_dim1,
+      index_type a_dim1, b_dim1,
 		 i1, i2, i3, i4, i5, i6;
 
       /* Local variables */
@@ -889,25 +900,22 @@ matmul_c8_avx2 (gfc_array_c8 * const restrict retarray,
       index_type isec, jsec, lsec, uisec, ujsec, ulsec;
       GFC_COMPLEX_8 *t1;
 
-      a = abase;
-      b = bbase;
       c = retarray->base_addr;
 
       /* Parameter adjustments */
-      c_dim1 = rystride;
       a_dim1 = aystride;
       b_dim1 = bystride;
 
 #define A_ARRAY_ELEM(i,j) \
-    a[(i) + (j) * a_dim1]
+    (ARRAY_ELEM_AT_OFFSET (abase, (i) * sizeof (GFC_COMPLEX_8) + (j) * aystride_bytes))
 
 #define B_ARRAY_ELEM(i,j) \
-    b[(i) + (j) * b_dim1]
+    (ARRAY_ELEM_AT_OFFSET (bbase, (i) * sizeof (GFC_COMPLEX_8) + (j) * bystride_bytes))
 
 #define C_ARRAY_ELEM(i,j) \
-    c[(i) + (j) * c_dim1]
+    (ARRAY_ELEM_AT_OFFSET (c, (i) * sizeof (GFC_COMPLEX_8) + (j) * rystride_bytes))
 
-      /* Empty c first.  */
+      /* Empty result first.  */
       for (j=0; j<n; j++)
 	for (i=0; i<m; i++)
 	  C_ARRAY_ELEM (i, j) = (GFC_COMPLEX_8)0;
@@ -1155,11 +1163,11 @@ matmul_c8_avx2 (gfc_array_c8 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
-	      dest_y = &dest[y*rystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	      dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	      for (x = 0; x < xcount; x++)
 		{
-		  abase_x = &abase[x*axstride];
+		  abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 		  s = (GFC_COMPLEX_8) 0;
 		  for (n = 0; n < count; n++)
 		    s += abase_x[n] * bbase_y[n];
@@ -1174,11 +1182,11 @@ matmul_c8_avx2 (gfc_array_c8 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	      s = (GFC_COMPLEX_8) 0;
 	      for (n = 0; n < count; n++)
 		s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n];
-	      dest[y*rystride] = s;
+	      ARRAY_ELEM_AT_OFFSET (dest, y * rystride_bytes) = s;
 	    }
 	}
     }
@@ -1189,10 +1197,11 @@ matmul_c8_avx2 (gfc_array_c8 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	  s = (GFC_COMPLEX_8) 0;
 	  for (n = 0; n < count; n++)
-	    s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n*bxstride];
+	    s += GFC_DESCRIPTOR1_ELEM (a, n)
+	         * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
 	  GFC_DESCRIPTOR1_ELEM (retarray, y) = s;
 	}
     }
@@ -1219,15 +1228,16 @@ matmul_c8_avx2 (gfc_array_c8 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
-	  dest_y = &dest[y*rystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	  dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	  for (x = 0; x < xcount; x++)
 	    {
-	      abase_x = &abase[x*axstride];
+	      abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 	      s = (GFC_COMPLEX_8) 0;
 	      for (n = 0; n < count; n++)
-		s += abase_x[n*aystride] * bbase_y[n*bxstride];
-	      dest_y[x*rxstride] = s;
+		s += ARRAY_ELEM_AT_OFFSET (abase_x, n * aystride_bytes)
+		     * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
+	      ARRAY_ELEM_AT_OFFSET (dest_y, x * rxstride_bytes) = s;
 	    }
 	}
     }
@@ -1254,7 +1264,8 @@ matmul_c8_avx512f (gfc_array_c8 * const restrict retarray,
 
   index_type rxstride, rystride, axstride, aystride, bxstride, bystride;
   index_type x, y, n, count, xcount, ycount;
-  index_type aystride_bytes, bystride_bytes, rystride_bytes;
+  index_type axstride_bytes, aystride_bytes, bxstride_bytes, bystride_bytes,
+	     rxstride_bytes, rystride_bytes;
 
   assert (GFC_DESCRIPTOR_RANK (a) == 2
           || GFC_DESCRIPTOR_RANK (b) == 2);
@@ -1343,12 +1354,13 @@ matmul_c8_avx512f (gfc_array_c8 * const restrict retarray,
 	 either as a row or a column matrix. We want both cases to
 	 work. */
       rxstride = rystride = GFC_DESCRIPTOR_STRIDE(retarray,0);
-      rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
+      rxstride_bytes = rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
     }
   else
     {
       rxstride = GFC_DESCRIPTOR_STRIDE(retarray,0);
       rystride = GFC_DESCRIPTOR_STRIDE(retarray,1);
+      rxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
       rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,1);
     }
 
@@ -1357,6 +1369,7 @@ matmul_c8_avx512f (gfc_array_c8 * const restrict retarray,
       /* Treat it as a a row matrix A[1,count]. */
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = 1;
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = sizeof (GFC_COMPLEX_8);
 
       xcount = 1;
@@ -1366,6 +1379,7 @@ matmul_c8_avx512f (gfc_array_c8 * const restrict retarray,
     {
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = GFC_DESCRIPTOR_STRIDE(a,1);
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,1);
 
       count = GFC_DESCRIPTOR_EXTENT(a,1);
@@ -1384,17 +1398,20 @@ matmul_c8_avx512f (gfc_array_c8 * const restrict retarray,
     {
       /* Treat it as a column matrix B[count,1] */
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
 
       /* bystride should never be used for 1-dimensional b.
          The value is only used for calculation of the
          memory by the buffer.  */
       bystride = 256;
+      bystride_bytes = 99999999;
       ycount = 1;
     }
   else
     {
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
       bystride = GFC_DESCRIPTOR_STRIDE(b,1);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
       bystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,1);
       ycount = GFC_DESCRIPTOR_EXTENT(b,1);
     }
@@ -1454,12 +1471,11 @@ matmul_c8_avx512f (gfc_array_c8 * const restrict retarray,
 
 	 from netlib.org, translated to C, and modified for matmul.m4.  */
 
-      const GFC_COMPLEX_8 *a, *b;
       GFC_COMPLEX_8 *c;
       const index_type m = xcount, n = ycount, k = count;
 
       /* System generated locals */
-      index_type a_dim1, b_dim1, c_dim1,
+      index_type a_dim1, b_dim1,
 		 i1, i2, i3, i4, i5, i6;
 
       /* Local variables */
@@ -1469,25 +1485,22 @@ matmul_c8_avx512f (gfc_array_c8 * const restrict retarray,
       index_type isec, jsec, lsec, uisec, ujsec, ulsec;
       GFC_COMPLEX_8 *t1;
 
-      a = abase;
-      b = bbase;
       c = retarray->base_addr;
 
       /* Parameter adjustments */
-      c_dim1 = rystride;
       a_dim1 = aystride;
       b_dim1 = bystride;
 
 #define A_ARRAY_ELEM(i,j) \
-    a[(i) + (j) * a_dim1]
+    (ARRAY_ELEM_AT_OFFSET (abase, (i) * sizeof (GFC_COMPLEX_8) + (j) * aystride_bytes))
 
 #define B_ARRAY_ELEM(i,j) \
-    b[(i) + (j) * b_dim1]
+    (ARRAY_ELEM_AT_OFFSET (bbase, (i) * sizeof (GFC_COMPLEX_8) + (j) * bystride_bytes))
 
 #define C_ARRAY_ELEM(i,j) \
-    c[(i) + (j) * c_dim1]
+    (ARRAY_ELEM_AT_OFFSET (c, (i) * sizeof (GFC_COMPLEX_8) + (j) * rystride_bytes))
 
-      /* Empty c first.  */
+      /* Empty result first.  */
       for (j=0; j<n; j++)
 	for (i=0; i<m; i++)
 	  C_ARRAY_ELEM (i, j) = (GFC_COMPLEX_8)0;
@@ -1735,11 +1748,11 @@ matmul_c8_avx512f (gfc_array_c8 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
-	      dest_y = &dest[y*rystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	      dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	      for (x = 0; x < xcount; x++)
 		{
-		  abase_x = &abase[x*axstride];
+		  abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 		  s = (GFC_COMPLEX_8) 0;
 		  for (n = 0; n < count; n++)
 		    s += abase_x[n] * bbase_y[n];
@@ -1754,11 +1767,11 @@ matmul_c8_avx512f (gfc_array_c8 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	      s = (GFC_COMPLEX_8) 0;
 	      for (n = 0; n < count; n++)
 		s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n];
-	      dest[y*rystride] = s;
+	      ARRAY_ELEM_AT_OFFSET (dest, y * rystride_bytes) = s;
 	    }
 	}
     }
@@ -1769,10 +1782,11 @@ matmul_c8_avx512f (gfc_array_c8 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	  s = (GFC_COMPLEX_8) 0;
 	  for (n = 0; n < count; n++)
-	    s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n*bxstride];
+	    s += GFC_DESCRIPTOR1_ELEM (a, n)
+	         * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
 	  GFC_DESCRIPTOR1_ELEM (retarray, y) = s;
 	}
     }
@@ -1799,15 +1813,16 @@ matmul_c8_avx512f (gfc_array_c8 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
-	  dest_y = &dest[y*rystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	  dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	  for (x = 0; x < xcount; x++)
 	    {
-	      abase_x = &abase[x*axstride];
+	      abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 	      s = (GFC_COMPLEX_8) 0;
 	      for (n = 0; n < count; n++)
-		s += abase_x[n*aystride] * bbase_y[n*bxstride];
-	      dest_y[x*rxstride] = s;
+		s += ARRAY_ELEM_AT_OFFSET (abase_x, n * aystride_bytes)
+		     * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
+	      ARRAY_ELEM_AT_OFFSET (dest_y, x * rxstride_bytes) = s;
 	    }
 	}
     }
@@ -1848,7 +1863,8 @@ matmul_c8_vanilla (gfc_array_c8 * const restrict retarray,
 
   index_type rxstride, rystride, axstride, aystride, bxstride, bystride;
   index_type x, y, n, count, xcount, ycount;
-  index_type aystride_bytes, bystride_bytes, rystride_bytes;
+  index_type axstride_bytes, aystride_bytes, bxstride_bytes, bystride_bytes,
+	     rxstride_bytes, rystride_bytes;
 
   assert (GFC_DESCRIPTOR_RANK (a) == 2
           || GFC_DESCRIPTOR_RANK (b) == 2);
@@ -1937,12 +1953,13 @@ matmul_c8_vanilla (gfc_array_c8 * const restrict retarray,
 	 either as a row or a column matrix. We want both cases to
 	 work. */
       rxstride = rystride = GFC_DESCRIPTOR_STRIDE(retarray,0);
-      rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
+      rxstride_bytes = rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
     }
   else
     {
       rxstride = GFC_DESCRIPTOR_STRIDE(retarray,0);
       rystride = GFC_DESCRIPTOR_STRIDE(retarray,1);
+      rxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
       rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,1);
     }
 
@@ -1951,6 +1968,7 @@ matmul_c8_vanilla (gfc_array_c8 * const restrict retarray,
       /* Treat it as a a row matrix A[1,count]. */
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = 1;
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = sizeof (GFC_COMPLEX_8);
 
       xcount = 1;
@@ -1960,6 +1978,7 @@ matmul_c8_vanilla (gfc_array_c8 * const restrict retarray,
     {
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = GFC_DESCRIPTOR_STRIDE(a,1);
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,1);
 
       count = GFC_DESCRIPTOR_EXTENT(a,1);
@@ -1978,17 +1997,20 @@ matmul_c8_vanilla (gfc_array_c8 * const restrict retarray,
     {
       /* Treat it as a column matrix B[count,1] */
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
 
       /* bystride should never be used for 1-dimensional b.
          The value is only used for calculation of the
          memory by the buffer.  */
       bystride = 256;
+      bystride_bytes = 99999999;
       ycount = 1;
     }
   else
     {
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
       bystride = GFC_DESCRIPTOR_STRIDE(b,1);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
       bystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,1);
       ycount = GFC_DESCRIPTOR_EXTENT(b,1);
     }
@@ -2048,12 +2070,11 @@ matmul_c8_vanilla (gfc_array_c8 * const restrict retarray,
 
 	 from netlib.org, translated to C, and modified for matmul.m4.  */
 
-      const GFC_COMPLEX_8 *a, *b;
       GFC_COMPLEX_8 *c;
       const index_type m = xcount, n = ycount, k = count;
 
       /* System generated locals */
-      index_type a_dim1, b_dim1, c_dim1,
+      index_type a_dim1, b_dim1,
 		 i1, i2, i3, i4, i5, i6;
 
       /* Local variables */
@@ -2063,25 +2084,22 @@ matmul_c8_vanilla (gfc_array_c8 * const restrict retarray,
       index_type isec, jsec, lsec, uisec, ujsec, ulsec;
       GFC_COMPLEX_8 *t1;
 
-      a = abase;
-      b = bbase;
       c = retarray->base_addr;
 
       /* Parameter adjustments */
-      c_dim1 = rystride;
       a_dim1 = aystride;
       b_dim1 = bystride;
 
 #define A_ARRAY_ELEM(i,j) \
-    a[(i) + (j) * a_dim1]
+    (ARRAY_ELEM_AT_OFFSET (abase, (i) * sizeof (GFC_COMPLEX_8) + (j) * aystride_bytes))
 
 #define B_ARRAY_ELEM(i,j) \
-    b[(i) + (j) * b_dim1]
+    (ARRAY_ELEM_AT_OFFSET (bbase, (i) * sizeof (GFC_COMPLEX_8) + (j) * bystride_bytes))
 
 #define C_ARRAY_ELEM(i,j) \
-    c[(i) + (j) * c_dim1]
+    (ARRAY_ELEM_AT_OFFSET (c, (i) * sizeof (GFC_COMPLEX_8) + (j) * rystride_bytes))
 
-      /* Empty c first.  */
+      /* Empty result first.  */
       for (j=0; j<n; j++)
 	for (i=0; i<m; i++)
 	  C_ARRAY_ELEM (i, j) = (GFC_COMPLEX_8)0;
@@ -2329,11 +2347,11 @@ matmul_c8_vanilla (gfc_array_c8 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
-	      dest_y = &dest[y*rystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	      dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	      for (x = 0; x < xcount; x++)
 		{
-		  abase_x = &abase[x*axstride];
+		  abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 		  s = (GFC_COMPLEX_8) 0;
 		  for (n = 0; n < count; n++)
 		    s += abase_x[n] * bbase_y[n];
@@ -2348,11 +2366,11 @@ matmul_c8_vanilla (gfc_array_c8 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	      s = (GFC_COMPLEX_8) 0;
 	      for (n = 0; n < count; n++)
 		s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n];
-	      dest[y*rystride] = s;
+	      ARRAY_ELEM_AT_OFFSET (dest, y * rystride_bytes) = s;
 	    }
 	}
     }
@@ -2363,10 +2381,11 @@ matmul_c8_vanilla (gfc_array_c8 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	  s = (GFC_COMPLEX_8) 0;
 	  for (n = 0; n < count; n++)
-	    s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n*bxstride];
+	    s += GFC_DESCRIPTOR1_ELEM (a, n)
+	         * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
 	  GFC_DESCRIPTOR1_ELEM (retarray, y) = s;
 	}
     }
@@ -2393,15 +2412,16 @@ matmul_c8_vanilla (gfc_array_c8 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
-	  dest_y = &dest[y*rystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	  dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	  for (x = 0; x < xcount; x++)
 	    {
-	      abase_x = &abase[x*axstride];
+	      abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 	      s = (GFC_COMPLEX_8) 0;
 	      for (n = 0; n < count; n++)
-		s += abase_x[n*aystride] * bbase_y[n*bxstride];
-	      dest_y[x*rxstride] = s;
+		s += ARRAY_ELEM_AT_OFFSET (abase_x, n * aystride_bytes)
+		     * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
+	      ARRAY_ELEM_AT_OFFSET (dest_y, x * rxstride_bytes) = s;
 	    }
 	}
     }
@@ -2501,7 +2521,8 @@ matmul_c8 (gfc_array_c8 * const restrict retarray,
 
   index_type rxstride, rystride, axstride, aystride, bxstride, bystride;
   index_type x, y, n, count, xcount, ycount;
-  index_type aystride_bytes, bystride_bytes, rystride_bytes;
+  index_type axstride_bytes, aystride_bytes, bxstride_bytes, bystride_bytes,
+	     rxstride_bytes, rystride_bytes;
 
   assert (GFC_DESCRIPTOR_RANK (a) == 2
           || GFC_DESCRIPTOR_RANK (b) == 2);
@@ -2590,12 +2611,13 @@ matmul_c8 (gfc_array_c8 * const restrict retarray,
 	 either as a row or a column matrix. We want both cases to
 	 work. */
       rxstride = rystride = GFC_DESCRIPTOR_STRIDE(retarray,0);
-      rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
+      rxstride_bytes = rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
     }
   else
     {
       rxstride = GFC_DESCRIPTOR_STRIDE(retarray,0);
       rystride = GFC_DESCRIPTOR_STRIDE(retarray,1);
+      rxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
       rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,1);
     }
 
@@ -2604,6 +2626,7 @@ matmul_c8 (gfc_array_c8 * const restrict retarray,
       /* Treat it as a a row matrix A[1,count]. */
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = 1;
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = sizeof (GFC_COMPLEX_8);
 
       xcount = 1;
@@ -2613,6 +2636,7 @@ matmul_c8 (gfc_array_c8 * const restrict retarray,
     {
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = GFC_DESCRIPTOR_STRIDE(a,1);
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,1);
 
       count = GFC_DESCRIPTOR_EXTENT(a,1);
@@ -2631,17 +2655,20 @@ matmul_c8 (gfc_array_c8 * const restrict retarray,
     {
       /* Treat it as a column matrix B[count,1] */
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
 
       /* bystride should never be used for 1-dimensional b.
          The value is only used for calculation of the
          memory by the buffer.  */
       bystride = 256;
+      bystride_bytes = 99999999;
       ycount = 1;
     }
   else
     {
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
       bystride = GFC_DESCRIPTOR_STRIDE(b,1);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
       bystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,1);
       ycount = GFC_DESCRIPTOR_EXTENT(b,1);
     }
@@ -2701,12 +2728,11 @@ matmul_c8 (gfc_array_c8 * const restrict retarray,
 
 	 from netlib.org, translated to C, and modified for matmul.m4.  */
 
-      const GFC_COMPLEX_8 *a, *b;
       GFC_COMPLEX_8 *c;
       const index_type m = xcount, n = ycount, k = count;
 
       /* System generated locals */
-      index_type a_dim1, b_dim1, c_dim1,
+      index_type a_dim1, b_dim1,
 		 i1, i2, i3, i4, i5, i6;
 
       /* Local variables */
@@ -2716,25 +2742,22 @@ matmul_c8 (gfc_array_c8 * const restrict retarray,
       index_type isec, jsec, lsec, uisec, ujsec, ulsec;
       GFC_COMPLEX_8 *t1;
 
-      a = abase;
-      b = bbase;
       c = retarray->base_addr;
 
       /* Parameter adjustments */
-      c_dim1 = rystride;
       a_dim1 = aystride;
       b_dim1 = bystride;
 
 #define A_ARRAY_ELEM(i,j) \
-    a[(i) + (j) * a_dim1]
+    (ARRAY_ELEM_AT_OFFSET (abase, (i) * sizeof (GFC_COMPLEX_8) + (j) * aystride_bytes))
 
 #define B_ARRAY_ELEM(i,j) \
-    b[(i) + (j) * b_dim1]
+    (ARRAY_ELEM_AT_OFFSET (bbase, (i) * sizeof (GFC_COMPLEX_8) + (j) * bystride_bytes))
 
 #define C_ARRAY_ELEM(i,j) \
-    c[(i) + (j) * c_dim1]
+    (ARRAY_ELEM_AT_OFFSET (c, (i) * sizeof (GFC_COMPLEX_8) + (j) * rystride_bytes))
 
-      /* Empty c first.  */
+      /* Empty result first.  */
       for (j=0; j<n; j++)
 	for (i=0; i<m; i++)
 	  C_ARRAY_ELEM (i, j) = (GFC_COMPLEX_8)0;
@@ -2982,11 +3005,11 @@ matmul_c8 (gfc_array_c8 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
-	      dest_y = &dest[y*rystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	      dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	      for (x = 0; x < xcount; x++)
 		{
-		  abase_x = &abase[x*axstride];
+		  abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 		  s = (GFC_COMPLEX_8) 0;
 		  for (n = 0; n < count; n++)
 		    s += abase_x[n] * bbase_y[n];
@@ -3001,11 +3024,11 @@ matmul_c8 (gfc_array_c8 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	      s = (GFC_COMPLEX_8) 0;
 	      for (n = 0; n < count; n++)
 		s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n];
-	      dest[y*rystride] = s;
+	      ARRAY_ELEM_AT_OFFSET (dest, y * rystride_bytes) = s;
 	    }
 	}
     }
@@ -3016,10 +3039,11 @@ matmul_c8 (gfc_array_c8 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	  s = (GFC_COMPLEX_8) 0;
 	  for (n = 0; n < count; n++)
-	    s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n*bxstride];
+	    s += GFC_DESCRIPTOR1_ELEM (a, n)
+	         * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
 	  GFC_DESCRIPTOR1_ELEM (retarray, y) = s;
 	}
     }
@@ -3046,15 +3070,16 @@ matmul_c8 (gfc_array_c8 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
-	  dest_y = &dest[y*rystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	  dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	  for (x = 0; x < xcount; x++)
 	    {
-	      abase_x = &abase[x*axstride];
+	      abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 	      s = (GFC_COMPLEX_8) 0;
 	      for (n = 0; n < count; n++)
-		s += abase_x[n*aystride] * bbase_y[n*bxstride];
-	      dest_y[x*rxstride] = s;
+		s += ARRAY_ELEM_AT_OFFSET (abase_x, n * aystride_bytes)
+		     * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
+	      ARRAY_ELEM_AT_OFFSET (dest_y, x * rxstride_bytes) = s;
 	    }
 	}
     }
diff --git a/libgfortran/generated/matmul_i1.c b/libgfortran/generated/matmul_i1.c
index a69b8b180beb..2b45d14eeb19 100644
--- a/libgfortran/generated/matmul_i1.c
+++ b/libgfortran/generated/matmul_i1.c
@@ -94,7 +94,8 @@ matmul_i1_avx (gfc_array_m1 * const restrict retarray,
 
   index_type rxstride, rystride, axstride, aystride, bxstride, bystride;
   index_type x, y, n, count, xcount, ycount;
-  index_type aystride_bytes, bystride_bytes, rystride_bytes;
+  index_type axstride_bytes, aystride_bytes, bxstride_bytes, bystride_bytes,
+	     rxstride_bytes, rystride_bytes;
 
   assert (GFC_DESCRIPTOR_RANK (a) == 2
           || GFC_DESCRIPTOR_RANK (b) == 2);
@@ -183,12 +184,13 @@ matmul_i1_avx (gfc_array_m1 * const restrict retarray,
 	 either as a row or a column matrix. We want both cases to
 	 work. */
       rxstride = rystride = GFC_DESCRIPTOR_STRIDE(retarray,0);
-      rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
+      rxstride_bytes = rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
     }
   else
     {
       rxstride = GFC_DESCRIPTOR_STRIDE(retarray,0);
       rystride = GFC_DESCRIPTOR_STRIDE(retarray,1);
+      rxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
       rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,1);
     }
 
@@ -197,6 +199,7 @@ matmul_i1_avx (gfc_array_m1 * const restrict retarray,
       /* Treat it as a a row matrix A[1,count]. */
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = 1;
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = sizeof (GFC_UINTEGER_1);
 
       xcount = 1;
@@ -206,6 +209,7 @@ matmul_i1_avx (gfc_array_m1 * const restrict retarray,
     {
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = GFC_DESCRIPTOR_STRIDE(a,1);
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,1);
 
       count = GFC_DESCRIPTOR_EXTENT(a,1);
@@ -224,17 +228,20 @@ matmul_i1_avx (gfc_array_m1 * const restrict retarray,
     {
       /* Treat it as a column matrix B[count,1] */
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
 
       /* bystride should never be used for 1-dimensional b.
          The value is only used for calculation of the
          memory by the buffer.  */
       bystride = 256;
+      bystride_bytes = 99999999;
       ycount = 1;
     }
   else
     {
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
       bystride = GFC_DESCRIPTOR_STRIDE(b,1);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
       bystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,1);
       ycount = GFC_DESCRIPTOR_EXTENT(b,1);
     }
@@ -294,12 +301,11 @@ matmul_i1_avx (gfc_array_m1 * const restrict retarray,
 
 	 from netlib.org, translated to C, and modified for matmul.m4.  */
 
-      const GFC_UINTEGER_1 *a, *b;
       GFC_UINTEGER_1 *c;
       const index_type m = xcount, n = ycount, k = count;
 
       /* System generated locals */
-      index_type a_dim1, b_dim1, c_dim1,
+      index_type a_dim1, b_dim1,
 		 i1, i2, i3, i4, i5, i6;
 
       /* Local variables */
@@ -309,25 +315,22 @@ matmul_i1_avx (gfc_array_m1 * const restrict retarray,
       index_type isec, jsec, lsec, uisec, ujsec, ulsec;
       GFC_UINTEGER_1 *t1;
 
-      a = abase;
-      b = bbase;
       c = retarray->base_addr;
 
       /* Parameter adjustments */
-      c_dim1 = rystride;
       a_dim1 = aystride;
       b_dim1 = bystride;
 
 #define A_ARRAY_ELEM(i,j) \
-    a[(i) + (j) * a_dim1]
+    (ARRAY_ELEM_AT_OFFSET (abase, (i) * sizeof (GFC_UINTEGER_1) + (j) * aystride_bytes))
 
 #define B_ARRAY_ELEM(i,j) \
-    b[(i) + (j) * b_dim1]
+    (ARRAY_ELEM_AT_OFFSET (bbase, (i) * sizeof (GFC_UINTEGER_1) + (j) * bystride_bytes))
 
 #define C_ARRAY_ELEM(i,j) \
-    c[(i) + (j) * c_dim1]
+    (ARRAY_ELEM_AT_OFFSET (c, (i) * sizeof (GFC_UINTEGER_1) + (j) * rystride_bytes))
 
-      /* Empty c first.  */
+      /* Empty result first.  */
       for (j=0; j<n; j++)
 	for (i=0; i<m; i++)
 	  C_ARRAY_ELEM (i, j) = (GFC_UINTEGER_1)0;
@@ -575,11 +578,11 @@ matmul_i1_avx (gfc_array_m1 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
-	      dest_y = &dest[y*rystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	      dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	      for (x = 0; x < xcount; x++)
 		{
-		  abase_x = &abase[x*axstride];
+		  abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 		  s = (GFC_UINTEGER_1) 0;
 		  for (n = 0; n < count; n++)
 		    s += abase_x[n] * bbase_y[n];
@@ -594,11 +597,11 @@ matmul_i1_avx (gfc_array_m1 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	      s = (GFC_UINTEGER_1) 0;
 	      for (n = 0; n < count; n++)
 		s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n];
-	      dest[y*rystride] = s;
+	      ARRAY_ELEM_AT_OFFSET (dest, y * rystride_bytes) = s;
 	    }
 	}
     }
@@ -609,10 +612,11 @@ matmul_i1_avx (gfc_array_m1 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	  s = (GFC_UINTEGER_1) 0;
 	  for (n = 0; n < count; n++)
-	    s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n*bxstride];
+	    s += GFC_DESCRIPTOR1_ELEM (a, n)
+	         * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
 	  GFC_DESCRIPTOR1_ELEM (retarray, y) = s;
 	}
     }
@@ -639,15 +643,16 @@ matmul_i1_avx (gfc_array_m1 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
-	  dest_y = &dest[y*rystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	  dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	  for (x = 0; x < xcount; x++)
 	    {
-	      abase_x = &abase[x*axstride];
+	      abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 	      s = (GFC_UINTEGER_1) 0;
 	      for (n = 0; n < count; n++)
-		s += abase_x[n*aystride] * bbase_y[n*bxstride];
-	      dest_y[x*rxstride] = s;
+		s += ARRAY_ELEM_AT_OFFSET (abase_x, n * aystride_bytes)
+		     * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
+	      ARRAY_ELEM_AT_OFFSET (dest_y, x * rxstride_bytes) = s;
 	    }
 	}
     }
@@ -674,7 +679,8 @@ matmul_i1_avx2 (gfc_array_m1 * const restrict retarray,
 
   index_type rxstride, rystride, axstride, aystride, bxstride, bystride;
   index_type x, y, n, count, xcount, ycount;
-  index_type aystride_bytes, bystride_bytes, rystride_bytes;
+  index_type axstride_bytes, aystride_bytes, bxstride_bytes, bystride_bytes,
+	     rxstride_bytes, rystride_bytes;
 
   assert (GFC_DESCRIPTOR_RANK (a) == 2
           || GFC_DESCRIPTOR_RANK (b) == 2);
@@ -763,12 +769,13 @@ matmul_i1_avx2 (gfc_array_m1 * const restrict retarray,
 	 either as a row or a column matrix. We want both cases to
 	 work. */
       rxstride = rystride = GFC_DESCRIPTOR_STRIDE(retarray,0);
-      rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
+      rxstride_bytes = rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
     }
   else
     {
       rxstride = GFC_DESCRIPTOR_STRIDE(retarray,0);
       rystride = GFC_DESCRIPTOR_STRIDE(retarray,1);
+      rxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
       rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,1);
     }
 
@@ -777,6 +784,7 @@ matmul_i1_avx2 (gfc_array_m1 * const restrict retarray,
       /* Treat it as a a row matrix A[1,count]. */
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = 1;
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = sizeof (GFC_UINTEGER_1);
 
       xcount = 1;
@@ -786,6 +794,7 @@ matmul_i1_avx2 (gfc_array_m1 * const restrict retarray,
     {
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = GFC_DESCRIPTOR_STRIDE(a,1);
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,1);
 
       count = GFC_DESCRIPTOR_EXTENT(a,1);
@@ -804,17 +813,20 @@ matmul_i1_avx2 (gfc_array_m1 * const restrict retarray,
     {
       /* Treat it as a column matrix B[count,1] */
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
 
       /* bystride should never be used for 1-dimensional b.
          The value is only used for calculation of the
          memory by the buffer.  */
       bystride = 256;
+      bystride_bytes = 99999999;
       ycount = 1;
     }
   else
     {
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
       bystride = GFC_DESCRIPTOR_STRIDE(b,1);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
       bystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,1);
       ycount = GFC_DESCRIPTOR_EXTENT(b,1);
     }
@@ -874,12 +886,11 @@ matmul_i1_avx2 (gfc_array_m1 * const restrict retarray,
 
 	 from netlib.org, translated to C, and modified for matmul.m4.  */
 
-      const GFC_UINTEGER_1 *a, *b;
       GFC_UINTEGER_1 *c;
       const index_type m = xcount, n = ycount, k = count;
 
       /* System generated locals */
-      index_type a_dim1, b_dim1, c_dim1,
+      index_type a_dim1, b_dim1,
 		 i1, i2, i3, i4, i5, i6;
 
       /* Local variables */
@@ -889,25 +900,22 @@ matmul_i1_avx2 (gfc_array_m1 * const restrict retarray,
       index_type isec, jsec, lsec, uisec, ujsec, ulsec;
       GFC_UINTEGER_1 *t1;
 
-      a = abase;
-      b = bbase;
       c = retarray->base_addr;
 
       /* Parameter adjustments */
-      c_dim1 = rystride;
       a_dim1 = aystride;
       b_dim1 = bystride;
 
 #define A_ARRAY_ELEM(i,j) \
-    a[(i) + (j) * a_dim1]
+    (ARRAY_ELEM_AT_OFFSET (abase, (i) * sizeof (GFC_UINTEGER_1) + (j) * aystride_bytes))
 
 #define B_ARRAY_ELEM(i,j) \
-    b[(i) + (j) * b_dim1]
+    (ARRAY_ELEM_AT_OFFSET (bbase, (i) * sizeof (GFC_UINTEGER_1) + (j) * bystride_bytes))
 
 #define C_ARRAY_ELEM(i,j) \
-    c[(i) + (j) * c_dim1]
+    (ARRAY_ELEM_AT_OFFSET (c, (i) * sizeof (GFC_UINTEGER_1) + (j) * rystride_bytes))
 
-      /* Empty c first.  */
+      /* Empty result first.  */
       for (j=0; j<n; j++)
 	for (i=0; i<m; i++)
 	  C_ARRAY_ELEM (i, j) = (GFC_UINTEGER_1)0;
@@ -1155,11 +1163,11 @@ matmul_i1_avx2 (gfc_array_m1 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
-	      dest_y = &dest[y*rystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	      dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	      for (x = 0; x < xcount; x++)
 		{
-		  abase_x = &abase[x*axstride];
+		  abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 		  s = (GFC_UINTEGER_1) 0;
 		  for (n = 0; n < count; n++)
 		    s += abase_x[n] * bbase_y[n];
@@ -1174,11 +1182,11 @@ matmul_i1_avx2 (gfc_array_m1 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	      s = (GFC_UINTEGER_1) 0;
 	      for (n = 0; n < count; n++)
 		s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n];
-	      dest[y*rystride] = s;
+	      ARRAY_ELEM_AT_OFFSET (dest, y * rystride_bytes) = s;
 	    }
 	}
     }
@@ -1189,10 +1197,11 @@ matmul_i1_avx2 (gfc_array_m1 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	  s = (GFC_UINTEGER_1) 0;
 	  for (n = 0; n < count; n++)
-	    s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n*bxstride];
+	    s += GFC_DESCRIPTOR1_ELEM (a, n)
+	         * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
 	  GFC_DESCRIPTOR1_ELEM (retarray, y) = s;
 	}
     }
@@ -1219,15 +1228,16 @@ matmul_i1_avx2 (gfc_array_m1 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
-	  dest_y = &dest[y*rystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	  dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	  for (x = 0; x < xcount; x++)
 	    {
-	      abase_x = &abase[x*axstride];
+	      abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 	      s = (GFC_UINTEGER_1) 0;
 	      for (n = 0; n < count; n++)
-		s += abase_x[n*aystride] * bbase_y[n*bxstride];
-	      dest_y[x*rxstride] = s;
+		s += ARRAY_ELEM_AT_OFFSET (abase_x, n * aystride_bytes)
+		     * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
+	      ARRAY_ELEM_AT_OFFSET (dest_y, x * rxstride_bytes) = s;
 	    }
 	}
     }
@@ -1254,7 +1264,8 @@ matmul_i1_avx512f (gfc_array_m1 * const restrict retarray,
 
   index_type rxstride, rystride, axstride, aystride, bxstride, bystride;
   index_type x, y, n, count, xcount, ycount;
-  index_type aystride_bytes, bystride_bytes, rystride_bytes;
+  index_type axstride_bytes, aystride_bytes, bxstride_bytes, bystride_bytes,
+	     rxstride_bytes, rystride_bytes;
 
   assert (GFC_DESCRIPTOR_RANK (a) == 2
           || GFC_DESCRIPTOR_RANK (b) == 2);
@@ -1343,12 +1354,13 @@ matmul_i1_avx512f (gfc_array_m1 * const restrict retarray,
 	 either as a row or a column matrix. We want both cases to
 	 work. */
       rxstride = rystride = GFC_DESCRIPTOR_STRIDE(retarray,0);
-      rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
+      rxstride_bytes = rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
     }
   else
     {
       rxstride = GFC_DESCRIPTOR_STRIDE(retarray,0);
       rystride = GFC_DESCRIPTOR_STRIDE(retarray,1);
+      rxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
       rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,1);
     }
 
@@ -1357,6 +1369,7 @@ matmul_i1_avx512f (gfc_array_m1 * const restrict retarray,
       /* Treat it as a a row matrix A[1,count]. */
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = 1;
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = sizeof (GFC_UINTEGER_1);
 
       xcount = 1;
@@ -1366,6 +1379,7 @@ matmul_i1_avx512f (gfc_array_m1 * const restrict retarray,
     {
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = GFC_DESCRIPTOR_STRIDE(a,1);
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,1);
 
       count = GFC_DESCRIPTOR_EXTENT(a,1);
@@ -1384,17 +1398,20 @@ matmul_i1_avx512f (gfc_array_m1 * const restrict retarray,
     {
       /* Treat it as a column matrix B[count,1] */
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
 
       /* bystride should never be used for 1-dimensional b.
          The value is only used for calculation of the
          memory by the buffer.  */
       bystride = 256;
+      bystride_bytes = 99999999;
       ycount = 1;
     }
   else
     {
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
       bystride = GFC_DESCRIPTOR_STRIDE(b,1);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
       bystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,1);
       ycount = GFC_DESCRIPTOR_EXTENT(b,1);
     }
@@ -1454,12 +1471,11 @@ matmul_i1_avx512f (gfc_array_m1 * const restrict retarray,
 
 	 from netlib.org, translated to C, and modified for matmul.m4.  */
 
-      const GFC_UINTEGER_1 *a, *b;
       GFC_UINTEGER_1 *c;
       const index_type m = xcount, n = ycount, k = count;
 
       /* System generated locals */
-      index_type a_dim1, b_dim1, c_dim1,
+      index_type a_dim1, b_dim1,
 		 i1, i2, i3, i4, i5, i6;
 
       /* Local variables */
@@ -1469,25 +1485,22 @@ matmul_i1_avx512f (gfc_array_m1 * const restrict retarray,
       index_type isec, jsec, lsec, uisec, ujsec, ulsec;
       GFC_UINTEGER_1 *t1;
 
-      a = abase;
-      b = bbase;
       c = retarray->base_addr;
 
       /* Parameter adjustments */
-      c_dim1 = rystride;
       a_dim1 = aystride;
       b_dim1 = bystride;
 
 #define A_ARRAY_ELEM(i,j) \
-    a[(i) + (j) * a_dim1]
+    (ARRAY_ELEM_AT_OFFSET (abase, (i) * sizeof (GFC_UINTEGER_1) + (j) * aystride_bytes))
 
 #define B_ARRAY_ELEM(i,j) \
-    b[(i) + (j) * b_dim1]
+    (ARRAY_ELEM_AT_OFFSET (bbase, (i) * sizeof (GFC_UINTEGER_1) + (j) * bystride_bytes))
 
 #define C_ARRAY_ELEM(i,j) \
-    c[(i) + (j) * c_dim1]
+    (ARRAY_ELEM_AT_OFFSET (c, (i) * sizeof (GFC_UINTEGER_1) + (j) * rystride_bytes))
 
-      /* Empty c first.  */
+      /* Empty result first.  */
       for (j=0; j<n; j++)
 	for (i=0; i<m; i++)
 	  C_ARRAY_ELEM (i, j) = (GFC_UINTEGER_1)0;
@@ -1735,11 +1748,11 @@ matmul_i1_avx512f (gfc_array_m1 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
-	      dest_y = &dest[y*rystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	      dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	      for (x = 0; x < xcount; x++)
 		{
-		  abase_x = &abase[x*axstride];
+		  abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 		  s = (GFC_UINTEGER_1) 0;
 		  for (n = 0; n < count; n++)
 		    s += abase_x[n] * bbase_y[n];
@@ -1754,11 +1767,11 @@ matmul_i1_avx512f (gfc_array_m1 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	      s = (GFC_UINTEGER_1) 0;
 	      for (n = 0; n < count; n++)
 		s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n];
-	      dest[y*rystride] = s;
+	      ARRAY_ELEM_AT_OFFSET (dest, y * rystride_bytes) = s;
 	    }
 	}
     }
@@ -1769,10 +1782,11 @@ matmul_i1_avx512f (gfc_array_m1 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	  s = (GFC_UINTEGER_1) 0;
 	  for (n = 0; n < count; n++)
-	    s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n*bxstride];
+	    s += GFC_DESCRIPTOR1_ELEM (a, n)
+	         * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
 	  GFC_DESCRIPTOR1_ELEM (retarray, y) = s;
 	}
     }
@@ -1799,15 +1813,16 @@ matmul_i1_avx512f (gfc_array_m1 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
-	  dest_y = &dest[y*rystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	  dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	  for (x = 0; x < xcount; x++)
 	    {
-	      abase_x = &abase[x*axstride];
+	      abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 	      s = (GFC_UINTEGER_1) 0;
 	      for (n = 0; n < count; n++)
-		s += abase_x[n*aystride] * bbase_y[n*bxstride];
-	      dest_y[x*rxstride] = s;
+		s += ARRAY_ELEM_AT_OFFSET (abase_x, n * aystride_bytes)
+		     * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
+	      ARRAY_ELEM_AT_OFFSET (dest_y, x * rxstride_bytes) = s;
 	    }
 	}
     }
@@ -1848,7 +1863,8 @@ matmul_i1_vanilla (gfc_array_m1 * const restrict retarray,
 
   index_type rxstride, rystride, axstride, aystride, bxstride, bystride;
   index_type x, y, n, count, xcount, ycount;
-  index_type aystride_bytes, bystride_bytes, rystride_bytes;
+  index_type axstride_bytes, aystride_bytes, bxstride_bytes, bystride_bytes,
+	     rxstride_bytes, rystride_bytes;
 
   assert (GFC_DESCRIPTOR_RANK (a) == 2
           || GFC_DESCRIPTOR_RANK (b) == 2);
@@ -1937,12 +1953,13 @@ matmul_i1_vanilla (gfc_array_m1 * const restrict retarray,
 	 either as a row or a column matrix. We want both cases to
 	 work. */
       rxstride = rystride = GFC_DESCRIPTOR_STRIDE(retarray,0);
-      rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
+      rxstride_bytes = rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
     }
   else
     {
       rxstride = GFC_DESCRIPTOR_STRIDE(retarray,0);
       rystride = GFC_DESCRIPTOR_STRIDE(retarray,1);
+      rxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
       rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,1);
     }
 
@@ -1951,6 +1968,7 @@ matmul_i1_vanilla (gfc_array_m1 * const restrict retarray,
       /* Treat it as a a row matrix A[1,count]. */
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = 1;
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = sizeof (GFC_UINTEGER_1);
 
       xcount = 1;
@@ -1960,6 +1978,7 @@ matmul_i1_vanilla (gfc_array_m1 * const restrict retarray,
     {
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = GFC_DESCRIPTOR_STRIDE(a,1);
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,1);
 
       count = GFC_DESCRIPTOR_EXTENT(a,1);
@@ -1978,17 +1997,20 @@ matmul_i1_vanilla (gfc_array_m1 * const restrict retarray,
     {
       /* Treat it as a column matrix B[count,1] */
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
 
       /* bystride should never be used for 1-dimensional b.
          The value is only used for calculation of the
          memory by the buffer.  */
       bystride = 256;
+      bystride_bytes = 99999999;
       ycount = 1;
     }
   else
     {
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
       bystride = GFC_DESCRIPTOR_STRIDE(b,1);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
       bystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,1);
       ycount = GFC_DESCRIPTOR_EXTENT(b,1);
     }
@@ -2048,12 +2070,11 @@ matmul_i1_vanilla (gfc_array_m1 * const restrict retarray,
 
 	 from netlib.org, translated to C, and modified for matmul.m4.  */
 
-      const GFC_UINTEGER_1 *a, *b;
       GFC_UINTEGER_1 *c;
       const index_type m = xcount, n = ycount, k = count;
 
       /* System generated locals */
-      index_type a_dim1, b_dim1, c_dim1,
+      index_type a_dim1, b_dim1,
 		 i1, i2, i3, i4, i5, i6;
 
       /* Local variables */
@@ -2063,25 +2084,22 @@ matmul_i1_vanilla (gfc_array_m1 * const restrict retarray,
       index_type isec, jsec, lsec, uisec, ujsec, ulsec;
       GFC_UINTEGER_1 *t1;
 
-      a = abase;
-      b = bbase;
       c = retarray->base_addr;
 
       /* Parameter adjustments */
-      c_dim1 = rystride;
       a_dim1 = aystride;
       b_dim1 = bystride;
 
 #define A_ARRAY_ELEM(i,j) \
-    a[(i) + (j) * a_dim1]
+    (ARRAY_ELEM_AT_OFFSET (abase, (i) * sizeof (GFC_UINTEGER_1) + (j) * aystride_bytes))
 
 #define B_ARRAY_ELEM(i,j) \
-    b[(i) + (j) * b_dim1]
+    (ARRAY_ELEM_AT_OFFSET (bbase, (i) * sizeof (GFC_UINTEGER_1) + (j) * bystride_bytes))
 
 #define C_ARRAY_ELEM(i,j) \
-    c[(i) + (j) * c_dim1]
+    (ARRAY_ELEM_AT_OFFSET (c, (i) * sizeof (GFC_UINTEGER_1) + (j) * rystride_bytes))
 
-      /* Empty c first.  */
+      /* Empty result first.  */
       for (j=0; j<n; j++)
 	for (i=0; i<m; i++)
 	  C_ARRAY_ELEM (i, j) = (GFC_UINTEGER_1)0;
@@ -2329,11 +2347,11 @@ matmul_i1_vanilla (gfc_array_m1 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
-	      dest_y = &dest[y*rystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	      dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	      for (x = 0; x < xcount; x++)
 		{
-		  abase_x = &abase[x*axstride];
+		  abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 		  s = (GFC_UINTEGER_1) 0;
 		  for (n = 0; n < count; n++)
 		    s += abase_x[n] * bbase_y[n];
@@ -2348,11 +2366,11 @@ matmul_i1_vanilla (gfc_array_m1 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	      s = (GFC_UINTEGER_1) 0;
 	      for (n = 0; n < count; n++)
 		s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n];
-	      dest[y*rystride] = s;
+	      ARRAY_ELEM_AT_OFFSET (dest, y * rystride_bytes) = s;
 	    }
 	}
     }
@@ -2363,10 +2381,11 @@ matmul_i1_vanilla (gfc_array_m1 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	  s = (GFC_UINTEGER_1) 0;
 	  for (n = 0; n < count; n++)
-	    s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n*bxstride];
+	    s += GFC_DESCRIPTOR1_ELEM (a, n)
+	         * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
 	  GFC_DESCRIPTOR1_ELEM (retarray, y) = s;
 	}
     }
@@ -2393,15 +2412,16 @@ matmul_i1_vanilla (gfc_array_m1 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
-	  dest_y = &dest[y*rystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	  dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	  for (x = 0; x < xcount; x++)
 	    {
-	      abase_x = &abase[x*axstride];
+	      abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 	      s = (GFC_UINTEGER_1) 0;
 	      for (n = 0; n < count; n++)
-		s += abase_x[n*aystride] * bbase_y[n*bxstride];
-	      dest_y[x*rxstride] = s;
+		s += ARRAY_ELEM_AT_OFFSET (abase_x, n * aystride_bytes)
+		     * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
+	      ARRAY_ELEM_AT_OFFSET (dest_y, x * rxstride_bytes) = s;
 	    }
 	}
     }
@@ -2501,7 +2521,8 @@ matmul_i1 (gfc_array_m1 * const restrict retarray,
 
   index_type rxstride, rystride, axstride, aystride, bxstride, bystride;
   index_type x, y, n, count, xcount, ycount;
-  index_type aystride_bytes, bystride_bytes, rystride_bytes;
+  index_type axstride_bytes, aystride_bytes, bxstride_bytes, bystride_bytes,
+	     rxstride_bytes, rystride_bytes;
 
   assert (GFC_DESCRIPTOR_RANK (a) == 2
           || GFC_DESCRIPTOR_RANK (b) == 2);
@@ -2590,12 +2611,13 @@ matmul_i1 (gfc_array_m1 * const restrict retarray,
 	 either as a row or a column matrix. We want both cases to
 	 work. */
       rxstride = rystride = GFC_DESCRIPTOR_STRIDE(retarray,0);
-      rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
+      rxstride_bytes = rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
     }
   else
     {
       rxstride = GFC_DESCRIPTOR_STRIDE(retarray,0);
       rystride = GFC_DESCRIPTOR_STRIDE(retarray,1);
+      rxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
       rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,1);
     }
 
@@ -2604,6 +2626,7 @@ matmul_i1 (gfc_array_m1 * const restrict retarray,
       /* Treat it as a a row matrix A[1,count]. */
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = 1;
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = sizeof (GFC_UINTEGER_1);
 
       xcount = 1;
@@ -2613,6 +2636,7 @@ matmul_i1 (gfc_array_m1 * const restrict retarray,
     {
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = GFC_DESCRIPTOR_STRIDE(a,1);
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,1);
 
       count = GFC_DESCRIPTOR_EXTENT(a,1);
@@ -2631,17 +2655,20 @@ matmul_i1 (gfc_array_m1 * const restrict retarray,
     {
       /* Treat it as a column matrix B[count,1] */
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
 
       /* bystride should never be used for 1-dimensional b.
          The value is only used for calculation of the
          memory by the buffer.  */
       bystride = 256;
+      bystride_bytes = 99999999;
       ycount = 1;
     }
   else
     {
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
       bystride = GFC_DESCRIPTOR_STRIDE(b,1);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
       bystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,1);
       ycount = GFC_DESCRIPTOR_EXTENT(b,1);
     }
@@ -2701,12 +2728,11 @@ matmul_i1 (gfc_array_m1 * const restrict retarray,
 
 	 from netlib.org, translated to C, and modified for matmul.m4.  */
 
-      const GFC_UINTEGER_1 *a, *b;
       GFC_UINTEGER_1 *c;
       const index_type m = xcount, n = ycount, k = count;
 
       /* System generated locals */
-      index_type a_dim1, b_dim1, c_dim1,
+      index_type a_dim1, b_dim1,
 		 i1, i2, i3, i4, i5, i6;
 
       /* Local variables */
@@ -2716,25 +2742,22 @@ matmul_i1 (gfc_array_m1 * const restrict retarray,
       index_type isec, jsec, lsec, uisec, ujsec, ulsec;
       GFC_UINTEGER_1 *t1;
 
-      a = abase;
-      b = bbase;
       c = retarray->base_addr;
 
       /* Parameter adjustments */
-      c_dim1 = rystride;
       a_dim1 = aystride;
       b_dim1 = bystride;
 
 #define A_ARRAY_ELEM(i,j) \
-    a[(i) + (j) * a_dim1]
+    (ARRAY_ELEM_AT_OFFSET (abase, (i) * sizeof (GFC_UINTEGER_1) + (j) * aystride_bytes))
 
 #define B_ARRAY_ELEM(i,j) \
-    b[(i) + (j) * b_dim1]
+    (ARRAY_ELEM_AT_OFFSET (bbase, (i) * sizeof (GFC_UINTEGER_1) + (j) * bystride_bytes))
 
 #define C_ARRAY_ELEM(i,j) \
-    c[(i) + (j) * c_dim1]
+    (ARRAY_ELEM_AT_OFFSET (c, (i) * sizeof (GFC_UINTEGER_1) + (j) * rystride_bytes))
 
-      /* Empty c first.  */
+      /* Empty result first.  */
       for (j=0; j<n; j++)
 	for (i=0; i<m; i++)
 	  C_ARRAY_ELEM (i, j) = (GFC_UINTEGER_1)0;
@@ -2982,11 +3005,11 @@ matmul_i1 (gfc_array_m1 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
-	      dest_y = &dest[y*rystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	      dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	      for (x = 0; x < xcount; x++)
 		{
-		  abase_x = &abase[x*axstride];
+		  abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 		  s = (GFC_UINTEGER_1) 0;
 		  for (n = 0; n < count; n++)
 		    s += abase_x[n] * bbase_y[n];
@@ -3001,11 +3024,11 @@ matmul_i1 (gfc_array_m1 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	      s = (GFC_UINTEGER_1) 0;
 	      for (n = 0; n < count; n++)
 		s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n];
-	      dest[y*rystride] = s;
+	      ARRAY_ELEM_AT_OFFSET (dest, y * rystride_bytes) = s;
 	    }
 	}
     }
@@ -3016,10 +3039,11 @@ matmul_i1 (gfc_array_m1 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	  s = (GFC_UINTEGER_1) 0;
 	  for (n = 0; n < count; n++)
-	    s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n*bxstride];
+	    s += GFC_DESCRIPTOR1_ELEM (a, n)
+	         * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
 	  GFC_DESCRIPTOR1_ELEM (retarray, y) = s;
 	}
     }
@@ -3046,15 +3070,16 @@ matmul_i1 (gfc_array_m1 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
-	  dest_y = &dest[y*rystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	  dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	  for (x = 0; x < xcount; x++)
 	    {
-	      abase_x = &abase[x*axstride];
+	      abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 	      s = (GFC_UINTEGER_1) 0;
 	      for (n = 0; n < count; n++)
-		s += abase_x[n*aystride] * bbase_y[n*bxstride];
-	      dest_y[x*rxstride] = s;
+		s += ARRAY_ELEM_AT_OFFSET (abase_x, n * aystride_bytes)
+		     * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
+	      ARRAY_ELEM_AT_OFFSET (dest_y, x * rxstride_bytes) = s;
 	    }
 	}
     }
diff --git a/libgfortran/generated/matmul_i16.c b/libgfortran/generated/matmul_i16.c
index 6b96733436cd..aedf424f933f 100644
--- a/libgfortran/generated/matmul_i16.c
+++ b/libgfortran/generated/matmul_i16.c
@@ -94,7 +94,8 @@ matmul_i16_avx (gfc_array_m16 * const restrict retarray,
 
   index_type rxstride, rystride, axstride, aystride, bxstride, bystride;
   index_type x, y, n, count, xcount, ycount;
-  index_type aystride_bytes, bystride_bytes, rystride_bytes;
+  index_type axstride_bytes, aystride_bytes, bxstride_bytes, bystride_bytes,
+	     rxstride_bytes, rystride_bytes;
 
   assert (GFC_DESCRIPTOR_RANK (a) == 2
           || GFC_DESCRIPTOR_RANK (b) == 2);
@@ -183,12 +184,13 @@ matmul_i16_avx (gfc_array_m16 * const restrict retarray,
 	 either as a row or a column matrix. We want both cases to
 	 work. */
       rxstride = rystride = GFC_DESCRIPTOR_STRIDE(retarray,0);
-      rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
+      rxstride_bytes = rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
     }
   else
     {
       rxstride = GFC_DESCRIPTOR_STRIDE(retarray,0);
       rystride = GFC_DESCRIPTOR_STRIDE(retarray,1);
+      rxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
       rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,1);
     }
 
@@ -197,6 +199,7 @@ matmul_i16_avx (gfc_array_m16 * const restrict retarray,
       /* Treat it as a a row matrix A[1,count]. */
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = 1;
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = sizeof (GFC_UINTEGER_16);
 
       xcount = 1;
@@ -206,6 +209,7 @@ matmul_i16_avx (gfc_array_m16 * const restrict retarray,
     {
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = GFC_DESCRIPTOR_STRIDE(a,1);
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,1);
 
       count = GFC_DESCRIPTOR_EXTENT(a,1);
@@ -224,17 +228,20 @@ matmul_i16_avx (gfc_array_m16 * const restrict retarray,
     {
       /* Treat it as a column matrix B[count,1] */
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
 
       /* bystride should never be used for 1-dimensional b.
          The value is only used for calculation of the
          memory by the buffer.  */
       bystride = 256;
+      bystride_bytes = 99999999;
       ycount = 1;
     }
   else
     {
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
       bystride = GFC_DESCRIPTOR_STRIDE(b,1);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
       bystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,1);
       ycount = GFC_DESCRIPTOR_EXTENT(b,1);
     }
@@ -294,12 +301,11 @@ matmul_i16_avx (gfc_array_m16 * const restrict retarray,
 
 	 from netlib.org, translated to C, and modified for matmul.m4.  */
 
-      const GFC_UINTEGER_16 *a, *b;
       GFC_UINTEGER_16 *c;
       const index_type m = xcount, n = ycount, k = count;
 
       /* System generated locals */
-      index_type a_dim1, b_dim1, c_dim1,
+      index_type a_dim1, b_dim1,
 		 i1, i2, i3, i4, i5, i6;
 
       /* Local variables */
@@ -309,25 +315,22 @@ matmul_i16_avx (gfc_array_m16 * const restrict retarray,
       index_type isec, jsec, lsec, uisec, ujsec, ulsec;
       GFC_UINTEGER_16 *t1;
 
-      a = abase;
-      b = bbase;
       c = retarray->base_addr;
 
       /* Parameter adjustments */
-      c_dim1 = rystride;
       a_dim1 = aystride;
       b_dim1 = bystride;
 
 #define A_ARRAY_ELEM(i,j) \
-    a[(i) + (j) * a_dim1]
+    (ARRAY_ELEM_AT_OFFSET (abase, (i) * sizeof (GFC_UINTEGER_16) + (j) * aystride_bytes))
 
 #define B_ARRAY_ELEM(i,j) \
-    b[(i) + (j) * b_dim1]
+    (ARRAY_ELEM_AT_OFFSET (bbase, (i) * sizeof (GFC_UINTEGER_16) + (j) * bystride_bytes))
 
 #define C_ARRAY_ELEM(i,j) \
-    c[(i) + (j) * c_dim1]
+    (ARRAY_ELEM_AT_OFFSET (c, (i) * sizeof (GFC_UINTEGER_16) + (j) * rystride_bytes))
 
-      /* Empty c first.  */
+      /* Empty result first.  */
       for (j=0; j<n; j++)
 	for (i=0; i<m; i++)
 	  C_ARRAY_ELEM (i, j) = (GFC_UINTEGER_16)0;
@@ -575,11 +578,11 @@ matmul_i16_avx (gfc_array_m16 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
-	      dest_y = &dest[y*rystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	      dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	      for (x = 0; x < xcount; x++)
 		{
-		  abase_x = &abase[x*axstride];
+		  abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 		  s = (GFC_UINTEGER_16) 0;
 		  for (n = 0; n < count; n++)
 		    s += abase_x[n] * bbase_y[n];
@@ -594,11 +597,11 @@ matmul_i16_avx (gfc_array_m16 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	      s = (GFC_UINTEGER_16) 0;
 	      for (n = 0; n < count; n++)
 		s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n];
-	      dest[y*rystride] = s;
+	      ARRAY_ELEM_AT_OFFSET (dest, y * rystride_bytes) = s;
 	    }
 	}
     }
@@ -609,10 +612,11 @@ matmul_i16_avx (gfc_array_m16 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	  s = (GFC_UINTEGER_16) 0;
 	  for (n = 0; n < count; n++)
-	    s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n*bxstride];
+	    s += GFC_DESCRIPTOR1_ELEM (a, n)
+	         * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
 	  GFC_DESCRIPTOR1_ELEM (retarray, y) = s;
 	}
     }
@@ -639,15 +643,16 @@ matmul_i16_avx (gfc_array_m16 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
-	  dest_y = &dest[y*rystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	  dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	  for (x = 0; x < xcount; x++)
 	    {
-	      abase_x = &abase[x*axstride];
+	      abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 	      s = (GFC_UINTEGER_16) 0;
 	      for (n = 0; n < count; n++)
-		s += abase_x[n*aystride] * bbase_y[n*bxstride];
-	      dest_y[x*rxstride] = s;
+		s += ARRAY_ELEM_AT_OFFSET (abase_x, n * aystride_bytes)
+		     * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
+	      ARRAY_ELEM_AT_OFFSET (dest_y, x * rxstride_bytes) = s;
 	    }
 	}
     }
@@ -674,7 +679,8 @@ matmul_i16_avx2 (gfc_array_m16 * const restrict retarray,
 
   index_type rxstride, rystride, axstride, aystride, bxstride, bystride;
   index_type x, y, n, count, xcount, ycount;
-  index_type aystride_bytes, bystride_bytes, rystride_bytes;
+  index_type axstride_bytes, aystride_bytes, bxstride_bytes, bystride_bytes,
+	     rxstride_bytes, rystride_bytes;
 
   assert (GFC_DESCRIPTOR_RANK (a) == 2
           || GFC_DESCRIPTOR_RANK (b) == 2);
@@ -763,12 +769,13 @@ matmul_i16_avx2 (gfc_array_m16 * const restrict retarray,
 	 either as a row or a column matrix. We want both cases to
 	 work. */
       rxstride = rystride = GFC_DESCRIPTOR_STRIDE(retarray,0);
-      rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
+      rxstride_bytes = rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
     }
   else
     {
       rxstride = GFC_DESCRIPTOR_STRIDE(retarray,0);
       rystride = GFC_DESCRIPTOR_STRIDE(retarray,1);
+      rxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
       rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,1);
     }
 
@@ -777,6 +784,7 @@ matmul_i16_avx2 (gfc_array_m16 * const restrict retarray,
       /* Treat it as a a row matrix A[1,count]. */
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = 1;
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = sizeof (GFC_UINTEGER_16);
 
       xcount = 1;
@@ -786,6 +794,7 @@ matmul_i16_avx2 (gfc_array_m16 * const restrict retarray,
     {
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = GFC_DESCRIPTOR_STRIDE(a,1);
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,1);
 
       count = GFC_DESCRIPTOR_EXTENT(a,1);
@@ -804,17 +813,20 @@ matmul_i16_avx2 (gfc_array_m16 * const restrict retarray,
     {
       /* Treat it as a column matrix B[count,1] */
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
 
       /* bystride should never be used for 1-dimensional b.
          The value is only used for calculation of the
          memory by the buffer.  */
       bystride = 256;
+      bystride_bytes = 99999999;
       ycount = 1;
     }
   else
     {
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
       bystride = GFC_DESCRIPTOR_STRIDE(b,1);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
       bystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,1);
       ycount = GFC_DESCRIPTOR_EXTENT(b,1);
     }
@@ -874,12 +886,11 @@ matmul_i16_avx2 (gfc_array_m16 * const restrict retarray,
 
 	 from netlib.org, translated to C, and modified for matmul.m4.  */
 
-      const GFC_UINTEGER_16 *a, *b;
       GFC_UINTEGER_16 *c;
       const index_type m = xcount, n = ycount, k = count;
 
       /* System generated locals */
-      index_type a_dim1, b_dim1, c_dim1,
+      index_type a_dim1, b_dim1,
 		 i1, i2, i3, i4, i5, i6;
 
       /* Local variables */
@@ -889,25 +900,22 @@ matmul_i16_avx2 (gfc_array_m16 * const restrict retarray,
       index_type isec, jsec, lsec, uisec, ujsec, ulsec;
       GFC_UINTEGER_16 *t1;
 
-      a = abase;
-      b = bbase;
       c = retarray->base_addr;
 
       /* Parameter adjustments */
-      c_dim1 = rystride;
       a_dim1 = aystride;
       b_dim1 = bystride;
 
 #define A_ARRAY_ELEM(i,j) \
-    a[(i) + (j) * a_dim1]
+    (ARRAY_ELEM_AT_OFFSET (abase, (i) * sizeof (GFC_UINTEGER_16) + (j) * aystride_bytes))
 
 #define B_ARRAY_ELEM(i,j) \
-    b[(i) + (j) * b_dim1]
+    (ARRAY_ELEM_AT_OFFSET (bbase, (i) * sizeof (GFC_UINTEGER_16) + (j) * bystride_bytes))
 
 #define C_ARRAY_ELEM(i,j) \
-    c[(i) + (j) * c_dim1]
+    (ARRAY_ELEM_AT_OFFSET (c, (i) * sizeof (GFC_UINTEGER_16) + (j) * rystride_bytes))
 
-      /* Empty c first.  */
+      /* Empty result first.  */
       for (j=0; j<n; j++)
 	for (i=0; i<m; i++)
 	  C_ARRAY_ELEM (i, j) = (GFC_UINTEGER_16)0;
@@ -1155,11 +1163,11 @@ matmul_i16_avx2 (gfc_array_m16 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
-	      dest_y = &dest[y*rystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	      dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	      for (x = 0; x < xcount; x++)
 		{
-		  abase_x = &abase[x*axstride];
+		  abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 		  s = (GFC_UINTEGER_16) 0;
 		  for (n = 0; n < count; n++)
 		    s += abase_x[n] * bbase_y[n];
@@ -1174,11 +1182,11 @@ matmul_i16_avx2 (gfc_array_m16 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	      s = (GFC_UINTEGER_16) 0;
 	      for (n = 0; n < count; n++)
 		s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n];
-	      dest[y*rystride] = s;
+	      ARRAY_ELEM_AT_OFFSET (dest, y * rystride_bytes) = s;
 	    }
 	}
     }
@@ -1189,10 +1197,11 @@ matmul_i16_avx2 (gfc_array_m16 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	  s = (GFC_UINTEGER_16) 0;
 	  for (n = 0; n < count; n++)
-	    s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n*bxstride];
+	    s += GFC_DESCRIPTOR1_ELEM (a, n)
+	         * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
 	  GFC_DESCRIPTOR1_ELEM (retarray, y) = s;
 	}
     }
@@ -1219,15 +1228,16 @@ matmul_i16_avx2 (gfc_array_m16 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
-	  dest_y = &dest[y*rystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	  dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	  for (x = 0; x < xcount; x++)
 	    {
-	      abase_x = &abase[x*axstride];
+	      abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 	      s = (GFC_UINTEGER_16) 0;
 	      for (n = 0; n < count; n++)
-		s += abase_x[n*aystride] * bbase_y[n*bxstride];
-	      dest_y[x*rxstride] = s;
+		s += ARRAY_ELEM_AT_OFFSET (abase_x, n * aystride_bytes)
+		     * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
+	      ARRAY_ELEM_AT_OFFSET (dest_y, x * rxstride_bytes) = s;
 	    }
 	}
     }
@@ -1254,7 +1264,8 @@ matmul_i16_avx512f (gfc_array_m16 * const restrict retarray,
 
   index_type rxstride, rystride, axstride, aystride, bxstride, bystride;
   index_type x, y, n, count, xcount, ycount;
-  index_type aystride_bytes, bystride_bytes, rystride_bytes;
+  index_type axstride_bytes, aystride_bytes, bxstride_bytes, bystride_bytes,
+	     rxstride_bytes, rystride_bytes;
 
   assert (GFC_DESCRIPTOR_RANK (a) == 2
           || GFC_DESCRIPTOR_RANK (b) == 2);
@@ -1343,12 +1354,13 @@ matmul_i16_avx512f (gfc_array_m16 * const restrict retarray,
 	 either as a row or a column matrix. We want both cases to
 	 work. */
       rxstride = rystride = GFC_DESCRIPTOR_STRIDE(retarray,0);
-      rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
+      rxstride_bytes = rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
     }
   else
     {
       rxstride = GFC_DESCRIPTOR_STRIDE(retarray,0);
       rystride = GFC_DESCRIPTOR_STRIDE(retarray,1);
+      rxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
       rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,1);
     }
 
@@ -1357,6 +1369,7 @@ matmul_i16_avx512f (gfc_array_m16 * const restrict retarray,
       /* Treat it as a a row matrix A[1,count]. */
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = 1;
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = sizeof (GFC_UINTEGER_16);
 
       xcount = 1;
@@ -1366,6 +1379,7 @@ matmul_i16_avx512f (gfc_array_m16 * const restrict retarray,
     {
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = GFC_DESCRIPTOR_STRIDE(a,1);
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,1);
 
       count = GFC_DESCRIPTOR_EXTENT(a,1);
@@ -1384,17 +1398,20 @@ matmul_i16_avx512f (gfc_array_m16 * const restrict retarray,
     {
       /* Treat it as a column matrix B[count,1] */
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
 
       /* bystride should never be used for 1-dimensional b.
          The value is only used for calculation of the
          memory by the buffer.  */
       bystride = 256;
+      bystride_bytes = 99999999;
       ycount = 1;
     }
   else
     {
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
       bystride = GFC_DESCRIPTOR_STRIDE(b,1);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
       bystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,1);
       ycount = GFC_DESCRIPTOR_EXTENT(b,1);
     }
@@ -1454,12 +1471,11 @@ matmul_i16_avx512f (gfc_array_m16 * const restrict retarray,
 
 	 from netlib.org, translated to C, and modified for matmul.m4.  */
 
-      const GFC_UINTEGER_16 *a, *b;
       GFC_UINTEGER_16 *c;
       const index_type m = xcount, n = ycount, k = count;
 
       /* System generated locals */
-      index_type a_dim1, b_dim1, c_dim1,
+      index_type a_dim1, b_dim1,
 		 i1, i2, i3, i4, i5, i6;
 
       /* Local variables */
@@ -1469,25 +1485,22 @@ matmul_i16_avx512f (gfc_array_m16 * const restrict retarray,
       index_type isec, jsec, lsec, uisec, ujsec, ulsec;
       GFC_UINTEGER_16 *t1;
 
-      a = abase;
-      b = bbase;
       c = retarray->base_addr;
 
       /* Parameter adjustments */
-      c_dim1 = rystride;
       a_dim1 = aystride;
       b_dim1 = bystride;
 
 #define A_ARRAY_ELEM(i,j) \
-    a[(i) + (j) * a_dim1]
+    (ARRAY_ELEM_AT_OFFSET (abase, (i) * sizeof (GFC_UINTEGER_16) + (j) * aystride_bytes))
 
 #define B_ARRAY_ELEM(i,j) \
-    b[(i) + (j) * b_dim1]
+    (ARRAY_ELEM_AT_OFFSET (bbase, (i) * sizeof (GFC_UINTEGER_16) + (j) * bystride_bytes))
 
 #define C_ARRAY_ELEM(i,j) \
-    c[(i) + (j) * c_dim1]
+    (ARRAY_ELEM_AT_OFFSET (c, (i) * sizeof (GFC_UINTEGER_16) + (j) * rystride_bytes))
 
-      /* Empty c first.  */
+      /* Empty result first.  */
       for (j=0; j<n; j++)
 	for (i=0; i<m; i++)
 	  C_ARRAY_ELEM (i, j) = (GFC_UINTEGER_16)0;
@@ -1735,11 +1748,11 @@ matmul_i16_avx512f (gfc_array_m16 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
-	      dest_y = &dest[y*rystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	      dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	      for (x = 0; x < xcount; x++)
 		{
-		  abase_x = &abase[x*axstride];
+		  abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 		  s = (GFC_UINTEGER_16) 0;
 		  for (n = 0; n < count; n++)
 		    s += abase_x[n] * bbase_y[n];
@@ -1754,11 +1767,11 @@ matmul_i16_avx512f (gfc_array_m16 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	      s = (GFC_UINTEGER_16) 0;
 	      for (n = 0; n < count; n++)
 		s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n];
-	      dest[y*rystride] = s;
+	      ARRAY_ELEM_AT_OFFSET (dest, y * rystride_bytes) = s;
 	    }
 	}
     }
@@ -1769,10 +1782,11 @@ matmul_i16_avx512f (gfc_array_m16 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	  s = (GFC_UINTEGER_16) 0;
 	  for (n = 0; n < count; n++)
-	    s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n*bxstride];
+	    s += GFC_DESCRIPTOR1_ELEM (a, n)
+	         * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
 	  GFC_DESCRIPTOR1_ELEM (retarray, y) = s;
 	}
     }
@@ -1799,15 +1813,16 @@ matmul_i16_avx512f (gfc_array_m16 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
-	  dest_y = &dest[y*rystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	  dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	  for (x = 0; x < xcount; x++)
 	    {
-	      abase_x = &abase[x*axstride];
+	      abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 	      s = (GFC_UINTEGER_16) 0;
 	      for (n = 0; n < count; n++)
-		s += abase_x[n*aystride] * bbase_y[n*bxstride];
-	      dest_y[x*rxstride] = s;
+		s += ARRAY_ELEM_AT_OFFSET (abase_x, n * aystride_bytes)
+		     * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
+	      ARRAY_ELEM_AT_OFFSET (dest_y, x * rxstride_bytes) = s;
 	    }
 	}
     }
@@ -1848,7 +1863,8 @@ matmul_i16_vanilla (gfc_array_m16 * const restrict retarray,
 
   index_type rxstride, rystride, axstride, aystride, bxstride, bystride;
   index_type x, y, n, count, xcount, ycount;
-  index_type aystride_bytes, bystride_bytes, rystride_bytes;
+  index_type axstride_bytes, aystride_bytes, bxstride_bytes, bystride_bytes,
+	     rxstride_bytes, rystride_bytes;
 
   assert (GFC_DESCRIPTOR_RANK (a) == 2
           || GFC_DESCRIPTOR_RANK (b) == 2);
@@ -1937,12 +1953,13 @@ matmul_i16_vanilla (gfc_array_m16 * const restrict retarray,
 	 either as a row or a column matrix. We want both cases to
 	 work. */
       rxstride = rystride = GFC_DESCRIPTOR_STRIDE(retarray,0);
-      rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
+      rxstride_bytes = rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
     }
   else
     {
       rxstride = GFC_DESCRIPTOR_STRIDE(retarray,0);
       rystride = GFC_DESCRIPTOR_STRIDE(retarray,1);
+      rxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
       rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,1);
     }
 
@@ -1951,6 +1968,7 @@ matmul_i16_vanilla (gfc_array_m16 * const restrict retarray,
       /* Treat it as a a row matrix A[1,count]. */
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = 1;
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = sizeof (GFC_UINTEGER_16);
 
       xcount = 1;
@@ -1960,6 +1978,7 @@ matmul_i16_vanilla (gfc_array_m16 * const restrict retarray,
     {
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = GFC_DESCRIPTOR_STRIDE(a,1);
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,1);
 
       count = GFC_DESCRIPTOR_EXTENT(a,1);
@@ -1978,17 +1997,20 @@ matmul_i16_vanilla (gfc_array_m16 * const restrict retarray,
     {
       /* Treat it as a column matrix B[count,1] */
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
 
       /* bystride should never be used for 1-dimensional b.
          The value is only used for calculation of the
          memory by the buffer.  */
       bystride = 256;
+      bystride_bytes = 99999999;
       ycount = 1;
     }
   else
     {
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
       bystride = GFC_DESCRIPTOR_STRIDE(b,1);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
       bystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,1);
       ycount = GFC_DESCRIPTOR_EXTENT(b,1);
     }
@@ -2048,12 +2070,11 @@ matmul_i16_vanilla (gfc_array_m16 * const restrict retarray,
 
 	 from netlib.org, translated to C, and modified for matmul.m4.  */
 
-      const GFC_UINTEGER_16 *a, *b;
       GFC_UINTEGER_16 *c;
       const index_type m = xcount, n = ycount, k = count;
 
       /* System generated locals */
-      index_type a_dim1, b_dim1, c_dim1,
+      index_type a_dim1, b_dim1,
 		 i1, i2, i3, i4, i5, i6;
 
       /* Local variables */
@@ -2063,25 +2084,22 @@ matmul_i16_vanilla (gfc_array_m16 * const restrict retarray,
       index_type isec, jsec, lsec, uisec, ujsec, ulsec;
       GFC_UINTEGER_16 *t1;
 
-      a = abase;
-      b = bbase;
       c = retarray->base_addr;
 
       /* Parameter adjustments */
-      c_dim1 = rystride;
       a_dim1 = aystride;
       b_dim1 = bystride;
 
 #define A_ARRAY_ELEM(i,j) \
-    a[(i) + (j) * a_dim1]
+    (ARRAY_ELEM_AT_OFFSET (abase, (i) * sizeof (GFC_UINTEGER_16) + (j) * aystride_bytes))
 
 #define B_ARRAY_ELEM(i,j) \
-    b[(i) + (j) * b_dim1]
+    (ARRAY_ELEM_AT_OFFSET (bbase, (i) * sizeof (GFC_UINTEGER_16) + (j) * bystride_bytes))
 
 #define C_ARRAY_ELEM(i,j) \
-    c[(i) + (j) * c_dim1]
+    (ARRAY_ELEM_AT_OFFSET (c, (i) * sizeof (GFC_UINTEGER_16) + (j) * rystride_bytes))
 
-      /* Empty c first.  */
+      /* Empty result first.  */
       for (j=0; j<n; j++)
 	for (i=0; i<m; i++)
 	  C_ARRAY_ELEM (i, j) = (GFC_UINTEGER_16)0;
@@ -2329,11 +2347,11 @@ matmul_i16_vanilla (gfc_array_m16 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
-	      dest_y = &dest[y*rystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	      dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	      for (x = 0; x < xcount; x++)
 		{
-		  abase_x = &abase[x*axstride];
+		  abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 		  s = (GFC_UINTEGER_16) 0;
 		  for (n = 0; n < count; n++)
 		    s += abase_x[n] * bbase_y[n];
@@ -2348,11 +2366,11 @@ matmul_i16_vanilla (gfc_array_m16 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	      s = (GFC_UINTEGER_16) 0;
 	      for (n = 0; n < count; n++)
 		s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n];
-	      dest[y*rystride] = s;
+	      ARRAY_ELEM_AT_OFFSET (dest, y * rystride_bytes) = s;
 	    }
 	}
     }
@@ -2363,10 +2381,11 @@ matmul_i16_vanilla (gfc_array_m16 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	  s = (GFC_UINTEGER_16) 0;
 	  for (n = 0; n < count; n++)
-	    s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n*bxstride];
+	    s += GFC_DESCRIPTOR1_ELEM (a, n)
+	         * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
 	  GFC_DESCRIPTOR1_ELEM (retarray, y) = s;
 	}
     }
@@ -2393,15 +2412,16 @@ matmul_i16_vanilla (gfc_array_m16 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
-	  dest_y = &dest[y*rystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	  dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	  for (x = 0; x < xcount; x++)
 	    {
-	      abase_x = &abase[x*axstride];
+	      abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 	      s = (GFC_UINTEGER_16) 0;
 	      for (n = 0; n < count; n++)
-		s += abase_x[n*aystride] * bbase_y[n*bxstride];
-	      dest_y[x*rxstride] = s;
+		s += ARRAY_ELEM_AT_OFFSET (abase_x, n * aystride_bytes)
+		     * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
+	      ARRAY_ELEM_AT_OFFSET (dest_y, x * rxstride_bytes) = s;
 	    }
 	}
     }
@@ -2501,7 +2521,8 @@ matmul_i16 (gfc_array_m16 * const restrict retarray,
 
   index_type rxstride, rystride, axstride, aystride, bxstride, bystride;
   index_type x, y, n, count, xcount, ycount;
-  index_type aystride_bytes, bystride_bytes, rystride_bytes;
+  index_type axstride_bytes, aystride_bytes, bxstride_bytes, bystride_bytes,
+	     rxstride_bytes, rystride_bytes;
 
   assert (GFC_DESCRIPTOR_RANK (a) == 2
           || GFC_DESCRIPTOR_RANK (b) == 2);
@@ -2590,12 +2611,13 @@ matmul_i16 (gfc_array_m16 * const restrict retarray,
 	 either as a row or a column matrix. We want both cases to
 	 work. */
       rxstride = rystride = GFC_DESCRIPTOR_STRIDE(retarray,0);
-      rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
+      rxstride_bytes = rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
     }
   else
     {
       rxstride = GFC_DESCRIPTOR_STRIDE(retarray,0);
       rystride = GFC_DESCRIPTOR_STRIDE(retarray,1);
+      rxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
       rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,1);
     }
 
@@ -2604,6 +2626,7 @@ matmul_i16 (gfc_array_m16 * const restrict retarray,
       /* Treat it as a a row matrix A[1,count]. */
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = 1;
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = sizeof (GFC_UINTEGER_16);
 
       xcount = 1;
@@ -2613,6 +2636,7 @@ matmul_i16 (gfc_array_m16 * const restrict retarray,
     {
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = GFC_DESCRIPTOR_STRIDE(a,1);
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,1);
 
       count = GFC_DESCRIPTOR_EXTENT(a,1);
@@ -2631,17 +2655,20 @@ matmul_i16 (gfc_array_m16 * const restrict retarray,
     {
       /* Treat it as a column matrix B[count,1] */
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
 
       /* bystride should never be used for 1-dimensional b.
          The value is only used for calculation of the
          memory by the buffer.  */
       bystride = 256;
+      bystride_bytes = 99999999;
       ycount = 1;
     }
   else
     {
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
       bystride = GFC_DESCRIPTOR_STRIDE(b,1);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
       bystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,1);
       ycount = GFC_DESCRIPTOR_EXTENT(b,1);
     }
@@ -2701,12 +2728,11 @@ matmul_i16 (gfc_array_m16 * const restrict retarray,
 
 	 from netlib.org, translated to C, and modified for matmul.m4.  */
 
-      const GFC_UINTEGER_16 *a, *b;
       GFC_UINTEGER_16 *c;
       const index_type m = xcount, n = ycount, k = count;
 
       /* System generated locals */
-      index_type a_dim1, b_dim1, c_dim1,
+      index_type a_dim1, b_dim1,
 		 i1, i2, i3, i4, i5, i6;
 
       /* Local variables */
@@ -2716,25 +2742,22 @@ matmul_i16 (gfc_array_m16 * const restrict retarray,
       index_type isec, jsec, lsec, uisec, ujsec, ulsec;
       GFC_UINTEGER_16 *t1;
 
-      a = abase;
-      b = bbase;
       c = retarray->base_addr;
 
       /* Parameter adjustments */
-      c_dim1 = rystride;
       a_dim1 = aystride;
       b_dim1 = bystride;
 
 #define A_ARRAY_ELEM(i,j) \
-    a[(i) + (j) * a_dim1]
+    (ARRAY_ELEM_AT_OFFSET (abase, (i) * sizeof (GFC_UINTEGER_16) + (j) * aystride_bytes))
 
 #define B_ARRAY_ELEM(i,j) \
-    b[(i) + (j) * b_dim1]
+    (ARRAY_ELEM_AT_OFFSET (bbase, (i) * sizeof (GFC_UINTEGER_16) + (j) * bystride_bytes))
 
 #define C_ARRAY_ELEM(i,j) \
-    c[(i) + (j) * c_dim1]
+    (ARRAY_ELEM_AT_OFFSET (c, (i) * sizeof (GFC_UINTEGER_16) + (j) * rystride_bytes))
 
-      /* Empty c first.  */
+      /* Empty result first.  */
       for (j=0; j<n; j++)
 	for (i=0; i<m; i++)
 	  C_ARRAY_ELEM (i, j) = (GFC_UINTEGER_16)0;
@@ -2982,11 +3005,11 @@ matmul_i16 (gfc_array_m16 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
-	      dest_y = &dest[y*rystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	      dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	      for (x = 0; x < xcount; x++)
 		{
-		  abase_x = &abase[x*axstride];
+		  abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 		  s = (GFC_UINTEGER_16) 0;
 		  for (n = 0; n < count; n++)
 		    s += abase_x[n] * bbase_y[n];
@@ -3001,11 +3024,11 @@ matmul_i16 (gfc_array_m16 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	      s = (GFC_UINTEGER_16) 0;
 	      for (n = 0; n < count; n++)
 		s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n];
-	      dest[y*rystride] = s;
+	      ARRAY_ELEM_AT_OFFSET (dest, y * rystride_bytes) = s;
 	    }
 	}
     }
@@ -3016,10 +3039,11 @@ matmul_i16 (gfc_array_m16 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	  s = (GFC_UINTEGER_16) 0;
 	  for (n = 0; n < count; n++)
-	    s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n*bxstride];
+	    s += GFC_DESCRIPTOR1_ELEM (a, n)
+	         * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
 	  GFC_DESCRIPTOR1_ELEM (retarray, y) = s;
 	}
     }
@@ -3046,15 +3070,16 @@ matmul_i16 (gfc_array_m16 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
-	  dest_y = &dest[y*rystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	  dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	  for (x = 0; x < xcount; x++)
 	    {
-	      abase_x = &abase[x*axstride];
+	      abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 	      s = (GFC_UINTEGER_16) 0;
 	      for (n = 0; n < count; n++)
-		s += abase_x[n*aystride] * bbase_y[n*bxstride];
-	      dest_y[x*rxstride] = s;
+		s += ARRAY_ELEM_AT_OFFSET (abase_x, n * aystride_bytes)
+		     * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
+	      ARRAY_ELEM_AT_OFFSET (dest_y, x * rxstride_bytes) = s;
 	    }
 	}
     }
diff --git a/libgfortran/generated/matmul_i2.c b/libgfortran/generated/matmul_i2.c
index d3c85c4f5b14..2dc463c6ff67 100644
--- a/libgfortran/generated/matmul_i2.c
+++ b/libgfortran/generated/matmul_i2.c
@@ -94,7 +94,8 @@ matmul_i2_avx (gfc_array_m2 * const restrict retarray,
 
   index_type rxstride, rystride, axstride, aystride, bxstride, bystride;
   index_type x, y, n, count, xcount, ycount;
-  index_type aystride_bytes, bystride_bytes, rystride_bytes;
+  index_type axstride_bytes, aystride_bytes, bxstride_bytes, bystride_bytes,
+	     rxstride_bytes, rystride_bytes;
 
   assert (GFC_DESCRIPTOR_RANK (a) == 2
           || GFC_DESCRIPTOR_RANK (b) == 2);
@@ -183,12 +184,13 @@ matmul_i2_avx (gfc_array_m2 * const restrict retarray,
 	 either as a row or a column matrix. We want both cases to
 	 work. */
       rxstride = rystride = GFC_DESCRIPTOR_STRIDE(retarray,0);
-      rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
+      rxstride_bytes = rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
     }
   else
     {
       rxstride = GFC_DESCRIPTOR_STRIDE(retarray,0);
       rystride = GFC_DESCRIPTOR_STRIDE(retarray,1);
+      rxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
       rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,1);
     }
 
@@ -197,6 +199,7 @@ matmul_i2_avx (gfc_array_m2 * const restrict retarray,
       /* Treat it as a a row matrix A[1,count]. */
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = 1;
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = sizeof (GFC_UINTEGER_2);
 
       xcount = 1;
@@ -206,6 +209,7 @@ matmul_i2_avx (gfc_array_m2 * const restrict retarray,
     {
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = GFC_DESCRIPTOR_STRIDE(a,1);
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,1);
 
       count = GFC_DESCRIPTOR_EXTENT(a,1);
@@ -224,17 +228,20 @@ matmul_i2_avx (gfc_array_m2 * const restrict retarray,
     {
       /* Treat it as a column matrix B[count,1] */
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
 
       /* bystride should never be used for 1-dimensional b.
          The value is only used for calculation of the
          memory by the buffer.  */
       bystride = 256;
+      bystride_bytes = 99999999;
       ycount = 1;
     }
   else
     {
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
       bystride = GFC_DESCRIPTOR_STRIDE(b,1);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
       bystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,1);
       ycount = GFC_DESCRIPTOR_EXTENT(b,1);
     }
@@ -294,12 +301,11 @@ matmul_i2_avx (gfc_array_m2 * const restrict retarray,
 
 	 from netlib.org, translated to C, and modified for matmul.m4.  */
 
-      const GFC_UINTEGER_2 *a, *b;
       GFC_UINTEGER_2 *c;
       const index_type m = xcount, n = ycount, k = count;
 
       /* System generated locals */
-      index_type a_dim1, b_dim1, c_dim1,
+      index_type a_dim1, b_dim1,
 		 i1, i2, i3, i4, i5, i6;
 
       /* Local variables */
@@ -309,25 +315,22 @@ matmul_i2_avx (gfc_array_m2 * const restrict retarray,
       index_type isec, jsec, lsec, uisec, ujsec, ulsec;
       GFC_UINTEGER_2 *t1;
 
-      a = abase;
-      b = bbase;
       c = retarray->base_addr;
 
       /* Parameter adjustments */
-      c_dim1 = rystride;
       a_dim1 = aystride;
       b_dim1 = bystride;
 
 #define A_ARRAY_ELEM(i,j) \
-    a[(i) + (j) * a_dim1]
+    (ARRAY_ELEM_AT_OFFSET (abase, (i) * sizeof (GFC_UINTEGER_2) + (j) * aystride_bytes))
 
 #define B_ARRAY_ELEM(i,j) \
-    b[(i) + (j) * b_dim1]
+    (ARRAY_ELEM_AT_OFFSET (bbase, (i) * sizeof (GFC_UINTEGER_2) + (j) * bystride_bytes))
 
 #define C_ARRAY_ELEM(i,j) \
-    c[(i) + (j) * c_dim1]
+    (ARRAY_ELEM_AT_OFFSET (c, (i) * sizeof (GFC_UINTEGER_2) + (j) * rystride_bytes))
 
-      /* Empty c first.  */
+      /* Empty result first.  */
       for (j=0; j<n; j++)
 	for (i=0; i<m; i++)
 	  C_ARRAY_ELEM (i, j) = (GFC_UINTEGER_2)0;
@@ -575,11 +578,11 @@ matmul_i2_avx (gfc_array_m2 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
-	      dest_y = &dest[y*rystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	      dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	      for (x = 0; x < xcount; x++)
 		{
-		  abase_x = &abase[x*axstride];
+		  abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 		  s = (GFC_UINTEGER_2) 0;
 		  for (n = 0; n < count; n++)
 		    s += abase_x[n] * bbase_y[n];
@@ -594,11 +597,11 @@ matmul_i2_avx (gfc_array_m2 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	      s = (GFC_UINTEGER_2) 0;
 	      for (n = 0; n < count; n++)
 		s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n];
-	      dest[y*rystride] = s;
+	      ARRAY_ELEM_AT_OFFSET (dest, y * rystride_bytes) = s;
 	    }
 	}
     }
@@ -609,10 +612,11 @@ matmul_i2_avx (gfc_array_m2 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	  s = (GFC_UINTEGER_2) 0;
 	  for (n = 0; n < count; n++)
-	    s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n*bxstride];
+	    s += GFC_DESCRIPTOR1_ELEM (a, n)
+	         * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
 	  GFC_DESCRIPTOR1_ELEM (retarray, y) = s;
 	}
     }
@@ -639,15 +643,16 @@ matmul_i2_avx (gfc_array_m2 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
-	  dest_y = &dest[y*rystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	  dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	  for (x = 0; x < xcount; x++)
 	    {
-	      abase_x = &abase[x*axstride];
+	      abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 	      s = (GFC_UINTEGER_2) 0;
 	      for (n = 0; n < count; n++)
-		s += abase_x[n*aystride] * bbase_y[n*bxstride];
-	      dest_y[x*rxstride] = s;
+		s += ARRAY_ELEM_AT_OFFSET (abase_x, n * aystride_bytes)
+		     * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
+	      ARRAY_ELEM_AT_OFFSET (dest_y, x * rxstride_bytes) = s;
 	    }
 	}
     }
@@ -674,7 +679,8 @@ matmul_i2_avx2 (gfc_array_m2 * const restrict retarray,
 
   index_type rxstride, rystride, axstride, aystride, bxstride, bystride;
   index_type x, y, n, count, xcount, ycount;
-  index_type aystride_bytes, bystride_bytes, rystride_bytes;
+  index_type axstride_bytes, aystride_bytes, bxstride_bytes, bystride_bytes,
+	     rxstride_bytes, rystride_bytes;
 
   assert (GFC_DESCRIPTOR_RANK (a) == 2
           || GFC_DESCRIPTOR_RANK (b) == 2);
@@ -763,12 +769,13 @@ matmul_i2_avx2 (gfc_array_m2 * const restrict retarray,
 	 either as a row or a column matrix. We want both cases to
 	 work. */
       rxstride = rystride = GFC_DESCRIPTOR_STRIDE(retarray,0);
-      rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
+      rxstride_bytes = rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
     }
   else
     {
       rxstride = GFC_DESCRIPTOR_STRIDE(retarray,0);
       rystride = GFC_DESCRIPTOR_STRIDE(retarray,1);
+      rxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
       rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,1);
     }
 
@@ -777,6 +784,7 @@ matmul_i2_avx2 (gfc_array_m2 * const restrict retarray,
       /* Treat it as a a row matrix A[1,count]. */
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = 1;
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = sizeof (GFC_UINTEGER_2);
 
       xcount = 1;
@@ -786,6 +794,7 @@ matmul_i2_avx2 (gfc_array_m2 * const restrict retarray,
     {
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = GFC_DESCRIPTOR_STRIDE(a,1);
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,1);
 
       count = GFC_DESCRIPTOR_EXTENT(a,1);
@@ -804,17 +813,20 @@ matmul_i2_avx2 (gfc_array_m2 * const restrict retarray,
     {
       /* Treat it as a column matrix B[count,1] */
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
 
       /* bystride should never be used for 1-dimensional b.
          The value is only used for calculation of the
          memory by the buffer.  */
       bystride = 256;
+      bystride_bytes = 99999999;
       ycount = 1;
     }
   else
     {
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
       bystride = GFC_DESCRIPTOR_STRIDE(b,1);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
       bystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,1);
       ycount = GFC_DESCRIPTOR_EXTENT(b,1);
     }
@@ -874,12 +886,11 @@ matmul_i2_avx2 (gfc_array_m2 * const restrict retarray,
 
 	 from netlib.org, translated to C, and modified for matmul.m4.  */
 
-      const GFC_UINTEGER_2 *a, *b;
       GFC_UINTEGER_2 *c;
       const index_type m = xcount, n = ycount, k = count;
 
       /* System generated locals */
-      index_type a_dim1, b_dim1, c_dim1,
+      index_type a_dim1, b_dim1,
 		 i1, i2, i3, i4, i5, i6;
 
       /* Local variables */
@@ -889,25 +900,22 @@ matmul_i2_avx2 (gfc_array_m2 * const restrict retarray,
       index_type isec, jsec, lsec, uisec, ujsec, ulsec;
       GFC_UINTEGER_2 *t1;
 
-      a = abase;
-      b = bbase;
       c = retarray->base_addr;
 
       /* Parameter adjustments */
-      c_dim1 = rystride;
       a_dim1 = aystride;
       b_dim1 = bystride;
 
 #define A_ARRAY_ELEM(i,j) \
-    a[(i) + (j) * a_dim1]
+    (ARRAY_ELEM_AT_OFFSET (abase, (i) * sizeof (GFC_UINTEGER_2) + (j) * aystride_bytes))
 
 #define B_ARRAY_ELEM(i,j) \
-    b[(i) + (j) * b_dim1]
+    (ARRAY_ELEM_AT_OFFSET (bbase, (i) * sizeof (GFC_UINTEGER_2) + (j) * bystride_bytes))
 
 #define C_ARRAY_ELEM(i,j) \
-    c[(i) + (j) * c_dim1]
+    (ARRAY_ELEM_AT_OFFSET (c, (i) * sizeof (GFC_UINTEGER_2) + (j) * rystride_bytes))
 
-      /* Empty c first.  */
+      /* Empty result first.  */
       for (j=0; j<n; j++)
 	for (i=0; i<m; i++)
 	  C_ARRAY_ELEM (i, j) = (GFC_UINTEGER_2)0;
@@ -1155,11 +1163,11 @@ matmul_i2_avx2 (gfc_array_m2 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
-	      dest_y = &dest[y*rystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	      dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	      for (x = 0; x < xcount; x++)
 		{
-		  abase_x = &abase[x*axstride];
+		  abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 		  s = (GFC_UINTEGER_2) 0;
 		  for (n = 0; n < count; n++)
 		    s += abase_x[n] * bbase_y[n];
@@ -1174,11 +1182,11 @@ matmul_i2_avx2 (gfc_array_m2 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	      s = (GFC_UINTEGER_2) 0;
 	      for (n = 0; n < count; n++)
 		s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n];
-	      dest[y*rystride] = s;
+	      ARRAY_ELEM_AT_OFFSET (dest, y * rystride_bytes) = s;
 	    }
 	}
     }
@@ -1189,10 +1197,11 @@ matmul_i2_avx2 (gfc_array_m2 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	  s = (GFC_UINTEGER_2) 0;
 	  for (n = 0; n < count; n++)
-	    s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n*bxstride];
+	    s += GFC_DESCRIPTOR1_ELEM (a, n)
+	         * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
 	  GFC_DESCRIPTOR1_ELEM (retarray, y) = s;
 	}
     }
@@ -1219,15 +1228,16 @@ matmul_i2_avx2 (gfc_array_m2 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
-	  dest_y = &dest[y*rystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	  dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	  for (x = 0; x < xcount; x++)
 	    {
-	      abase_x = &abase[x*axstride];
+	      abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 	      s = (GFC_UINTEGER_2) 0;
 	      for (n = 0; n < count; n++)
-		s += abase_x[n*aystride] * bbase_y[n*bxstride];
-	      dest_y[x*rxstride] = s;
+		s += ARRAY_ELEM_AT_OFFSET (abase_x, n * aystride_bytes)
+		     * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
+	      ARRAY_ELEM_AT_OFFSET (dest_y, x * rxstride_bytes) = s;
 	    }
 	}
     }
@@ -1254,7 +1264,8 @@ matmul_i2_avx512f (gfc_array_m2 * const restrict retarray,
 
   index_type rxstride, rystride, axstride, aystride, bxstride, bystride;
   index_type x, y, n, count, xcount, ycount;
-  index_type aystride_bytes, bystride_bytes, rystride_bytes;
+  index_type axstride_bytes, aystride_bytes, bxstride_bytes, bystride_bytes,
+	     rxstride_bytes, rystride_bytes;
 
   assert (GFC_DESCRIPTOR_RANK (a) == 2
           || GFC_DESCRIPTOR_RANK (b) == 2);
@@ -1343,12 +1354,13 @@ matmul_i2_avx512f (gfc_array_m2 * const restrict retarray,
 	 either as a row or a column matrix. We want both cases to
 	 work. */
       rxstride = rystride = GFC_DESCRIPTOR_STRIDE(retarray,0);
-      rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
+      rxstride_bytes = rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
     }
   else
     {
       rxstride = GFC_DESCRIPTOR_STRIDE(retarray,0);
       rystride = GFC_DESCRIPTOR_STRIDE(retarray,1);
+      rxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
       rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,1);
     }
 
@@ -1357,6 +1369,7 @@ matmul_i2_avx512f (gfc_array_m2 * const restrict retarray,
       /* Treat it as a a row matrix A[1,count]. */
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = 1;
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = sizeof (GFC_UINTEGER_2);
 
       xcount = 1;
@@ -1366,6 +1379,7 @@ matmul_i2_avx512f (gfc_array_m2 * const restrict retarray,
     {
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = GFC_DESCRIPTOR_STRIDE(a,1);
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,1);
 
       count = GFC_DESCRIPTOR_EXTENT(a,1);
@@ -1384,17 +1398,20 @@ matmul_i2_avx512f (gfc_array_m2 * const restrict retarray,
     {
       /* Treat it as a column matrix B[count,1] */
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
 
       /* bystride should never be used for 1-dimensional b.
          The value is only used for calculation of the
          memory by the buffer.  */
       bystride = 256;
+      bystride_bytes = 99999999;
       ycount = 1;
     }
   else
     {
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
       bystride = GFC_DESCRIPTOR_STRIDE(b,1);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
       bystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,1);
       ycount = GFC_DESCRIPTOR_EXTENT(b,1);
     }
@@ -1454,12 +1471,11 @@ matmul_i2_avx512f (gfc_array_m2 * const restrict retarray,
 
 	 from netlib.org, translated to C, and modified for matmul.m4.  */
 
-      const GFC_UINTEGER_2 *a, *b;
       GFC_UINTEGER_2 *c;
       const index_type m = xcount, n = ycount, k = count;
 
       /* System generated locals */
-      index_type a_dim1, b_dim1, c_dim1,
+      index_type a_dim1, b_dim1,
 		 i1, i2, i3, i4, i5, i6;
 
       /* Local variables */
@@ -1469,25 +1485,22 @@ matmul_i2_avx512f (gfc_array_m2 * const restrict retarray,
       index_type isec, jsec, lsec, uisec, ujsec, ulsec;
       GFC_UINTEGER_2 *t1;
 
-      a = abase;
-      b = bbase;
       c = retarray->base_addr;
 
       /* Parameter adjustments */
-      c_dim1 = rystride;
       a_dim1 = aystride;
       b_dim1 = bystride;
 
 #define A_ARRAY_ELEM(i,j) \
-    a[(i) + (j) * a_dim1]
+    (ARRAY_ELEM_AT_OFFSET (abase, (i) * sizeof (GFC_UINTEGER_2) + (j) * aystride_bytes))
 
 #define B_ARRAY_ELEM(i,j) \
-    b[(i) + (j) * b_dim1]
+    (ARRAY_ELEM_AT_OFFSET (bbase, (i) * sizeof (GFC_UINTEGER_2) + (j) * bystride_bytes))
 
 #define C_ARRAY_ELEM(i,j) \
-    c[(i) + (j) * c_dim1]
+    (ARRAY_ELEM_AT_OFFSET (c, (i) * sizeof (GFC_UINTEGER_2) + (j) * rystride_bytes))
 
-      /* Empty c first.  */
+      /* Empty result first.  */
       for (j=0; j<n; j++)
 	for (i=0; i<m; i++)
 	  C_ARRAY_ELEM (i, j) = (GFC_UINTEGER_2)0;
@@ -1735,11 +1748,11 @@ matmul_i2_avx512f (gfc_array_m2 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
-	      dest_y = &dest[y*rystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	      dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	      for (x = 0; x < xcount; x++)
 		{
-		  abase_x = &abase[x*axstride];
+		  abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 		  s = (GFC_UINTEGER_2) 0;
 		  for (n = 0; n < count; n++)
 		    s += abase_x[n] * bbase_y[n];
@@ -1754,11 +1767,11 @@ matmul_i2_avx512f (gfc_array_m2 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	      s = (GFC_UINTEGER_2) 0;
 	      for (n = 0; n < count; n++)
 		s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n];
-	      dest[y*rystride] = s;
+	      ARRAY_ELEM_AT_OFFSET (dest, y * rystride_bytes) = s;
 	    }
 	}
     }
@@ -1769,10 +1782,11 @@ matmul_i2_avx512f (gfc_array_m2 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	  s = (GFC_UINTEGER_2) 0;
 	  for (n = 0; n < count; n++)
-	    s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n*bxstride];
+	    s += GFC_DESCRIPTOR1_ELEM (a, n)
+	         * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
 	  GFC_DESCRIPTOR1_ELEM (retarray, y) = s;
 	}
     }
@@ -1799,15 +1813,16 @@ matmul_i2_avx512f (gfc_array_m2 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
-	  dest_y = &dest[y*rystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	  dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	  for (x = 0; x < xcount; x++)
 	    {
-	      abase_x = &abase[x*axstride];
+	      abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 	      s = (GFC_UINTEGER_2) 0;
 	      for (n = 0; n < count; n++)
-		s += abase_x[n*aystride] * bbase_y[n*bxstride];
-	      dest_y[x*rxstride] = s;
+		s += ARRAY_ELEM_AT_OFFSET (abase_x, n * aystride_bytes)
+		     * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
+	      ARRAY_ELEM_AT_OFFSET (dest_y, x * rxstride_bytes) = s;
 	    }
 	}
     }
@@ -1848,7 +1863,8 @@ matmul_i2_vanilla (gfc_array_m2 * const restrict retarray,
 
   index_type rxstride, rystride, axstride, aystride, bxstride, bystride;
   index_type x, y, n, count, xcount, ycount;
-  index_type aystride_bytes, bystride_bytes, rystride_bytes;
+  index_type axstride_bytes, aystride_bytes, bxstride_bytes, bystride_bytes,
+	     rxstride_bytes, rystride_bytes;
 
   assert (GFC_DESCRIPTOR_RANK (a) == 2
           || GFC_DESCRIPTOR_RANK (b) == 2);
@@ -1937,12 +1953,13 @@ matmul_i2_vanilla (gfc_array_m2 * const restrict retarray,
 	 either as a row or a column matrix. We want both cases to
 	 work. */
       rxstride = rystride = GFC_DESCRIPTOR_STRIDE(retarray,0);
-      rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
+      rxstride_bytes = rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
     }
   else
     {
       rxstride = GFC_DESCRIPTOR_STRIDE(retarray,0);
       rystride = GFC_DESCRIPTOR_STRIDE(retarray,1);
+      rxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
       rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,1);
     }
 
@@ -1951,6 +1968,7 @@ matmul_i2_vanilla (gfc_array_m2 * const restrict retarray,
       /* Treat it as a a row matrix A[1,count]. */
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = 1;
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = sizeof (GFC_UINTEGER_2);
 
       xcount = 1;
@@ -1960,6 +1978,7 @@ matmul_i2_vanilla (gfc_array_m2 * const restrict retarray,
     {
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = GFC_DESCRIPTOR_STRIDE(a,1);
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,1);
 
       count = GFC_DESCRIPTOR_EXTENT(a,1);
@@ -1978,17 +1997,20 @@ matmul_i2_vanilla (gfc_array_m2 * const restrict retarray,
     {
       /* Treat it as a column matrix B[count,1] */
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
 
       /* bystride should never be used for 1-dimensional b.
          The value is only used for calculation of the
          memory by the buffer.  */
       bystride = 256;
+      bystride_bytes = 99999999;
       ycount = 1;
     }
   else
     {
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
       bystride = GFC_DESCRIPTOR_STRIDE(b,1);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
       bystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,1);
       ycount = GFC_DESCRIPTOR_EXTENT(b,1);
     }
@@ -2048,12 +2070,11 @@ matmul_i2_vanilla (gfc_array_m2 * const restrict retarray,
 
 	 from netlib.org, translated to C, and modified for matmul.m4.  */
 
-      const GFC_UINTEGER_2 *a, *b;
       GFC_UINTEGER_2 *c;
       const index_type m = xcount, n = ycount, k = count;
 
       /* System generated locals */
-      index_type a_dim1, b_dim1, c_dim1,
+      index_type a_dim1, b_dim1,
 		 i1, i2, i3, i4, i5, i6;
 
       /* Local variables */
@@ -2063,25 +2084,22 @@ matmul_i2_vanilla (gfc_array_m2 * const restrict retarray,
       index_type isec, jsec, lsec, uisec, ujsec, ulsec;
       GFC_UINTEGER_2 *t1;
 
-      a = abase;
-      b = bbase;
       c = retarray->base_addr;
 
       /* Parameter adjustments */
-      c_dim1 = rystride;
       a_dim1 = aystride;
       b_dim1 = bystride;
 
 #define A_ARRAY_ELEM(i,j) \
-    a[(i) + (j) * a_dim1]
+    (ARRAY_ELEM_AT_OFFSET (abase, (i) * sizeof (GFC_UINTEGER_2) + (j) * aystride_bytes))
 
 #define B_ARRAY_ELEM(i,j) \
-    b[(i) + (j) * b_dim1]
+    (ARRAY_ELEM_AT_OFFSET (bbase, (i) * sizeof (GFC_UINTEGER_2) + (j) * bystride_bytes))
 
 #define C_ARRAY_ELEM(i,j) \
-    c[(i) + (j) * c_dim1]
+    (ARRAY_ELEM_AT_OFFSET (c, (i) * sizeof (GFC_UINTEGER_2) + (j) * rystride_bytes))
 
-      /* Empty c first.  */
+      /* Empty result first.  */
       for (j=0; j<n; j++)
 	for (i=0; i<m; i++)
 	  C_ARRAY_ELEM (i, j) = (GFC_UINTEGER_2)0;
@@ -2329,11 +2347,11 @@ matmul_i2_vanilla (gfc_array_m2 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
-	      dest_y = &dest[y*rystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	      dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	      for (x = 0; x < xcount; x++)
 		{
-		  abase_x = &abase[x*axstride];
+		  abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 		  s = (GFC_UINTEGER_2) 0;
 		  for (n = 0; n < count; n++)
 		    s += abase_x[n] * bbase_y[n];
@@ -2348,11 +2366,11 @@ matmul_i2_vanilla (gfc_array_m2 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	      s = (GFC_UINTEGER_2) 0;
 	      for (n = 0; n < count; n++)
 		s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n];
-	      dest[y*rystride] = s;
+	      ARRAY_ELEM_AT_OFFSET (dest, y * rystride_bytes) = s;
 	    }
 	}
     }
@@ -2363,10 +2381,11 @@ matmul_i2_vanilla (gfc_array_m2 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	  s = (GFC_UINTEGER_2) 0;
 	  for (n = 0; n < count; n++)
-	    s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n*bxstride];
+	    s += GFC_DESCRIPTOR1_ELEM (a, n)
+	         * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
 	  GFC_DESCRIPTOR1_ELEM (retarray, y) = s;
 	}
     }
@@ -2393,15 +2412,16 @@ matmul_i2_vanilla (gfc_array_m2 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
-	  dest_y = &dest[y*rystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	  dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	  for (x = 0; x < xcount; x++)
 	    {
-	      abase_x = &abase[x*axstride];
+	      abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 	      s = (GFC_UINTEGER_2) 0;
 	      for (n = 0; n < count; n++)
-		s += abase_x[n*aystride] * bbase_y[n*bxstride];
-	      dest_y[x*rxstride] = s;
+		s += ARRAY_ELEM_AT_OFFSET (abase_x, n * aystride_bytes)
+		     * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
+	      ARRAY_ELEM_AT_OFFSET (dest_y, x * rxstride_bytes) = s;
 	    }
 	}
     }
@@ -2501,7 +2521,8 @@ matmul_i2 (gfc_array_m2 * const restrict retarray,
 
   index_type rxstride, rystride, axstride, aystride, bxstride, bystride;
   index_type x, y, n, count, xcount, ycount;
-  index_type aystride_bytes, bystride_bytes, rystride_bytes;
+  index_type axstride_bytes, aystride_bytes, bxstride_bytes, bystride_bytes,
+	     rxstride_bytes, rystride_bytes;
 
   assert (GFC_DESCRIPTOR_RANK (a) == 2
           || GFC_DESCRIPTOR_RANK (b) == 2);
@@ -2590,12 +2611,13 @@ matmul_i2 (gfc_array_m2 * const restrict retarray,
 	 either as a row or a column matrix. We want both cases to
 	 work. */
       rxstride = rystride = GFC_DESCRIPTOR_STRIDE(retarray,0);
-      rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
+      rxstride_bytes = rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
     }
   else
     {
       rxstride = GFC_DESCRIPTOR_STRIDE(retarray,0);
       rystride = GFC_DESCRIPTOR_STRIDE(retarray,1);
+      rxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
       rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,1);
     }
 
@@ -2604,6 +2626,7 @@ matmul_i2 (gfc_array_m2 * const restrict retarray,
       /* Treat it as a a row matrix A[1,count]. */
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = 1;
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = sizeof (GFC_UINTEGER_2);
 
       xcount = 1;
@@ -2613,6 +2636,7 @@ matmul_i2 (gfc_array_m2 * const restrict retarray,
     {
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = GFC_DESCRIPTOR_STRIDE(a,1);
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,1);
 
       count = GFC_DESCRIPTOR_EXTENT(a,1);
@@ -2631,17 +2655,20 @@ matmul_i2 (gfc_array_m2 * const restrict retarray,
     {
       /* Treat it as a column matrix B[count,1] */
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
 
       /* bystride should never be used for 1-dimensional b.
          The value is only used for calculation of the
          memory by the buffer.  */
       bystride = 256;
+      bystride_bytes = 99999999;
       ycount = 1;
     }
   else
     {
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
       bystride = GFC_DESCRIPTOR_STRIDE(b,1);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
       bystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,1);
       ycount = GFC_DESCRIPTOR_EXTENT(b,1);
     }
@@ -2701,12 +2728,11 @@ matmul_i2 (gfc_array_m2 * const restrict retarray,
 
 	 from netlib.org, translated to C, and modified for matmul.m4.  */
 
-      const GFC_UINTEGER_2 *a, *b;
       GFC_UINTEGER_2 *c;
       const index_type m = xcount, n = ycount, k = count;
 
       /* System generated locals */
-      index_type a_dim1, b_dim1, c_dim1,
+      index_type a_dim1, b_dim1,
 		 i1, i2, i3, i4, i5, i6;
 
       /* Local variables */
@@ -2716,25 +2742,22 @@ matmul_i2 (gfc_array_m2 * const restrict retarray,
       index_type isec, jsec, lsec, uisec, ujsec, ulsec;
       GFC_UINTEGER_2 *t1;
 
-      a = abase;
-      b = bbase;
       c = retarray->base_addr;
 
       /* Parameter adjustments */
-      c_dim1 = rystride;
       a_dim1 = aystride;
       b_dim1 = bystride;
 
 #define A_ARRAY_ELEM(i,j) \
-    a[(i) + (j) * a_dim1]
+    (ARRAY_ELEM_AT_OFFSET (abase, (i) * sizeof (GFC_UINTEGER_2) + (j) * aystride_bytes))
 
 #define B_ARRAY_ELEM(i,j) \
-    b[(i) + (j) * b_dim1]
+    (ARRAY_ELEM_AT_OFFSET (bbase, (i) * sizeof (GFC_UINTEGER_2) + (j) * bystride_bytes))
 
 #define C_ARRAY_ELEM(i,j) \
-    c[(i) + (j) * c_dim1]
+    (ARRAY_ELEM_AT_OFFSET (c, (i) * sizeof (GFC_UINTEGER_2) + (j) * rystride_bytes))
 
-      /* Empty c first.  */
+      /* Empty result first.  */
       for (j=0; j<n; j++)
 	for (i=0; i<m; i++)
 	  C_ARRAY_ELEM (i, j) = (GFC_UINTEGER_2)0;
@@ -2982,11 +3005,11 @@ matmul_i2 (gfc_array_m2 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
-	      dest_y = &dest[y*rystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	      dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	      for (x = 0; x < xcount; x++)
 		{
-		  abase_x = &abase[x*axstride];
+		  abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 		  s = (GFC_UINTEGER_2) 0;
 		  for (n = 0; n < count; n++)
 		    s += abase_x[n] * bbase_y[n];
@@ -3001,11 +3024,11 @@ matmul_i2 (gfc_array_m2 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	      s = (GFC_UINTEGER_2) 0;
 	      for (n = 0; n < count; n++)
 		s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n];
-	      dest[y*rystride] = s;
+	      ARRAY_ELEM_AT_OFFSET (dest, y * rystride_bytes) = s;
 	    }
 	}
     }
@@ -3016,10 +3039,11 @@ matmul_i2 (gfc_array_m2 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	  s = (GFC_UINTEGER_2) 0;
 	  for (n = 0; n < count; n++)
-	    s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n*bxstride];
+	    s += GFC_DESCRIPTOR1_ELEM (a, n)
+	         * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
 	  GFC_DESCRIPTOR1_ELEM (retarray, y) = s;
 	}
     }
@@ -3046,15 +3070,16 @@ matmul_i2 (gfc_array_m2 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
-	  dest_y = &dest[y*rystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	  dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	  for (x = 0; x < xcount; x++)
 	    {
-	      abase_x = &abase[x*axstride];
+	      abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 	      s = (GFC_UINTEGER_2) 0;
 	      for (n = 0; n < count; n++)
-		s += abase_x[n*aystride] * bbase_y[n*bxstride];
-	      dest_y[x*rxstride] = s;
+		s += ARRAY_ELEM_AT_OFFSET (abase_x, n * aystride_bytes)
+		     * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
+	      ARRAY_ELEM_AT_OFFSET (dest_y, x * rxstride_bytes) = s;
 	    }
 	}
     }
diff --git a/libgfortran/generated/matmul_i4.c b/libgfortran/generated/matmul_i4.c
index 09dc488e7b90..ca9b2dc41d7d 100644
--- a/libgfortran/generated/matmul_i4.c
+++ b/libgfortran/generated/matmul_i4.c
@@ -94,7 +94,8 @@ matmul_i4_avx (gfc_array_m4 * const restrict retarray,
 
   index_type rxstride, rystride, axstride, aystride, bxstride, bystride;
   index_type x, y, n, count, xcount, ycount;
-  index_type aystride_bytes, bystride_bytes, rystride_bytes;
+  index_type axstride_bytes, aystride_bytes, bxstride_bytes, bystride_bytes,
+	     rxstride_bytes, rystride_bytes;
 
   assert (GFC_DESCRIPTOR_RANK (a) == 2
           || GFC_DESCRIPTOR_RANK (b) == 2);
@@ -183,12 +184,13 @@ matmul_i4_avx (gfc_array_m4 * const restrict retarray,
 	 either as a row or a column matrix. We want both cases to
 	 work. */
       rxstride = rystride = GFC_DESCRIPTOR_STRIDE(retarray,0);
-      rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
+      rxstride_bytes = rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
     }
   else
     {
       rxstride = GFC_DESCRIPTOR_STRIDE(retarray,0);
       rystride = GFC_DESCRIPTOR_STRIDE(retarray,1);
+      rxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
       rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,1);
     }
 
@@ -197,6 +199,7 @@ matmul_i4_avx (gfc_array_m4 * const restrict retarray,
       /* Treat it as a a row matrix A[1,count]. */
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = 1;
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = sizeof (GFC_UINTEGER_4);
 
       xcount = 1;
@@ -206,6 +209,7 @@ matmul_i4_avx (gfc_array_m4 * const restrict retarray,
     {
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = GFC_DESCRIPTOR_STRIDE(a,1);
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,1);
 
       count = GFC_DESCRIPTOR_EXTENT(a,1);
@@ -224,17 +228,20 @@ matmul_i4_avx (gfc_array_m4 * const restrict retarray,
     {
       /* Treat it as a column matrix B[count,1] */
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
 
       /* bystride should never be used for 1-dimensional b.
          The value is only used for calculation of the
          memory by the buffer.  */
       bystride = 256;
+      bystride_bytes = 99999999;
       ycount = 1;
     }
   else
     {
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
       bystride = GFC_DESCRIPTOR_STRIDE(b,1);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
       bystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,1);
       ycount = GFC_DESCRIPTOR_EXTENT(b,1);
     }
@@ -294,12 +301,11 @@ matmul_i4_avx (gfc_array_m4 * const restrict retarray,
 
 	 from netlib.org, translated to C, and modified for matmul.m4.  */
 
-      const GFC_UINTEGER_4 *a, *b;
       GFC_UINTEGER_4 *c;
       const index_type m = xcount, n = ycount, k = count;
 
       /* System generated locals */
-      index_type a_dim1, b_dim1, c_dim1,
+      index_type a_dim1, b_dim1,
 		 i1, i2, i3, i4, i5, i6;
 
       /* Local variables */
@@ -309,25 +315,22 @@ matmul_i4_avx (gfc_array_m4 * const restrict retarray,
       index_type isec, jsec, lsec, uisec, ujsec, ulsec;
       GFC_UINTEGER_4 *t1;
 
-      a = abase;
-      b = bbase;
       c = retarray->base_addr;
 
       /* Parameter adjustments */
-      c_dim1 = rystride;
       a_dim1 = aystride;
       b_dim1 = bystride;
 
 #define A_ARRAY_ELEM(i,j) \
-    a[(i) + (j) * a_dim1]
+    (ARRAY_ELEM_AT_OFFSET (abase, (i) * sizeof (GFC_UINTEGER_4) + (j) * aystride_bytes))
 
 #define B_ARRAY_ELEM(i,j) \
-    b[(i) + (j) * b_dim1]
+    (ARRAY_ELEM_AT_OFFSET (bbase, (i) * sizeof (GFC_UINTEGER_4) + (j) * bystride_bytes))
 
 #define C_ARRAY_ELEM(i,j) \
-    c[(i) + (j) * c_dim1]
+    (ARRAY_ELEM_AT_OFFSET (c, (i) * sizeof (GFC_UINTEGER_4) + (j) * rystride_bytes))
 
-      /* Empty c first.  */
+      /* Empty result first.  */
       for (j=0; j<n; j++)
 	for (i=0; i<m; i++)
 	  C_ARRAY_ELEM (i, j) = (GFC_UINTEGER_4)0;
@@ -575,11 +578,11 @@ matmul_i4_avx (gfc_array_m4 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
-	      dest_y = &dest[y*rystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	      dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	      for (x = 0; x < xcount; x++)
 		{
-		  abase_x = &abase[x*axstride];
+		  abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 		  s = (GFC_UINTEGER_4) 0;
 		  for (n = 0; n < count; n++)
 		    s += abase_x[n] * bbase_y[n];
@@ -594,11 +597,11 @@ matmul_i4_avx (gfc_array_m4 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	      s = (GFC_UINTEGER_4) 0;
 	      for (n = 0; n < count; n++)
 		s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n];
-	      dest[y*rystride] = s;
+	      ARRAY_ELEM_AT_OFFSET (dest, y * rystride_bytes) = s;
 	    }
 	}
     }
@@ -609,10 +612,11 @@ matmul_i4_avx (gfc_array_m4 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	  s = (GFC_UINTEGER_4) 0;
 	  for (n = 0; n < count; n++)
-	    s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n*bxstride];
+	    s += GFC_DESCRIPTOR1_ELEM (a, n)
+	         * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
 	  GFC_DESCRIPTOR1_ELEM (retarray, y) = s;
 	}
     }
@@ -639,15 +643,16 @@ matmul_i4_avx (gfc_array_m4 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
-	  dest_y = &dest[y*rystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	  dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	  for (x = 0; x < xcount; x++)
 	    {
-	      abase_x = &abase[x*axstride];
+	      abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 	      s = (GFC_UINTEGER_4) 0;
 	      for (n = 0; n < count; n++)
-		s += abase_x[n*aystride] * bbase_y[n*bxstride];
-	      dest_y[x*rxstride] = s;
+		s += ARRAY_ELEM_AT_OFFSET (abase_x, n * aystride_bytes)
+		     * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
+	      ARRAY_ELEM_AT_OFFSET (dest_y, x * rxstride_bytes) = s;
 	    }
 	}
     }
@@ -674,7 +679,8 @@ matmul_i4_avx2 (gfc_array_m4 * const restrict retarray,
 
   index_type rxstride, rystride, axstride, aystride, bxstride, bystride;
   index_type x, y, n, count, xcount, ycount;
-  index_type aystride_bytes, bystride_bytes, rystride_bytes;
+  index_type axstride_bytes, aystride_bytes, bxstride_bytes, bystride_bytes,
+	     rxstride_bytes, rystride_bytes;
 
   assert (GFC_DESCRIPTOR_RANK (a) == 2
           || GFC_DESCRIPTOR_RANK (b) == 2);
@@ -763,12 +769,13 @@ matmul_i4_avx2 (gfc_array_m4 * const restrict retarray,
 	 either as a row or a column matrix. We want both cases to
 	 work. */
       rxstride = rystride = GFC_DESCRIPTOR_STRIDE(retarray,0);
-      rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
+      rxstride_bytes = rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
     }
   else
     {
       rxstride = GFC_DESCRIPTOR_STRIDE(retarray,0);
       rystride = GFC_DESCRIPTOR_STRIDE(retarray,1);
+      rxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
       rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,1);
     }
 
@@ -777,6 +784,7 @@ matmul_i4_avx2 (gfc_array_m4 * const restrict retarray,
       /* Treat it as a a row matrix A[1,count]. */
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = 1;
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = sizeof (GFC_UINTEGER_4);
 
       xcount = 1;
@@ -786,6 +794,7 @@ matmul_i4_avx2 (gfc_array_m4 * const restrict retarray,
     {
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = GFC_DESCRIPTOR_STRIDE(a,1);
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,1);
 
       count = GFC_DESCRIPTOR_EXTENT(a,1);
@@ -804,17 +813,20 @@ matmul_i4_avx2 (gfc_array_m4 * const restrict retarray,
     {
       /* Treat it as a column matrix B[count,1] */
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
 
       /* bystride should never be used for 1-dimensional b.
          The value is only used for calculation of the
          memory by the buffer.  */
       bystride = 256;
+      bystride_bytes = 99999999;
       ycount = 1;
     }
   else
     {
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
       bystride = GFC_DESCRIPTOR_STRIDE(b,1);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
       bystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,1);
       ycount = GFC_DESCRIPTOR_EXTENT(b,1);
     }
@@ -874,12 +886,11 @@ matmul_i4_avx2 (gfc_array_m4 * const restrict retarray,
 
 	 from netlib.org, translated to C, and modified for matmul.m4.  */
 
-      const GFC_UINTEGER_4 *a, *b;
       GFC_UINTEGER_4 *c;
       const index_type m = xcount, n = ycount, k = count;
 
       /* System generated locals */
-      index_type a_dim1, b_dim1, c_dim1,
+      index_type a_dim1, b_dim1,
 		 i1, i2, i3, i4, i5, i6;
 
       /* Local variables */
@@ -889,25 +900,22 @@ matmul_i4_avx2 (gfc_array_m4 * const restrict retarray,
       index_type isec, jsec, lsec, uisec, ujsec, ulsec;
       GFC_UINTEGER_4 *t1;
 
-      a = abase;
-      b = bbase;
       c = retarray->base_addr;
 
       /* Parameter adjustments */
-      c_dim1 = rystride;
       a_dim1 = aystride;
       b_dim1 = bystride;
 
 #define A_ARRAY_ELEM(i,j) \
-    a[(i) + (j) * a_dim1]
+    (ARRAY_ELEM_AT_OFFSET (abase, (i) * sizeof (GFC_UINTEGER_4) + (j) * aystride_bytes))
 
 #define B_ARRAY_ELEM(i,j) \
-    b[(i) + (j) * b_dim1]
+    (ARRAY_ELEM_AT_OFFSET (bbase, (i) * sizeof (GFC_UINTEGER_4) + (j) * bystride_bytes))
 
 #define C_ARRAY_ELEM(i,j) \
-    c[(i) + (j) * c_dim1]
+    (ARRAY_ELEM_AT_OFFSET (c, (i) * sizeof (GFC_UINTEGER_4) + (j) * rystride_bytes))
 
-      /* Empty c first.  */
+      /* Empty result first.  */
       for (j=0; j<n; j++)
 	for (i=0; i<m; i++)
 	  C_ARRAY_ELEM (i, j) = (GFC_UINTEGER_4)0;
@@ -1155,11 +1163,11 @@ matmul_i4_avx2 (gfc_array_m4 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
-	      dest_y = &dest[y*rystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	      dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	      for (x = 0; x < xcount; x++)
 		{
-		  abase_x = &abase[x*axstride];
+		  abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 		  s = (GFC_UINTEGER_4) 0;
 		  for (n = 0; n < count; n++)
 		    s += abase_x[n] * bbase_y[n];
@@ -1174,11 +1182,11 @@ matmul_i4_avx2 (gfc_array_m4 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	      s = (GFC_UINTEGER_4) 0;
 	      for (n = 0; n < count; n++)
 		s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n];
-	      dest[y*rystride] = s;
+	      ARRAY_ELEM_AT_OFFSET (dest, y * rystride_bytes) = s;
 	    }
 	}
     }
@@ -1189,10 +1197,11 @@ matmul_i4_avx2 (gfc_array_m4 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	  s = (GFC_UINTEGER_4) 0;
 	  for (n = 0; n < count; n++)
-	    s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n*bxstride];
+	    s += GFC_DESCRIPTOR1_ELEM (a, n)
+	         * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
 	  GFC_DESCRIPTOR1_ELEM (retarray, y) = s;
 	}
     }
@@ -1219,15 +1228,16 @@ matmul_i4_avx2 (gfc_array_m4 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
-	  dest_y = &dest[y*rystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	  dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	  for (x = 0; x < xcount; x++)
 	    {
-	      abase_x = &abase[x*axstride];
+	      abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 	      s = (GFC_UINTEGER_4) 0;
 	      for (n = 0; n < count; n++)
-		s += abase_x[n*aystride] * bbase_y[n*bxstride];
-	      dest_y[x*rxstride] = s;
+		s += ARRAY_ELEM_AT_OFFSET (abase_x, n * aystride_bytes)
+		     * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
+	      ARRAY_ELEM_AT_OFFSET (dest_y, x * rxstride_bytes) = s;
 	    }
 	}
     }
@@ -1254,7 +1264,8 @@ matmul_i4_avx512f (gfc_array_m4 * const restrict retarray,
 
   index_type rxstride, rystride, axstride, aystride, bxstride, bystride;
   index_type x, y, n, count, xcount, ycount;
-  index_type aystride_bytes, bystride_bytes, rystride_bytes;
+  index_type axstride_bytes, aystride_bytes, bxstride_bytes, bystride_bytes,
+	     rxstride_bytes, rystride_bytes;
 
   assert (GFC_DESCRIPTOR_RANK (a) == 2
           || GFC_DESCRIPTOR_RANK (b) == 2);
@@ -1343,12 +1354,13 @@ matmul_i4_avx512f (gfc_array_m4 * const restrict retarray,
 	 either as a row or a column matrix. We want both cases to
 	 work. */
       rxstride = rystride = GFC_DESCRIPTOR_STRIDE(retarray,0);
-      rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
+      rxstride_bytes = rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
     }
   else
     {
       rxstride = GFC_DESCRIPTOR_STRIDE(retarray,0);
       rystride = GFC_DESCRIPTOR_STRIDE(retarray,1);
+      rxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
       rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,1);
     }
 
@@ -1357,6 +1369,7 @@ matmul_i4_avx512f (gfc_array_m4 * const restrict retarray,
       /* Treat it as a a row matrix A[1,count]. */
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = 1;
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = sizeof (GFC_UINTEGER_4);
 
       xcount = 1;
@@ -1366,6 +1379,7 @@ matmul_i4_avx512f (gfc_array_m4 * const restrict retarray,
     {
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = GFC_DESCRIPTOR_STRIDE(a,1);
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,1);
 
       count = GFC_DESCRIPTOR_EXTENT(a,1);
@@ -1384,17 +1398,20 @@ matmul_i4_avx512f (gfc_array_m4 * const restrict retarray,
     {
       /* Treat it as a column matrix B[count,1] */
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
 
       /* bystride should never be used for 1-dimensional b.
          The value is only used for calculation of the
          memory by the buffer.  */
       bystride = 256;
+      bystride_bytes = 99999999;
       ycount = 1;
     }
   else
     {
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
       bystride = GFC_DESCRIPTOR_STRIDE(b,1);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
       bystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,1);
       ycount = GFC_DESCRIPTOR_EXTENT(b,1);
     }
@@ -1454,12 +1471,11 @@ matmul_i4_avx512f (gfc_array_m4 * const restrict retarray,
 
 	 from netlib.org, translated to C, and modified for matmul.m4.  */
 
-      const GFC_UINTEGER_4 *a, *b;
       GFC_UINTEGER_4 *c;
       const index_type m = xcount, n = ycount, k = count;
 
       /* System generated locals */
-      index_type a_dim1, b_dim1, c_dim1,
+      index_type a_dim1, b_dim1,
 		 i1, i2, i3, i4, i5, i6;
 
       /* Local variables */
@@ -1469,25 +1485,22 @@ matmul_i4_avx512f (gfc_array_m4 * const restrict retarray,
       index_type isec, jsec, lsec, uisec, ujsec, ulsec;
       GFC_UINTEGER_4 *t1;
 
-      a = abase;
-      b = bbase;
       c = retarray->base_addr;
 
       /* Parameter adjustments */
-      c_dim1 = rystride;
       a_dim1 = aystride;
       b_dim1 = bystride;
 
 #define A_ARRAY_ELEM(i,j) \
-    a[(i) + (j) * a_dim1]
+    (ARRAY_ELEM_AT_OFFSET (abase, (i) * sizeof (GFC_UINTEGER_4) + (j) * aystride_bytes))
 
 #define B_ARRAY_ELEM(i,j) \
-    b[(i) + (j) * b_dim1]
+    (ARRAY_ELEM_AT_OFFSET (bbase, (i) * sizeof (GFC_UINTEGER_4) + (j) * bystride_bytes))
 
 #define C_ARRAY_ELEM(i,j) \
-    c[(i) + (j) * c_dim1]
+    (ARRAY_ELEM_AT_OFFSET (c, (i) * sizeof (GFC_UINTEGER_4) + (j) * rystride_bytes))
 
-      /* Empty c first.  */
+      /* Empty result first.  */
       for (j=0; j<n; j++)
 	for (i=0; i<m; i++)
 	  C_ARRAY_ELEM (i, j) = (GFC_UINTEGER_4)0;
@@ -1735,11 +1748,11 @@ matmul_i4_avx512f (gfc_array_m4 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
-	      dest_y = &dest[y*rystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	      dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	      for (x = 0; x < xcount; x++)
 		{
-		  abase_x = &abase[x*axstride];
+		  abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 		  s = (GFC_UINTEGER_4) 0;
 		  for (n = 0; n < count; n++)
 		    s += abase_x[n] * bbase_y[n];
@@ -1754,11 +1767,11 @@ matmul_i4_avx512f (gfc_array_m4 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	      s = (GFC_UINTEGER_4) 0;
 	      for (n = 0; n < count; n++)
 		s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n];
-	      dest[y*rystride] = s;
+	      ARRAY_ELEM_AT_OFFSET (dest, y * rystride_bytes) = s;
 	    }
 	}
     }
@@ -1769,10 +1782,11 @@ matmul_i4_avx512f (gfc_array_m4 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	  s = (GFC_UINTEGER_4) 0;
 	  for (n = 0; n < count; n++)
-	    s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n*bxstride];
+	    s += GFC_DESCRIPTOR1_ELEM (a, n)
+	         * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
 	  GFC_DESCRIPTOR1_ELEM (retarray, y) = s;
 	}
     }
@@ -1799,15 +1813,16 @@ matmul_i4_avx512f (gfc_array_m4 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
-	  dest_y = &dest[y*rystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	  dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	  for (x = 0; x < xcount; x++)
 	    {
-	      abase_x = &abase[x*axstride];
+	      abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 	      s = (GFC_UINTEGER_4) 0;
 	      for (n = 0; n < count; n++)
-		s += abase_x[n*aystride] * bbase_y[n*bxstride];
-	      dest_y[x*rxstride] = s;
+		s += ARRAY_ELEM_AT_OFFSET (abase_x, n * aystride_bytes)
+		     * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
+	      ARRAY_ELEM_AT_OFFSET (dest_y, x * rxstride_bytes) = s;
 	    }
 	}
     }
@@ -1848,7 +1863,8 @@ matmul_i4_vanilla (gfc_array_m4 * const restrict retarray,
 
   index_type rxstride, rystride, axstride, aystride, bxstride, bystride;
   index_type x, y, n, count, xcount, ycount;
-  index_type aystride_bytes, bystride_bytes, rystride_bytes;
+  index_type axstride_bytes, aystride_bytes, bxstride_bytes, bystride_bytes,
+	     rxstride_bytes, rystride_bytes;
 
   assert (GFC_DESCRIPTOR_RANK (a) == 2
           || GFC_DESCRIPTOR_RANK (b) == 2);
@@ -1937,12 +1953,13 @@ matmul_i4_vanilla (gfc_array_m4 * const restrict retarray,
 	 either as a row or a column matrix. We want both cases to
 	 work. */
       rxstride = rystride = GFC_DESCRIPTOR_STRIDE(retarray,0);
-      rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
+      rxstride_bytes = rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
     }
   else
     {
       rxstride = GFC_DESCRIPTOR_STRIDE(retarray,0);
       rystride = GFC_DESCRIPTOR_STRIDE(retarray,1);
+      rxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
       rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,1);
     }
 
@@ -1951,6 +1968,7 @@ matmul_i4_vanilla (gfc_array_m4 * const restrict retarray,
       /* Treat it as a a row matrix A[1,count]. */
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = 1;
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = sizeof (GFC_UINTEGER_4);
 
       xcount = 1;
@@ -1960,6 +1978,7 @@ matmul_i4_vanilla (gfc_array_m4 * const restrict retarray,
     {
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = GFC_DESCRIPTOR_STRIDE(a,1);
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,1);
 
       count = GFC_DESCRIPTOR_EXTENT(a,1);
@@ -1978,17 +1997,20 @@ matmul_i4_vanilla (gfc_array_m4 * const restrict retarray,
     {
       /* Treat it as a column matrix B[count,1] */
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
 
       /* bystride should never be used for 1-dimensional b.
          The value is only used for calculation of the
          memory by the buffer.  */
       bystride = 256;
+      bystride_bytes = 99999999;
       ycount = 1;
     }
   else
     {
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
       bystride = GFC_DESCRIPTOR_STRIDE(b,1);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
       bystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,1);
       ycount = GFC_DESCRIPTOR_EXTENT(b,1);
     }
@@ -2048,12 +2070,11 @@ matmul_i4_vanilla (gfc_array_m4 * const restrict retarray,
 
 	 from netlib.org, translated to C, and modified for matmul.m4.  */
 
-      const GFC_UINTEGER_4 *a, *b;
       GFC_UINTEGER_4 *c;
       const index_type m = xcount, n = ycount, k = count;
 
       /* System generated locals */
-      index_type a_dim1, b_dim1, c_dim1,
+      index_type a_dim1, b_dim1,
 		 i1, i2, i3, i4, i5, i6;
 
       /* Local variables */
@@ -2063,25 +2084,22 @@ matmul_i4_vanilla (gfc_array_m4 * const restrict retarray,
       index_type isec, jsec, lsec, uisec, ujsec, ulsec;
       GFC_UINTEGER_4 *t1;
 
-      a = abase;
-      b = bbase;
       c = retarray->base_addr;
 
       /* Parameter adjustments */
-      c_dim1 = rystride;
       a_dim1 = aystride;
       b_dim1 = bystride;
 
 #define A_ARRAY_ELEM(i,j) \
-    a[(i) + (j) * a_dim1]
+    (ARRAY_ELEM_AT_OFFSET (abase, (i) * sizeof (GFC_UINTEGER_4) + (j) * aystride_bytes))
 
 #define B_ARRAY_ELEM(i,j) \
-    b[(i) + (j) * b_dim1]
+    (ARRAY_ELEM_AT_OFFSET (bbase, (i) * sizeof (GFC_UINTEGER_4) + (j) * bystride_bytes))
 
 #define C_ARRAY_ELEM(i,j) \
-    c[(i) + (j) * c_dim1]
+    (ARRAY_ELEM_AT_OFFSET (c, (i) * sizeof (GFC_UINTEGER_4) + (j) * rystride_bytes))
 
-      /* Empty c first.  */
+      /* Empty result first.  */
       for (j=0; j<n; j++)
 	for (i=0; i<m; i++)
 	  C_ARRAY_ELEM (i, j) = (GFC_UINTEGER_4)0;
@@ -2329,11 +2347,11 @@ matmul_i4_vanilla (gfc_array_m4 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
-	      dest_y = &dest[y*rystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	      dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	      for (x = 0; x < xcount; x++)
 		{
-		  abase_x = &abase[x*axstride];
+		  abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 		  s = (GFC_UINTEGER_4) 0;
 		  for (n = 0; n < count; n++)
 		    s += abase_x[n] * bbase_y[n];
@@ -2348,11 +2366,11 @@ matmul_i4_vanilla (gfc_array_m4 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	      s = (GFC_UINTEGER_4) 0;
 	      for (n = 0; n < count; n++)
 		s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n];
-	      dest[y*rystride] = s;
+	      ARRAY_ELEM_AT_OFFSET (dest, y * rystride_bytes) = s;
 	    }
 	}
     }
@@ -2363,10 +2381,11 @@ matmul_i4_vanilla (gfc_array_m4 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	  s = (GFC_UINTEGER_4) 0;
 	  for (n = 0; n < count; n++)
-	    s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n*bxstride];
+	    s += GFC_DESCRIPTOR1_ELEM (a, n)
+	         * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
 	  GFC_DESCRIPTOR1_ELEM (retarray, y) = s;
 	}
     }
@@ -2393,15 +2412,16 @@ matmul_i4_vanilla (gfc_array_m4 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
-	  dest_y = &dest[y*rystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	  dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	  for (x = 0; x < xcount; x++)
 	    {
-	      abase_x = &abase[x*axstride];
+	      abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 	      s = (GFC_UINTEGER_4) 0;
 	      for (n = 0; n < count; n++)
-		s += abase_x[n*aystride] * bbase_y[n*bxstride];
-	      dest_y[x*rxstride] = s;
+		s += ARRAY_ELEM_AT_OFFSET (abase_x, n * aystride_bytes)
+		     * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
+	      ARRAY_ELEM_AT_OFFSET (dest_y, x * rxstride_bytes) = s;
 	    }
 	}
     }
@@ -2501,7 +2521,8 @@ matmul_i4 (gfc_array_m4 * const restrict retarray,
 
   index_type rxstride, rystride, axstride, aystride, bxstride, bystride;
   index_type x, y, n, count, xcount, ycount;
-  index_type aystride_bytes, bystride_bytes, rystride_bytes;
+  index_type axstride_bytes, aystride_bytes, bxstride_bytes, bystride_bytes,
+	     rxstride_bytes, rystride_bytes;
 
   assert (GFC_DESCRIPTOR_RANK (a) == 2
           || GFC_DESCRIPTOR_RANK (b) == 2);
@@ -2590,12 +2611,13 @@ matmul_i4 (gfc_array_m4 * const restrict retarray,
 	 either as a row or a column matrix. We want both cases to
 	 work. */
       rxstride = rystride = GFC_DESCRIPTOR_STRIDE(retarray,0);
-      rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
+      rxstride_bytes = rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
     }
   else
     {
       rxstride = GFC_DESCRIPTOR_STRIDE(retarray,0);
       rystride = GFC_DESCRIPTOR_STRIDE(retarray,1);
+      rxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
       rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,1);
     }
 
@@ -2604,6 +2626,7 @@ matmul_i4 (gfc_array_m4 * const restrict retarray,
       /* Treat it as a a row matrix A[1,count]. */
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = 1;
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = sizeof (GFC_UINTEGER_4);
 
       xcount = 1;
@@ -2613,6 +2636,7 @@ matmul_i4 (gfc_array_m4 * const restrict retarray,
     {
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = GFC_DESCRIPTOR_STRIDE(a,1);
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,1);
 
       count = GFC_DESCRIPTOR_EXTENT(a,1);
@@ -2631,17 +2655,20 @@ matmul_i4 (gfc_array_m4 * const restrict retarray,
     {
       /* Treat it as a column matrix B[count,1] */
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
 
       /* bystride should never be used for 1-dimensional b.
          The value is only used for calculation of the
          memory by the buffer.  */
       bystride = 256;
+      bystride_bytes = 99999999;
       ycount = 1;
     }
   else
     {
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
       bystride = GFC_DESCRIPTOR_STRIDE(b,1);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
       bystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,1);
       ycount = GFC_DESCRIPTOR_EXTENT(b,1);
     }
@@ -2701,12 +2728,11 @@ matmul_i4 (gfc_array_m4 * const restrict retarray,
 
 	 from netlib.org, translated to C, and modified for matmul.m4.  */
 
-      const GFC_UINTEGER_4 *a, *b;
       GFC_UINTEGER_4 *c;
       const index_type m = xcount, n = ycount, k = count;
 
       /* System generated locals */
-      index_type a_dim1, b_dim1, c_dim1,
+      index_type a_dim1, b_dim1,
 		 i1, i2, i3, i4, i5, i6;
 
       /* Local variables */
@@ -2716,25 +2742,22 @@ matmul_i4 (gfc_array_m4 * const restrict retarray,
       index_type isec, jsec, lsec, uisec, ujsec, ulsec;
       GFC_UINTEGER_4 *t1;
 
-      a = abase;
-      b = bbase;
       c = retarray->base_addr;
 
       /* Parameter adjustments */
-      c_dim1 = rystride;
       a_dim1 = aystride;
       b_dim1 = bystride;
 
 #define A_ARRAY_ELEM(i,j) \
-    a[(i) + (j) * a_dim1]
+    (ARRAY_ELEM_AT_OFFSET (abase, (i) * sizeof (GFC_UINTEGER_4) + (j) * aystride_bytes))
 
 #define B_ARRAY_ELEM(i,j) \
-    b[(i) + (j) * b_dim1]
+    (ARRAY_ELEM_AT_OFFSET (bbase, (i) * sizeof (GFC_UINTEGER_4) + (j) * bystride_bytes))
 
 #define C_ARRAY_ELEM(i,j) \
-    c[(i) + (j) * c_dim1]
+    (ARRAY_ELEM_AT_OFFSET (c, (i) * sizeof (GFC_UINTEGER_4) + (j) * rystride_bytes))
 
-      /* Empty c first.  */
+      /* Empty result first.  */
       for (j=0; j<n; j++)
 	for (i=0; i<m; i++)
 	  C_ARRAY_ELEM (i, j) = (GFC_UINTEGER_4)0;
@@ -2982,11 +3005,11 @@ matmul_i4 (gfc_array_m4 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
-	      dest_y = &dest[y*rystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	      dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	      for (x = 0; x < xcount; x++)
 		{
-		  abase_x = &abase[x*axstride];
+		  abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 		  s = (GFC_UINTEGER_4) 0;
 		  for (n = 0; n < count; n++)
 		    s += abase_x[n] * bbase_y[n];
@@ -3001,11 +3024,11 @@ matmul_i4 (gfc_array_m4 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	      s = (GFC_UINTEGER_4) 0;
 	      for (n = 0; n < count; n++)
 		s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n];
-	      dest[y*rystride] = s;
+	      ARRAY_ELEM_AT_OFFSET (dest, y * rystride_bytes) = s;
 	    }
 	}
     }
@@ -3016,10 +3039,11 @@ matmul_i4 (gfc_array_m4 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	  s = (GFC_UINTEGER_4) 0;
 	  for (n = 0; n < count; n++)
-	    s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n*bxstride];
+	    s += GFC_DESCRIPTOR1_ELEM (a, n)
+	         * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
 	  GFC_DESCRIPTOR1_ELEM (retarray, y) = s;
 	}
     }
@@ -3046,15 +3070,16 @@ matmul_i4 (gfc_array_m4 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
-	  dest_y = &dest[y*rystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	  dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	  for (x = 0; x < xcount; x++)
 	    {
-	      abase_x = &abase[x*axstride];
+	      abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 	      s = (GFC_UINTEGER_4) 0;
 	      for (n = 0; n < count; n++)
-		s += abase_x[n*aystride] * bbase_y[n*bxstride];
-	      dest_y[x*rxstride] = s;
+		s += ARRAY_ELEM_AT_OFFSET (abase_x, n * aystride_bytes)
+		     * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
+	      ARRAY_ELEM_AT_OFFSET (dest_y, x * rxstride_bytes) = s;
 	    }
 	}
     }
diff --git a/libgfortran/generated/matmul_i8.c b/libgfortran/generated/matmul_i8.c
index 61cdefa99602..a8da3826b658 100644
--- a/libgfortran/generated/matmul_i8.c
+++ b/libgfortran/generated/matmul_i8.c
@@ -94,7 +94,8 @@ matmul_i8_avx (gfc_array_m8 * const restrict retarray,
 
   index_type rxstride, rystride, axstride, aystride, bxstride, bystride;
   index_type x, y, n, count, xcount, ycount;
-  index_type aystride_bytes, bystride_bytes, rystride_bytes;
+  index_type axstride_bytes, aystride_bytes, bxstride_bytes, bystride_bytes,
+	     rxstride_bytes, rystride_bytes;
 
   assert (GFC_DESCRIPTOR_RANK (a) == 2
           || GFC_DESCRIPTOR_RANK (b) == 2);
@@ -183,12 +184,13 @@ matmul_i8_avx (gfc_array_m8 * const restrict retarray,
 	 either as a row or a column matrix. We want both cases to
 	 work. */
       rxstride = rystride = GFC_DESCRIPTOR_STRIDE(retarray,0);
-      rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
+      rxstride_bytes = rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
     }
   else
     {
       rxstride = GFC_DESCRIPTOR_STRIDE(retarray,0);
       rystride = GFC_DESCRIPTOR_STRIDE(retarray,1);
+      rxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
       rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,1);
     }
 
@@ -197,6 +199,7 @@ matmul_i8_avx (gfc_array_m8 * const restrict retarray,
       /* Treat it as a a row matrix A[1,count]. */
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = 1;
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = sizeof (GFC_UINTEGER_8);
 
       xcount = 1;
@@ -206,6 +209,7 @@ matmul_i8_avx (gfc_array_m8 * const restrict retarray,
     {
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = GFC_DESCRIPTOR_STRIDE(a,1);
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,1);
 
       count = GFC_DESCRIPTOR_EXTENT(a,1);
@@ -224,17 +228,20 @@ matmul_i8_avx (gfc_array_m8 * const restrict retarray,
     {
       /* Treat it as a column matrix B[count,1] */
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
 
       /* bystride should never be used for 1-dimensional b.
          The value is only used for calculation of the
          memory by the buffer.  */
       bystride = 256;
+      bystride_bytes = 99999999;
       ycount = 1;
     }
   else
     {
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
       bystride = GFC_DESCRIPTOR_STRIDE(b,1);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
       bystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,1);
       ycount = GFC_DESCRIPTOR_EXTENT(b,1);
     }
@@ -294,12 +301,11 @@ matmul_i8_avx (gfc_array_m8 * const restrict retarray,
 
 	 from netlib.org, translated to C, and modified for matmul.m4.  */
 
-      const GFC_UINTEGER_8 *a, *b;
       GFC_UINTEGER_8 *c;
       const index_type m = xcount, n = ycount, k = count;
 
       /* System generated locals */
-      index_type a_dim1, b_dim1, c_dim1,
+      index_type a_dim1, b_dim1,
 		 i1, i2, i3, i4, i5, i6;
 
       /* Local variables */
@@ -309,25 +315,22 @@ matmul_i8_avx (gfc_array_m8 * const restrict retarray,
       index_type isec, jsec, lsec, uisec, ujsec, ulsec;
       GFC_UINTEGER_8 *t1;
 
-      a = abase;
-      b = bbase;
       c = retarray->base_addr;
 
       /* Parameter adjustments */
-      c_dim1 = rystride;
       a_dim1 = aystride;
       b_dim1 = bystride;
 
 #define A_ARRAY_ELEM(i,j) \
-    a[(i) + (j) * a_dim1]
+    (ARRAY_ELEM_AT_OFFSET (abase, (i) * sizeof (GFC_UINTEGER_8) + (j) * aystride_bytes))
 
 #define B_ARRAY_ELEM(i,j) \
-    b[(i) + (j) * b_dim1]
+    (ARRAY_ELEM_AT_OFFSET (bbase, (i) * sizeof (GFC_UINTEGER_8) + (j) * bystride_bytes))
 
 #define C_ARRAY_ELEM(i,j) \
-    c[(i) + (j) * c_dim1]
+    (ARRAY_ELEM_AT_OFFSET (c, (i) * sizeof (GFC_UINTEGER_8) + (j) * rystride_bytes))
 
-      /* Empty c first.  */
+      /* Empty result first.  */
       for (j=0; j<n; j++)
 	for (i=0; i<m; i++)
 	  C_ARRAY_ELEM (i, j) = (GFC_UINTEGER_8)0;
@@ -575,11 +578,11 @@ matmul_i8_avx (gfc_array_m8 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
-	      dest_y = &dest[y*rystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	      dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	      for (x = 0; x < xcount; x++)
 		{
-		  abase_x = &abase[x*axstride];
+		  abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 		  s = (GFC_UINTEGER_8) 0;
 		  for (n = 0; n < count; n++)
 		    s += abase_x[n] * bbase_y[n];
@@ -594,11 +597,11 @@ matmul_i8_avx (gfc_array_m8 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	      s = (GFC_UINTEGER_8) 0;
 	      for (n = 0; n < count; n++)
 		s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n];
-	      dest[y*rystride] = s;
+	      ARRAY_ELEM_AT_OFFSET (dest, y * rystride_bytes) = s;
 	    }
 	}
     }
@@ -609,10 +612,11 @@ matmul_i8_avx (gfc_array_m8 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	  s = (GFC_UINTEGER_8) 0;
 	  for (n = 0; n < count; n++)
-	    s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n*bxstride];
+	    s += GFC_DESCRIPTOR1_ELEM (a, n)
+	         * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
 	  GFC_DESCRIPTOR1_ELEM (retarray, y) = s;
 	}
     }
@@ -639,15 +643,16 @@ matmul_i8_avx (gfc_array_m8 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
-	  dest_y = &dest[y*rystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	  dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	  for (x = 0; x < xcount; x++)
 	    {
-	      abase_x = &abase[x*axstride];
+	      abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 	      s = (GFC_UINTEGER_8) 0;
 	      for (n = 0; n < count; n++)
-		s += abase_x[n*aystride] * bbase_y[n*bxstride];
-	      dest_y[x*rxstride] = s;
+		s += ARRAY_ELEM_AT_OFFSET (abase_x, n * aystride_bytes)
+		     * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
+	      ARRAY_ELEM_AT_OFFSET (dest_y, x * rxstride_bytes) = s;
 	    }
 	}
     }
@@ -674,7 +679,8 @@ matmul_i8_avx2 (gfc_array_m8 * const restrict retarray,
 
   index_type rxstride, rystride, axstride, aystride, bxstride, bystride;
   index_type x, y, n, count, xcount, ycount;
-  index_type aystride_bytes, bystride_bytes, rystride_bytes;
+  index_type axstride_bytes, aystride_bytes, bxstride_bytes, bystride_bytes,
+	     rxstride_bytes, rystride_bytes;
 
   assert (GFC_DESCRIPTOR_RANK (a) == 2
           || GFC_DESCRIPTOR_RANK (b) == 2);
@@ -763,12 +769,13 @@ matmul_i8_avx2 (gfc_array_m8 * const restrict retarray,
 	 either as a row or a column matrix. We want both cases to
 	 work. */
       rxstride = rystride = GFC_DESCRIPTOR_STRIDE(retarray,0);
-      rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
+      rxstride_bytes = rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
     }
   else
     {
       rxstride = GFC_DESCRIPTOR_STRIDE(retarray,0);
       rystride = GFC_DESCRIPTOR_STRIDE(retarray,1);
+      rxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
       rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,1);
     }
 
@@ -777,6 +784,7 @@ matmul_i8_avx2 (gfc_array_m8 * const restrict retarray,
       /* Treat it as a a row matrix A[1,count]. */
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = 1;
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = sizeof (GFC_UINTEGER_8);
 
       xcount = 1;
@@ -786,6 +794,7 @@ matmul_i8_avx2 (gfc_array_m8 * const restrict retarray,
     {
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = GFC_DESCRIPTOR_STRIDE(a,1);
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,1);
 
       count = GFC_DESCRIPTOR_EXTENT(a,1);
@@ -804,17 +813,20 @@ matmul_i8_avx2 (gfc_array_m8 * const restrict retarray,
     {
       /* Treat it as a column matrix B[count,1] */
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
 
       /* bystride should never be used for 1-dimensional b.
          The value is only used for calculation of the
          memory by the buffer.  */
       bystride = 256;
+      bystride_bytes = 99999999;
       ycount = 1;
     }
   else
     {
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
       bystride = GFC_DESCRIPTOR_STRIDE(b,1);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
       bystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,1);
       ycount = GFC_DESCRIPTOR_EXTENT(b,1);
     }
@@ -874,12 +886,11 @@ matmul_i8_avx2 (gfc_array_m8 * const restrict retarray,
 
 	 from netlib.org, translated to C, and modified for matmul.m4.  */
 
-      const GFC_UINTEGER_8 *a, *b;
       GFC_UINTEGER_8 *c;
       const index_type m = xcount, n = ycount, k = count;
 
       /* System generated locals */
-      index_type a_dim1, b_dim1, c_dim1,
+      index_type a_dim1, b_dim1,
 		 i1, i2, i3, i4, i5, i6;
 
       /* Local variables */
@@ -889,25 +900,22 @@ matmul_i8_avx2 (gfc_array_m8 * const restrict retarray,
       index_type isec, jsec, lsec, uisec, ujsec, ulsec;
       GFC_UINTEGER_8 *t1;
 
-      a = abase;
-      b = bbase;
       c = retarray->base_addr;
 
       /* Parameter adjustments */
-      c_dim1 = rystride;
       a_dim1 = aystride;
       b_dim1 = bystride;
 
 #define A_ARRAY_ELEM(i,j) \
-    a[(i) + (j) * a_dim1]
+    (ARRAY_ELEM_AT_OFFSET (abase, (i) * sizeof (GFC_UINTEGER_8) + (j) * aystride_bytes))
 
 #define B_ARRAY_ELEM(i,j) \
-    b[(i) + (j) * b_dim1]
+    (ARRAY_ELEM_AT_OFFSET (bbase, (i) * sizeof (GFC_UINTEGER_8) + (j) * bystride_bytes))
 
 #define C_ARRAY_ELEM(i,j) \
-    c[(i) + (j) * c_dim1]
+    (ARRAY_ELEM_AT_OFFSET (c, (i) * sizeof (GFC_UINTEGER_8) + (j) * rystride_bytes))
 
-      /* Empty c first.  */
+      /* Empty result first.  */
       for (j=0; j<n; j++)
 	for (i=0; i<m; i++)
 	  C_ARRAY_ELEM (i, j) = (GFC_UINTEGER_8)0;
@@ -1155,11 +1163,11 @@ matmul_i8_avx2 (gfc_array_m8 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
-	      dest_y = &dest[y*rystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	      dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	      for (x = 0; x < xcount; x++)
 		{
-		  abase_x = &abase[x*axstride];
+		  abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 		  s = (GFC_UINTEGER_8) 0;
 		  for (n = 0; n < count; n++)
 		    s += abase_x[n] * bbase_y[n];
@@ -1174,11 +1182,11 @@ matmul_i8_avx2 (gfc_array_m8 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	      s = (GFC_UINTEGER_8) 0;
 	      for (n = 0; n < count; n++)
 		s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n];
-	      dest[y*rystride] = s;
+	      ARRAY_ELEM_AT_OFFSET (dest, y * rystride_bytes) = s;
 	    }
 	}
     }
@@ -1189,10 +1197,11 @@ matmul_i8_avx2 (gfc_array_m8 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	  s = (GFC_UINTEGER_8) 0;
 	  for (n = 0; n < count; n++)
-	    s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n*bxstride];
+	    s += GFC_DESCRIPTOR1_ELEM (a, n)
+	         * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
 	  GFC_DESCRIPTOR1_ELEM (retarray, y) = s;
 	}
     }
@@ -1219,15 +1228,16 @@ matmul_i8_avx2 (gfc_array_m8 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
-	  dest_y = &dest[y*rystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	  dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	  for (x = 0; x < xcount; x++)
 	    {
-	      abase_x = &abase[x*axstride];
+	      abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 	      s = (GFC_UINTEGER_8) 0;
 	      for (n = 0; n < count; n++)
-		s += abase_x[n*aystride] * bbase_y[n*bxstride];
-	      dest_y[x*rxstride] = s;
+		s += ARRAY_ELEM_AT_OFFSET (abase_x, n * aystride_bytes)
+		     * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
+	      ARRAY_ELEM_AT_OFFSET (dest_y, x * rxstride_bytes) = s;
 	    }
 	}
     }
@@ -1254,7 +1264,8 @@ matmul_i8_avx512f (gfc_array_m8 * const restrict retarray,
 
   index_type rxstride, rystride, axstride, aystride, bxstride, bystride;
   index_type x, y, n, count, xcount, ycount;
-  index_type aystride_bytes, bystride_bytes, rystride_bytes;
+  index_type axstride_bytes, aystride_bytes, bxstride_bytes, bystride_bytes,
+	     rxstride_bytes, rystride_bytes;
 
   assert (GFC_DESCRIPTOR_RANK (a) == 2
           || GFC_DESCRIPTOR_RANK (b) == 2);
@@ -1343,12 +1354,13 @@ matmul_i8_avx512f (gfc_array_m8 * const restrict retarray,
 	 either as a row or a column matrix. We want both cases to
 	 work. */
       rxstride = rystride = GFC_DESCRIPTOR_STRIDE(retarray,0);
-      rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
+      rxstride_bytes = rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
     }
   else
     {
       rxstride = GFC_DESCRIPTOR_STRIDE(retarray,0);
       rystride = GFC_DESCRIPTOR_STRIDE(retarray,1);
+      rxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
       rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,1);
     }
 
@@ -1357,6 +1369,7 @@ matmul_i8_avx512f (gfc_array_m8 * const restrict retarray,
       /* Treat it as a a row matrix A[1,count]. */
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = 1;
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = sizeof (GFC_UINTEGER_8);
 
       xcount = 1;
@@ -1366,6 +1379,7 @@ matmul_i8_avx512f (gfc_array_m8 * const restrict retarray,
     {
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = GFC_DESCRIPTOR_STRIDE(a,1);
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,1);
 
       count = GFC_DESCRIPTOR_EXTENT(a,1);
@@ -1384,17 +1398,20 @@ matmul_i8_avx512f (gfc_array_m8 * const restrict retarray,
     {
       /* Treat it as a column matrix B[count,1] */
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
 
       /* bystride should never be used for 1-dimensional b.
          The value is only used for calculation of the
          memory by the buffer.  */
       bystride = 256;
+      bystride_bytes = 99999999;
       ycount = 1;
     }
   else
     {
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
       bystride = GFC_DESCRIPTOR_STRIDE(b,1);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
       bystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,1);
       ycount = GFC_DESCRIPTOR_EXTENT(b,1);
     }
@@ -1454,12 +1471,11 @@ matmul_i8_avx512f (gfc_array_m8 * const restrict retarray,
 
 	 from netlib.org, translated to C, and modified for matmul.m4.  */
 
-      const GFC_UINTEGER_8 *a, *b;
       GFC_UINTEGER_8 *c;
       const index_type m = xcount, n = ycount, k = count;
 
       /* System generated locals */
-      index_type a_dim1, b_dim1, c_dim1,
+      index_type a_dim1, b_dim1,
 		 i1, i2, i3, i4, i5, i6;
 
       /* Local variables */
@@ -1469,25 +1485,22 @@ matmul_i8_avx512f (gfc_array_m8 * const restrict retarray,
       index_type isec, jsec, lsec, uisec, ujsec, ulsec;
       GFC_UINTEGER_8 *t1;
 
-      a = abase;
-      b = bbase;
       c = retarray->base_addr;
 
       /* Parameter adjustments */
-      c_dim1 = rystride;
       a_dim1 = aystride;
       b_dim1 = bystride;
 
 #define A_ARRAY_ELEM(i,j) \
-    a[(i) + (j) * a_dim1]
+    (ARRAY_ELEM_AT_OFFSET (abase, (i) * sizeof (GFC_UINTEGER_8) + (j) * aystride_bytes))
 
 #define B_ARRAY_ELEM(i,j) \
-    b[(i) + (j) * b_dim1]
+    (ARRAY_ELEM_AT_OFFSET (bbase, (i) * sizeof (GFC_UINTEGER_8) + (j) * bystride_bytes))
 
 #define C_ARRAY_ELEM(i,j) \
-    c[(i) + (j) * c_dim1]
+    (ARRAY_ELEM_AT_OFFSET (c, (i) * sizeof (GFC_UINTEGER_8) + (j) * rystride_bytes))
 
-      /* Empty c first.  */
+      /* Empty result first.  */
       for (j=0; j<n; j++)
 	for (i=0; i<m; i++)
 	  C_ARRAY_ELEM (i, j) = (GFC_UINTEGER_8)0;
@@ -1735,11 +1748,11 @@ matmul_i8_avx512f (gfc_array_m8 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
-	      dest_y = &dest[y*rystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	      dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	      for (x = 0; x < xcount; x++)
 		{
-		  abase_x = &abase[x*axstride];
+		  abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 		  s = (GFC_UINTEGER_8) 0;
 		  for (n = 0; n < count; n++)
 		    s += abase_x[n] * bbase_y[n];
@@ -1754,11 +1767,11 @@ matmul_i8_avx512f (gfc_array_m8 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	      s = (GFC_UINTEGER_8) 0;
 	      for (n = 0; n < count; n++)
 		s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n];
-	      dest[y*rystride] = s;
+	      ARRAY_ELEM_AT_OFFSET (dest, y * rystride_bytes) = s;
 	    }
 	}
     }
@@ -1769,10 +1782,11 @@ matmul_i8_avx512f (gfc_array_m8 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	  s = (GFC_UINTEGER_8) 0;
 	  for (n = 0; n < count; n++)
-	    s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n*bxstride];
+	    s += GFC_DESCRIPTOR1_ELEM (a, n)
+	         * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
 	  GFC_DESCRIPTOR1_ELEM (retarray, y) = s;
 	}
     }
@@ -1799,15 +1813,16 @@ matmul_i8_avx512f (gfc_array_m8 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
-	  dest_y = &dest[y*rystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	  dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	  for (x = 0; x < xcount; x++)
 	    {
-	      abase_x = &abase[x*axstride];
+	      abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 	      s = (GFC_UINTEGER_8) 0;
 	      for (n = 0; n < count; n++)
-		s += abase_x[n*aystride] * bbase_y[n*bxstride];
-	      dest_y[x*rxstride] = s;
+		s += ARRAY_ELEM_AT_OFFSET (abase_x, n * aystride_bytes)
+		     * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
+	      ARRAY_ELEM_AT_OFFSET (dest_y, x * rxstride_bytes) = s;
 	    }
 	}
     }
@@ -1848,7 +1863,8 @@ matmul_i8_vanilla (gfc_array_m8 * const restrict retarray,
 
   index_type rxstride, rystride, axstride, aystride, bxstride, bystride;
   index_type x, y, n, count, xcount, ycount;
-  index_type aystride_bytes, bystride_bytes, rystride_bytes;
+  index_type axstride_bytes, aystride_bytes, bxstride_bytes, bystride_bytes,
+	     rxstride_bytes, rystride_bytes;
 
   assert (GFC_DESCRIPTOR_RANK (a) == 2
           || GFC_DESCRIPTOR_RANK (b) == 2);
@@ -1937,12 +1953,13 @@ matmul_i8_vanilla (gfc_array_m8 * const restrict retarray,
 	 either as a row or a column matrix. We want both cases to
 	 work. */
       rxstride = rystride = GFC_DESCRIPTOR_STRIDE(retarray,0);
-      rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
+      rxstride_bytes = rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
     }
   else
     {
       rxstride = GFC_DESCRIPTOR_STRIDE(retarray,0);
       rystride = GFC_DESCRIPTOR_STRIDE(retarray,1);
+      rxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
       rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,1);
     }
 
@@ -1951,6 +1968,7 @@ matmul_i8_vanilla (gfc_array_m8 * const restrict retarray,
       /* Treat it as a a row matrix A[1,count]. */
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = 1;
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = sizeof (GFC_UINTEGER_8);
 
       xcount = 1;
@@ -1960,6 +1978,7 @@ matmul_i8_vanilla (gfc_array_m8 * const restrict retarray,
     {
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = GFC_DESCRIPTOR_STRIDE(a,1);
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,1);
 
       count = GFC_DESCRIPTOR_EXTENT(a,1);
@@ -1978,17 +1997,20 @@ matmul_i8_vanilla (gfc_array_m8 * const restrict retarray,
     {
       /* Treat it as a column matrix B[count,1] */
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
 
       /* bystride should never be used for 1-dimensional b.
          The value is only used for calculation of the
          memory by the buffer.  */
       bystride = 256;
+      bystride_bytes = 99999999;
       ycount = 1;
     }
   else
     {
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
       bystride = GFC_DESCRIPTOR_STRIDE(b,1);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
       bystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,1);
       ycount = GFC_DESCRIPTOR_EXTENT(b,1);
     }
@@ -2048,12 +2070,11 @@ matmul_i8_vanilla (gfc_array_m8 * const restrict retarray,
 
 	 from netlib.org, translated to C, and modified for matmul.m4.  */
 
-      const GFC_UINTEGER_8 *a, *b;
       GFC_UINTEGER_8 *c;
       const index_type m = xcount, n = ycount, k = count;
 
       /* System generated locals */
-      index_type a_dim1, b_dim1, c_dim1,
+      index_type a_dim1, b_dim1,
 		 i1, i2, i3, i4, i5, i6;
 
       /* Local variables */
@@ -2063,25 +2084,22 @@ matmul_i8_vanilla (gfc_array_m8 * const restrict retarray,
       index_type isec, jsec, lsec, uisec, ujsec, ulsec;
       GFC_UINTEGER_8 *t1;
 
-      a = abase;
-      b = bbase;
       c = retarray->base_addr;
 
       /* Parameter adjustments */
-      c_dim1 = rystride;
       a_dim1 = aystride;
       b_dim1 = bystride;
 
 #define A_ARRAY_ELEM(i,j) \
-    a[(i) + (j) * a_dim1]
+    (ARRAY_ELEM_AT_OFFSET (abase, (i) * sizeof (GFC_UINTEGER_8) + (j) * aystride_bytes))
 
 #define B_ARRAY_ELEM(i,j) \
-    b[(i) + (j) * b_dim1]
+    (ARRAY_ELEM_AT_OFFSET (bbase, (i) * sizeof (GFC_UINTEGER_8) + (j) * bystride_bytes))
 
 #define C_ARRAY_ELEM(i,j) \
-    c[(i) + (j) * c_dim1]
+    (ARRAY_ELEM_AT_OFFSET (c, (i) * sizeof (GFC_UINTEGER_8) + (j) * rystride_bytes))
 
-      /* Empty c first.  */
+      /* Empty result first.  */
       for (j=0; j<n; j++)
 	for (i=0; i<m; i++)
 	  C_ARRAY_ELEM (i, j) = (GFC_UINTEGER_8)0;
@@ -2329,11 +2347,11 @@ matmul_i8_vanilla (gfc_array_m8 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
-	      dest_y = &dest[y*rystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	      dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	      for (x = 0; x < xcount; x++)
 		{
-		  abase_x = &abase[x*axstride];
+		  abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 		  s = (GFC_UINTEGER_8) 0;
 		  for (n = 0; n < count; n++)
 		    s += abase_x[n] * bbase_y[n];
@@ -2348,11 +2366,11 @@ matmul_i8_vanilla (gfc_array_m8 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	      s = (GFC_UINTEGER_8) 0;
 	      for (n = 0; n < count; n++)
 		s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n];
-	      dest[y*rystride] = s;
+	      ARRAY_ELEM_AT_OFFSET (dest, y * rystride_bytes) = s;
 	    }
 	}
     }
@@ -2363,10 +2381,11 @@ matmul_i8_vanilla (gfc_array_m8 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	  s = (GFC_UINTEGER_8) 0;
 	  for (n = 0; n < count; n++)
-	    s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n*bxstride];
+	    s += GFC_DESCRIPTOR1_ELEM (a, n)
+	         * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
 	  GFC_DESCRIPTOR1_ELEM (retarray, y) = s;
 	}
     }
@@ -2393,15 +2412,16 @@ matmul_i8_vanilla (gfc_array_m8 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
-	  dest_y = &dest[y*rystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	  dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	  for (x = 0; x < xcount; x++)
 	    {
-	      abase_x = &abase[x*axstride];
+	      abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 	      s = (GFC_UINTEGER_8) 0;
 	      for (n = 0; n < count; n++)
-		s += abase_x[n*aystride] * bbase_y[n*bxstride];
-	      dest_y[x*rxstride] = s;
+		s += ARRAY_ELEM_AT_OFFSET (abase_x, n * aystride_bytes)
+		     * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
+	      ARRAY_ELEM_AT_OFFSET (dest_y, x * rxstride_bytes) = s;
 	    }
 	}
     }
@@ -2501,7 +2521,8 @@ matmul_i8 (gfc_array_m8 * const restrict retarray,
 
   index_type rxstride, rystride, axstride, aystride, bxstride, bystride;
   index_type x, y, n, count, xcount, ycount;
-  index_type aystride_bytes, bystride_bytes, rystride_bytes;
+  index_type axstride_bytes, aystride_bytes, bxstride_bytes, bystride_bytes,
+	     rxstride_bytes, rystride_bytes;
 
   assert (GFC_DESCRIPTOR_RANK (a) == 2
           || GFC_DESCRIPTOR_RANK (b) == 2);
@@ -2590,12 +2611,13 @@ matmul_i8 (gfc_array_m8 * const restrict retarray,
 	 either as a row or a column matrix. We want both cases to
 	 work. */
       rxstride = rystride = GFC_DESCRIPTOR_STRIDE(retarray,0);
-      rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
+      rxstride_bytes = rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
     }
   else
     {
       rxstride = GFC_DESCRIPTOR_STRIDE(retarray,0);
       rystride = GFC_DESCRIPTOR_STRIDE(retarray,1);
+      rxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
       rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,1);
     }
 
@@ -2604,6 +2626,7 @@ matmul_i8 (gfc_array_m8 * const restrict retarray,
       /* Treat it as a a row matrix A[1,count]. */
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = 1;
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = sizeof (GFC_UINTEGER_8);
 
       xcount = 1;
@@ -2613,6 +2636,7 @@ matmul_i8 (gfc_array_m8 * const restrict retarray,
     {
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = GFC_DESCRIPTOR_STRIDE(a,1);
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,1);
 
       count = GFC_DESCRIPTOR_EXTENT(a,1);
@@ -2631,17 +2655,20 @@ matmul_i8 (gfc_array_m8 * const restrict retarray,
     {
       /* Treat it as a column matrix B[count,1] */
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
 
       /* bystride should never be used for 1-dimensional b.
          The value is only used for calculation of the
          memory by the buffer.  */
       bystride = 256;
+      bystride_bytes = 99999999;
       ycount = 1;
     }
   else
     {
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
       bystride = GFC_DESCRIPTOR_STRIDE(b,1);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
       bystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,1);
       ycount = GFC_DESCRIPTOR_EXTENT(b,1);
     }
@@ -2701,12 +2728,11 @@ matmul_i8 (gfc_array_m8 * const restrict retarray,
 
 	 from netlib.org, translated to C, and modified for matmul.m4.  */
 
-      const GFC_UINTEGER_8 *a, *b;
       GFC_UINTEGER_8 *c;
       const index_type m = xcount, n = ycount, k = count;
 
       /* System generated locals */
-      index_type a_dim1, b_dim1, c_dim1,
+      index_type a_dim1, b_dim1,
 		 i1, i2, i3, i4, i5, i6;
 
       /* Local variables */
@@ -2716,25 +2742,22 @@ matmul_i8 (gfc_array_m8 * const restrict retarray,
       index_type isec, jsec, lsec, uisec, ujsec, ulsec;
       GFC_UINTEGER_8 *t1;
 
-      a = abase;
-      b = bbase;
       c = retarray->base_addr;
 
       /* Parameter adjustments */
-      c_dim1 = rystride;
       a_dim1 = aystride;
       b_dim1 = bystride;
 
 #define A_ARRAY_ELEM(i,j) \
-    a[(i) + (j) * a_dim1]
+    (ARRAY_ELEM_AT_OFFSET (abase, (i) * sizeof (GFC_UINTEGER_8) + (j) * aystride_bytes))
 
 #define B_ARRAY_ELEM(i,j) \
-    b[(i) + (j) * b_dim1]
+    (ARRAY_ELEM_AT_OFFSET (bbase, (i) * sizeof (GFC_UINTEGER_8) + (j) * bystride_bytes))
 
 #define C_ARRAY_ELEM(i,j) \
-    c[(i) + (j) * c_dim1]
+    (ARRAY_ELEM_AT_OFFSET (c, (i) * sizeof (GFC_UINTEGER_8) + (j) * rystride_bytes))
 
-      /* Empty c first.  */
+      /* Empty result first.  */
       for (j=0; j<n; j++)
 	for (i=0; i<m; i++)
 	  C_ARRAY_ELEM (i, j) = (GFC_UINTEGER_8)0;
@@ -2982,11 +3005,11 @@ matmul_i8 (gfc_array_m8 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
-	      dest_y = &dest[y*rystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	      dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	      for (x = 0; x < xcount; x++)
 		{
-		  abase_x = &abase[x*axstride];
+		  abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 		  s = (GFC_UINTEGER_8) 0;
 		  for (n = 0; n < count; n++)
 		    s += abase_x[n] * bbase_y[n];
@@ -3001,11 +3024,11 @@ matmul_i8 (gfc_array_m8 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	      s = (GFC_UINTEGER_8) 0;
 	      for (n = 0; n < count; n++)
 		s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n];
-	      dest[y*rystride] = s;
+	      ARRAY_ELEM_AT_OFFSET (dest, y * rystride_bytes) = s;
 	    }
 	}
     }
@@ -3016,10 +3039,11 @@ matmul_i8 (gfc_array_m8 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	  s = (GFC_UINTEGER_8) 0;
 	  for (n = 0; n < count; n++)
-	    s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n*bxstride];
+	    s += GFC_DESCRIPTOR1_ELEM (a, n)
+	         * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
 	  GFC_DESCRIPTOR1_ELEM (retarray, y) = s;
 	}
     }
@@ -3046,15 +3070,16 @@ matmul_i8 (gfc_array_m8 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
-	  dest_y = &dest[y*rystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	  dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	  for (x = 0; x < xcount; x++)
 	    {
-	      abase_x = &abase[x*axstride];
+	      abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 	      s = (GFC_UINTEGER_8) 0;
 	      for (n = 0; n < count; n++)
-		s += abase_x[n*aystride] * bbase_y[n*bxstride];
-	      dest_y[x*rxstride] = s;
+		s += ARRAY_ELEM_AT_OFFSET (abase_x, n * aystride_bytes)
+		     * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
+	      ARRAY_ELEM_AT_OFFSET (dest_y, x * rxstride_bytes) = s;
 	    }
 	}
     }
diff --git a/libgfortran/generated/matmul_r10.c b/libgfortran/generated/matmul_r10.c
index 179e85931e3e..5f3cc97cbf21 100644
--- a/libgfortran/generated/matmul_r10.c
+++ b/libgfortran/generated/matmul_r10.c
@@ -94,7 +94,8 @@ matmul_r10_avx (gfc_array_r10 * const restrict retarray,
 
   index_type rxstride, rystride, axstride, aystride, bxstride, bystride;
   index_type x, y, n, count, xcount, ycount;
-  index_type aystride_bytes, bystride_bytes, rystride_bytes;
+  index_type axstride_bytes, aystride_bytes, bxstride_bytes, bystride_bytes,
+	     rxstride_bytes, rystride_bytes;
 
   assert (GFC_DESCRIPTOR_RANK (a) == 2
           || GFC_DESCRIPTOR_RANK (b) == 2);
@@ -183,12 +184,13 @@ matmul_r10_avx (gfc_array_r10 * const restrict retarray,
 	 either as a row or a column matrix. We want both cases to
 	 work. */
       rxstride = rystride = GFC_DESCRIPTOR_STRIDE(retarray,0);
-      rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
+      rxstride_bytes = rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
     }
   else
     {
       rxstride = GFC_DESCRIPTOR_STRIDE(retarray,0);
       rystride = GFC_DESCRIPTOR_STRIDE(retarray,1);
+      rxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
       rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,1);
     }
 
@@ -197,6 +199,7 @@ matmul_r10_avx (gfc_array_r10 * const restrict retarray,
       /* Treat it as a a row matrix A[1,count]. */
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = 1;
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = sizeof (GFC_REAL_10);
 
       xcount = 1;
@@ -206,6 +209,7 @@ matmul_r10_avx (gfc_array_r10 * const restrict retarray,
     {
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = GFC_DESCRIPTOR_STRIDE(a,1);
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,1);
 
       count = GFC_DESCRIPTOR_EXTENT(a,1);
@@ -224,17 +228,20 @@ matmul_r10_avx (gfc_array_r10 * const restrict retarray,
     {
       /* Treat it as a column matrix B[count,1] */
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
 
       /* bystride should never be used for 1-dimensional b.
          The value is only used for calculation of the
          memory by the buffer.  */
       bystride = 256;
+      bystride_bytes = 99999999;
       ycount = 1;
     }
   else
     {
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
       bystride = GFC_DESCRIPTOR_STRIDE(b,1);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
       bystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,1);
       ycount = GFC_DESCRIPTOR_EXTENT(b,1);
     }
@@ -294,12 +301,11 @@ matmul_r10_avx (gfc_array_r10 * const restrict retarray,
 
 	 from netlib.org, translated to C, and modified for matmul.m4.  */
 
-      const GFC_REAL_10 *a, *b;
       GFC_REAL_10 *c;
       const index_type m = xcount, n = ycount, k = count;
 
       /* System generated locals */
-      index_type a_dim1, b_dim1, c_dim1,
+      index_type a_dim1, b_dim1,
 		 i1, i2, i3, i4, i5, i6;
 
       /* Local variables */
@@ -309,25 +315,22 @@ matmul_r10_avx (gfc_array_r10 * const restrict retarray,
       index_type isec, jsec, lsec, uisec, ujsec, ulsec;
       GFC_REAL_10 *t1;
 
-      a = abase;
-      b = bbase;
       c = retarray->base_addr;
 
       /* Parameter adjustments */
-      c_dim1 = rystride;
       a_dim1 = aystride;
       b_dim1 = bystride;
 
 #define A_ARRAY_ELEM(i,j) \
-    a[(i) + (j) * a_dim1]
+    (ARRAY_ELEM_AT_OFFSET (abase, (i) * sizeof (GFC_REAL_10) + (j) * aystride_bytes))
 
 #define B_ARRAY_ELEM(i,j) \
-    b[(i) + (j) * b_dim1]
+    (ARRAY_ELEM_AT_OFFSET (bbase, (i) * sizeof (GFC_REAL_10) + (j) * bystride_bytes))
 
 #define C_ARRAY_ELEM(i,j) \
-    c[(i) + (j) * c_dim1]
+    (ARRAY_ELEM_AT_OFFSET (c, (i) * sizeof (GFC_REAL_10) + (j) * rystride_bytes))
 
-      /* Empty c first.  */
+      /* Empty result first.  */
       for (j=0; j<n; j++)
 	for (i=0; i<m; i++)
 	  C_ARRAY_ELEM (i, j) = (GFC_REAL_10)0;
@@ -575,11 +578,11 @@ matmul_r10_avx (gfc_array_r10 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
-	      dest_y = &dest[y*rystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	      dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	      for (x = 0; x < xcount; x++)
 		{
-		  abase_x = &abase[x*axstride];
+		  abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 		  s = (GFC_REAL_10) 0;
 		  for (n = 0; n < count; n++)
 		    s += abase_x[n] * bbase_y[n];
@@ -594,11 +597,11 @@ matmul_r10_avx (gfc_array_r10 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	      s = (GFC_REAL_10) 0;
 	      for (n = 0; n < count; n++)
 		s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n];
-	      dest[y*rystride] = s;
+	      ARRAY_ELEM_AT_OFFSET (dest, y * rystride_bytes) = s;
 	    }
 	}
     }
@@ -609,10 +612,11 @@ matmul_r10_avx (gfc_array_r10 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	  s = (GFC_REAL_10) 0;
 	  for (n = 0; n < count; n++)
-	    s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n*bxstride];
+	    s += GFC_DESCRIPTOR1_ELEM (a, n)
+	         * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
 	  GFC_DESCRIPTOR1_ELEM (retarray, y) = s;
 	}
     }
@@ -639,15 +643,16 @@ matmul_r10_avx (gfc_array_r10 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
-	  dest_y = &dest[y*rystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	  dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	  for (x = 0; x < xcount; x++)
 	    {
-	      abase_x = &abase[x*axstride];
+	      abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 	      s = (GFC_REAL_10) 0;
 	      for (n = 0; n < count; n++)
-		s += abase_x[n*aystride] * bbase_y[n*bxstride];
-	      dest_y[x*rxstride] = s;
+		s += ARRAY_ELEM_AT_OFFSET (abase_x, n * aystride_bytes)
+		     * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
+	      ARRAY_ELEM_AT_OFFSET (dest_y, x * rxstride_bytes) = s;
 	    }
 	}
     }
@@ -674,7 +679,8 @@ matmul_r10_avx2 (gfc_array_r10 * const restrict retarray,
 
   index_type rxstride, rystride, axstride, aystride, bxstride, bystride;
   index_type x, y, n, count, xcount, ycount;
-  index_type aystride_bytes, bystride_bytes, rystride_bytes;
+  index_type axstride_bytes, aystride_bytes, bxstride_bytes, bystride_bytes,
+	     rxstride_bytes, rystride_bytes;
 
   assert (GFC_DESCRIPTOR_RANK (a) == 2
           || GFC_DESCRIPTOR_RANK (b) == 2);
@@ -763,12 +769,13 @@ matmul_r10_avx2 (gfc_array_r10 * const restrict retarray,
 	 either as a row or a column matrix. We want both cases to
 	 work. */
       rxstride = rystride = GFC_DESCRIPTOR_STRIDE(retarray,0);
-      rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
+      rxstride_bytes = rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
     }
   else
     {
       rxstride = GFC_DESCRIPTOR_STRIDE(retarray,0);
       rystride = GFC_DESCRIPTOR_STRIDE(retarray,1);
+      rxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
       rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,1);
     }
 
@@ -777,6 +784,7 @@ matmul_r10_avx2 (gfc_array_r10 * const restrict retarray,
       /* Treat it as a a row matrix A[1,count]. */
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = 1;
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = sizeof (GFC_REAL_10);
 
       xcount = 1;
@@ -786,6 +794,7 @@ matmul_r10_avx2 (gfc_array_r10 * const restrict retarray,
     {
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = GFC_DESCRIPTOR_STRIDE(a,1);
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,1);
 
       count = GFC_DESCRIPTOR_EXTENT(a,1);
@@ -804,17 +813,20 @@ matmul_r10_avx2 (gfc_array_r10 * const restrict retarray,
     {
       /* Treat it as a column matrix B[count,1] */
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
 
       /* bystride should never be used for 1-dimensional b.
          The value is only used for calculation of the
          memory by the buffer.  */
       bystride = 256;
+      bystride_bytes = 99999999;
       ycount = 1;
     }
   else
     {
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
       bystride = GFC_DESCRIPTOR_STRIDE(b,1);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
       bystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,1);
       ycount = GFC_DESCRIPTOR_EXTENT(b,1);
     }
@@ -874,12 +886,11 @@ matmul_r10_avx2 (gfc_array_r10 * const restrict retarray,
 
 	 from netlib.org, translated to C, and modified for matmul.m4.  */
 
-      const GFC_REAL_10 *a, *b;
       GFC_REAL_10 *c;
       const index_type m = xcount, n = ycount, k = count;
 
       /* System generated locals */
-      index_type a_dim1, b_dim1, c_dim1,
+      index_type a_dim1, b_dim1,
 		 i1, i2, i3, i4, i5, i6;
 
       /* Local variables */
@@ -889,25 +900,22 @@ matmul_r10_avx2 (gfc_array_r10 * const restrict retarray,
       index_type isec, jsec, lsec, uisec, ujsec, ulsec;
       GFC_REAL_10 *t1;
 
-      a = abase;
-      b = bbase;
       c = retarray->base_addr;
 
       /* Parameter adjustments */
-      c_dim1 = rystride;
       a_dim1 = aystride;
       b_dim1 = bystride;
 
 #define A_ARRAY_ELEM(i,j) \
-    a[(i) + (j) * a_dim1]
+    (ARRAY_ELEM_AT_OFFSET (abase, (i) * sizeof (GFC_REAL_10) + (j) * aystride_bytes))
 
 #define B_ARRAY_ELEM(i,j) \
-    b[(i) + (j) * b_dim1]
+    (ARRAY_ELEM_AT_OFFSET (bbase, (i) * sizeof (GFC_REAL_10) + (j) * bystride_bytes))
 
 #define C_ARRAY_ELEM(i,j) \
-    c[(i) + (j) * c_dim1]
+    (ARRAY_ELEM_AT_OFFSET (c, (i) * sizeof (GFC_REAL_10) + (j) * rystride_bytes))
 
-      /* Empty c first.  */
+      /* Empty result first.  */
       for (j=0; j<n; j++)
 	for (i=0; i<m; i++)
 	  C_ARRAY_ELEM (i, j) = (GFC_REAL_10)0;
@@ -1155,11 +1163,11 @@ matmul_r10_avx2 (gfc_array_r10 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
-	      dest_y = &dest[y*rystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	      dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	      for (x = 0; x < xcount; x++)
 		{
-		  abase_x = &abase[x*axstride];
+		  abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 		  s = (GFC_REAL_10) 0;
 		  for (n = 0; n < count; n++)
 		    s += abase_x[n] * bbase_y[n];
@@ -1174,11 +1182,11 @@ matmul_r10_avx2 (gfc_array_r10 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	      s = (GFC_REAL_10) 0;
 	      for (n = 0; n < count; n++)
 		s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n];
-	      dest[y*rystride] = s;
+	      ARRAY_ELEM_AT_OFFSET (dest, y * rystride_bytes) = s;
 	    }
 	}
     }
@@ -1189,10 +1197,11 @@ matmul_r10_avx2 (gfc_array_r10 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	  s = (GFC_REAL_10) 0;
 	  for (n = 0; n < count; n++)
-	    s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n*bxstride];
+	    s += GFC_DESCRIPTOR1_ELEM (a, n)
+	         * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
 	  GFC_DESCRIPTOR1_ELEM (retarray, y) = s;
 	}
     }
@@ -1219,15 +1228,16 @@ matmul_r10_avx2 (gfc_array_r10 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
-	  dest_y = &dest[y*rystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	  dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	  for (x = 0; x < xcount; x++)
 	    {
-	      abase_x = &abase[x*axstride];
+	      abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 	      s = (GFC_REAL_10) 0;
 	      for (n = 0; n < count; n++)
-		s += abase_x[n*aystride] * bbase_y[n*bxstride];
-	      dest_y[x*rxstride] = s;
+		s += ARRAY_ELEM_AT_OFFSET (abase_x, n * aystride_bytes)
+		     * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
+	      ARRAY_ELEM_AT_OFFSET (dest_y, x * rxstride_bytes) = s;
 	    }
 	}
     }
@@ -1254,7 +1264,8 @@ matmul_r10_avx512f (gfc_array_r10 * const restrict retarray,
 
   index_type rxstride, rystride, axstride, aystride, bxstride, bystride;
   index_type x, y, n, count, xcount, ycount;
-  index_type aystride_bytes, bystride_bytes, rystride_bytes;
+  index_type axstride_bytes, aystride_bytes, bxstride_bytes, bystride_bytes,
+	     rxstride_bytes, rystride_bytes;
 
   assert (GFC_DESCRIPTOR_RANK (a) == 2
           || GFC_DESCRIPTOR_RANK (b) == 2);
@@ -1343,12 +1354,13 @@ matmul_r10_avx512f (gfc_array_r10 * const restrict retarray,
 	 either as a row or a column matrix. We want both cases to
 	 work. */
       rxstride = rystride = GFC_DESCRIPTOR_STRIDE(retarray,0);
-      rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
+      rxstride_bytes = rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
     }
   else
     {
       rxstride = GFC_DESCRIPTOR_STRIDE(retarray,0);
       rystride = GFC_DESCRIPTOR_STRIDE(retarray,1);
+      rxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
       rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,1);
     }
 
@@ -1357,6 +1369,7 @@ matmul_r10_avx512f (gfc_array_r10 * const restrict retarray,
       /* Treat it as a a row matrix A[1,count]. */
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = 1;
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = sizeof (GFC_REAL_10);
 
       xcount = 1;
@@ -1366,6 +1379,7 @@ matmul_r10_avx512f (gfc_array_r10 * const restrict retarray,
     {
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = GFC_DESCRIPTOR_STRIDE(a,1);
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,1);
 
       count = GFC_DESCRIPTOR_EXTENT(a,1);
@@ -1384,17 +1398,20 @@ matmul_r10_avx512f (gfc_array_r10 * const restrict retarray,
     {
       /* Treat it as a column matrix B[count,1] */
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
 
       /* bystride should never be used for 1-dimensional b.
          The value is only used for calculation of the
          memory by the buffer.  */
       bystride = 256;
+      bystride_bytes = 99999999;
       ycount = 1;
     }
   else
     {
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
       bystride = GFC_DESCRIPTOR_STRIDE(b,1);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
       bystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,1);
       ycount = GFC_DESCRIPTOR_EXTENT(b,1);
     }
@@ -1454,12 +1471,11 @@ matmul_r10_avx512f (gfc_array_r10 * const restrict retarray,
 
 	 from netlib.org, translated to C, and modified for matmul.m4.  */
 
-      const GFC_REAL_10 *a, *b;
       GFC_REAL_10 *c;
       const index_type m = xcount, n = ycount, k = count;
 
       /* System generated locals */
-      index_type a_dim1, b_dim1, c_dim1,
+      index_type a_dim1, b_dim1,
 		 i1, i2, i3, i4, i5, i6;
 
       /* Local variables */
@@ -1469,25 +1485,22 @@ matmul_r10_avx512f (gfc_array_r10 * const restrict retarray,
       index_type isec, jsec, lsec, uisec, ujsec, ulsec;
       GFC_REAL_10 *t1;
 
-      a = abase;
-      b = bbase;
       c = retarray->base_addr;
 
       /* Parameter adjustments */
-      c_dim1 = rystride;
       a_dim1 = aystride;
       b_dim1 = bystride;
 
 #define A_ARRAY_ELEM(i,j) \
-    a[(i) + (j) * a_dim1]
+    (ARRAY_ELEM_AT_OFFSET (abase, (i) * sizeof (GFC_REAL_10) + (j) * aystride_bytes))
 
 #define B_ARRAY_ELEM(i,j) \
-    b[(i) + (j) * b_dim1]
+    (ARRAY_ELEM_AT_OFFSET (bbase, (i) * sizeof (GFC_REAL_10) + (j) * bystride_bytes))
 
 #define C_ARRAY_ELEM(i,j) \
-    c[(i) + (j) * c_dim1]
+    (ARRAY_ELEM_AT_OFFSET (c, (i) * sizeof (GFC_REAL_10) + (j) * rystride_bytes))
 
-      /* Empty c first.  */
+      /* Empty result first.  */
       for (j=0; j<n; j++)
 	for (i=0; i<m; i++)
 	  C_ARRAY_ELEM (i, j) = (GFC_REAL_10)0;
@@ -1735,11 +1748,11 @@ matmul_r10_avx512f (gfc_array_r10 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
-	      dest_y = &dest[y*rystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	      dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	      for (x = 0; x < xcount; x++)
 		{
-		  abase_x = &abase[x*axstride];
+		  abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 		  s = (GFC_REAL_10) 0;
 		  for (n = 0; n < count; n++)
 		    s += abase_x[n] * bbase_y[n];
@@ -1754,11 +1767,11 @@ matmul_r10_avx512f (gfc_array_r10 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	      s = (GFC_REAL_10) 0;
 	      for (n = 0; n < count; n++)
 		s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n];
-	      dest[y*rystride] = s;
+	      ARRAY_ELEM_AT_OFFSET (dest, y * rystride_bytes) = s;
 	    }
 	}
     }
@@ -1769,10 +1782,11 @@ matmul_r10_avx512f (gfc_array_r10 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	  s = (GFC_REAL_10) 0;
 	  for (n = 0; n < count; n++)
-	    s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n*bxstride];
+	    s += GFC_DESCRIPTOR1_ELEM (a, n)
+	         * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
 	  GFC_DESCRIPTOR1_ELEM (retarray, y) = s;
 	}
     }
@@ -1799,15 +1813,16 @@ matmul_r10_avx512f (gfc_array_r10 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
-	  dest_y = &dest[y*rystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	  dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	  for (x = 0; x < xcount; x++)
 	    {
-	      abase_x = &abase[x*axstride];
+	      abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 	      s = (GFC_REAL_10) 0;
 	      for (n = 0; n < count; n++)
-		s += abase_x[n*aystride] * bbase_y[n*bxstride];
-	      dest_y[x*rxstride] = s;
+		s += ARRAY_ELEM_AT_OFFSET (abase_x, n * aystride_bytes)
+		     * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
+	      ARRAY_ELEM_AT_OFFSET (dest_y, x * rxstride_bytes) = s;
 	    }
 	}
     }
@@ -1848,7 +1863,8 @@ matmul_r10_vanilla (gfc_array_r10 * const restrict retarray,
 
   index_type rxstride, rystride, axstride, aystride, bxstride, bystride;
   index_type x, y, n, count, xcount, ycount;
-  index_type aystride_bytes, bystride_bytes, rystride_bytes;
+  index_type axstride_bytes, aystride_bytes, bxstride_bytes, bystride_bytes,
+	     rxstride_bytes, rystride_bytes;
 
   assert (GFC_DESCRIPTOR_RANK (a) == 2
           || GFC_DESCRIPTOR_RANK (b) == 2);
@@ -1937,12 +1953,13 @@ matmul_r10_vanilla (gfc_array_r10 * const restrict retarray,
 	 either as a row or a column matrix. We want both cases to
 	 work. */
       rxstride = rystride = GFC_DESCRIPTOR_STRIDE(retarray,0);
-      rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
+      rxstride_bytes = rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
     }
   else
     {
       rxstride = GFC_DESCRIPTOR_STRIDE(retarray,0);
       rystride = GFC_DESCRIPTOR_STRIDE(retarray,1);
+      rxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
       rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,1);
     }
 
@@ -1951,6 +1968,7 @@ matmul_r10_vanilla (gfc_array_r10 * const restrict retarray,
       /* Treat it as a a row matrix A[1,count]. */
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = 1;
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = sizeof (GFC_REAL_10);
 
       xcount = 1;
@@ -1960,6 +1978,7 @@ matmul_r10_vanilla (gfc_array_r10 * const restrict retarray,
     {
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = GFC_DESCRIPTOR_STRIDE(a,1);
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,1);
 
       count = GFC_DESCRIPTOR_EXTENT(a,1);
@@ -1978,17 +1997,20 @@ matmul_r10_vanilla (gfc_array_r10 * const restrict retarray,
     {
       /* Treat it as a column matrix B[count,1] */
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
 
       /* bystride should never be used for 1-dimensional b.
          The value is only used for calculation of the
          memory by the buffer.  */
       bystride = 256;
+      bystride_bytes = 99999999;
       ycount = 1;
     }
   else
     {
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
       bystride = GFC_DESCRIPTOR_STRIDE(b,1);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
       bystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,1);
       ycount = GFC_DESCRIPTOR_EXTENT(b,1);
     }
@@ -2048,12 +2070,11 @@ matmul_r10_vanilla (gfc_array_r10 * const restrict retarray,
 
 	 from netlib.org, translated to C, and modified for matmul.m4.  */
 
-      const GFC_REAL_10 *a, *b;
       GFC_REAL_10 *c;
       const index_type m = xcount, n = ycount, k = count;
 
       /* System generated locals */
-      index_type a_dim1, b_dim1, c_dim1,
+      index_type a_dim1, b_dim1,
 		 i1, i2, i3, i4, i5, i6;
 
       /* Local variables */
@@ -2063,25 +2084,22 @@ matmul_r10_vanilla (gfc_array_r10 * const restrict retarray,
       index_type isec, jsec, lsec, uisec, ujsec, ulsec;
       GFC_REAL_10 *t1;
 
-      a = abase;
-      b = bbase;
       c = retarray->base_addr;
 
       /* Parameter adjustments */
-      c_dim1 = rystride;
       a_dim1 = aystride;
       b_dim1 = bystride;
 
 #define A_ARRAY_ELEM(i,j) \
-    a[(i) + (j) * a_dim1]
+    (ARRAY_ELEM_AT_OFFSET (abase, (i) * sizeof (GFC_REAL_10) + (j) * aystride_bytes))
 
 #define B_ARRAY_ELEM(i,j) \
-    b[(i) + (j) * b_dim1]
+    (ARRAY_ELEM_AT_OFFSET (bbase, (i) * sizeof (GFC_REAL_10) + (j) * bystride_bytes))
 
 #define C_ARRAY_ELEM(i,j) \
-    c[(i) + (j) * c_dim1]
+    (ARRAY_ELEM_AT_OFFSET (c, (i) * sizeof (GFC_REAL_10) + (j) * rystride_bytes))
 
-      /* Empty c first.  */
+      /* Empty result first.  */
       for (j=0; j<n; j++)
 	for (i=0; i<m; i++)
 	  C_ARRAY_ELEM (i, j) = (GFC_REAL_10)0;
@@ -2329,11 +2347,11 @@ matmul_r10_vanilla (gfc_array_r10 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
-	      dest_y = &dest[y*rystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	      dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	      for (x = 0; x < xcount; x++)
 		{
-		  abase_x = &abase[x*axstride];
+		  abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 		  s = (GFC_REAL_10) 0;
 		  for (n = 0; n < count; n++)
 		    s += abase_x[n] * bbase_y[n];
@@ -2348,11 +2366,11 @@ matmul_r10_vanilla (gfc_array_r10 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	      s = (GFC_REAL_10) 0;
 	      for (n = 0; n < count; n++)
 		s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n];
-	      dest[y*rystride] = s;
+	      ARRAY_ELEM_AT_OFFSET (dest, y * rystride_bytes) = s;
 	    }
 	}
     }
@@ -2363,10 +2381,11 @@ matmul_r10_vanilla (gfc_array_r10 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	  s = (GFC_REAL_10) 0;
 	  for (n = 0; n < count; n++)
-	    s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n*bxstride];
+	    s += GFC_DESCRIPTOR1_ELEM (a, n)
+	         * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
 	  GFC_DESCRIPTOR1_ELEM (retarray, y) = s;
 	}
     }
@@ -2393,15 +2412,16 @@ matmul_r10_vanilla (gfc_array_r10 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
-	  dest_y = &dest[y*rystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	  dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	  for (x = 0; x < xcount; x++)
 	    {
-	      abase_x = &abase[x*axstride];
+	      abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 	      s = (GFC_REAL_10) 0;
 	      for (n = 0; n < count; n++)
-		s += abase_x[n*aystride] * bbase_y[n*bxstride];
-	      dest_y[x*rxstride] = s;
+		s += ARRAY_ELEM_AT_OFFSET (abase_x, n * aystride_bytes)
+		     * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
+	      ARRAY_ELEM_AT_OFFSET (dest_y, x * rxstride_bytes) = s;
 	    }
 	}
     }
@@ -2501,7 +2521,8 @@ matmul_r10 (gfc_array_r10 * const restrict retarray,
 
   index_type rxstride, rystride, axstride, aystride, bxstride, bystride;
   index_type x, y, n, count, xcount, ycount;
-  index_type aystride_bytes, bystride_bytes, rystride_bytes;
+  index_type axstride_bytes, aystride_bytes, bxstride_bytes, bystride_bytes,
+	     rxstride_bytes, rystride_bytes;
 
   assert (GFC_DESCRIPTOR_RANK (a) == 2
           || GFC_DESCRIPTOR_RANK (b) == 2);
@@ -2590,12 +2611,13 @@ matmul_r10 (gfc_array_r10 * const restrict retarray,
 	 either as a row or a column matrix. We want both cases to
 	 work. */
       rxstride = rystride = GFC_DESCRIPTOR_STRIDE(retarray,0);
-      rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
+      rxstride_bytes = rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
     }
   else
     {
       rxstride = GFC_DESCRIPTOR_STRIDE(retarray,0);
       rystride = GFC_DESCRIPTOR_STRIDE(retarray,1);
+      rxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
       rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,1);
     }
 
@@ -2604,6 +2626,7 @@ matmul_r10 (gfc_array_r10 * const restrict retarray,
       /* Treat it as a a row matrix A[1,count]. */
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = 1;
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = sizeof (GFC_REAL_10);
 
       xcount = 1;
@@ -2613,6 +2636,7 @@ matmul_r10 (gfc_array_r10 * const restrict retarray,
     {
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = GFC_DESCRIPTOR_STRIDE(a,1);
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,1);
 
       count = GFC_DESCRIPTOR_EXTENT(a,1);
@@ -2631,17 +2655,20 @@ matmul_r10 (gfc_array_r10 * const restrict retarray,
     {
       /* Treat it as a column matrix B[count,1] */
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
 
       /* bystride should never be used for 1-dimensional b.
          The value is only used for calculation of the
          memory by the buffer.  */
       bystride = 256;
+      bystride_bytes = 99999999;
       ycount = 1;
     }
   else
     {
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
       bystride = GFC_DESCRIPTOR_STRIDE(b,1);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
       bystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,1);
       ycount = GFC_DESCRIPTOR_EXTENT(b,1);
     }
@@ -2701,12 +2728,11 @@ matmul_r10 (gfc_array_r10 * const restrict retarray,
 
 	 from netlib.org, translated to C, and modified for matmul.m4.  */
 
-      const GFC_REAL_10 *a, *b;
       GFC_REAL_10 *c;
       const index_type m = xcount, n = ycount, k = count;
 
       /* System generated locals */
-      index_type a_dim1, b_dim1, c_dim1,
+      index_type a_dim1, b_dim1,
 		 i1, i2, i3, i4, i5, i6;
 
       /* Local variables */
@@ -2716,25 +2742,22 @@ matmul_r10 (gfc_array_r10 * const restrict retarray,
       index_type isec, jsec, lsec, uisec, ujsec, ulsec;
       GFC_REAL_10 *t1;
 
-      a = abase;
-      b = bbase;
       c = retarray->base_addr;
 
       /* Parameter adjustments */
-      c_dim1 = rystride;
       a_dim1 = aystride;
       b_dim1 = bystride;
 
 #define A_ARRAY_ELEM(i,j) \
-    a[(i) + (j) * a_dim1]
+    (ARRAY_ELEM_AT_OFFSET (abase, (i) * sizeof (GFC_REAL_10) + (j) * aystride_bytes))
 
 #define B_ARRAY_ELEM(i,j) \
-    b[(i) + (j) * b_dim1]
+    (ARRAY_ELEM_AT_OFFSET (bbase, (i) * sizeof (GFC_REAL_10) + (j) * bystride_bytes))
 
 #define C_ARRAY_ELEM(i,j) \
-    c[(i) + (j) * c_dim1]
+    (ARRAY_ELEM_AT_OFFSET (c, (i) * sizeof (GFC_REAL_10) + (j) * rystride_bytes))
 
-      /* Empty c first.  */
+      /* Empty result first.  */
       for (j=0; j<n; j++)
 	for (i=0; i<m; i++)
 	  C_ARRAY_ELEM (i, j) = (GFC_REAL_10)0;
@@ -2982,11 +3005,11 @@ matmul_r10 (gfc_array_r10 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
-	      dest_y = &dest[y*rystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	      dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	      for (x = 0; x < xcount; x++)
 		{
-		  abase_x = &abase[x*axstride];
+		  abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 		  s = (GFC_REAL_10) 0;
 		  for (n = 0; n < count; n++)
 		    s += abase_x[n] * bbase_y[n];
@@ -3001,11 +3024,11 @@ matmul_r10 (gfc_array_r10 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	      s = (GFC_REAL_10) 0;
 	      for (n = 0; n < count; n++)
 		s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n];
-	      dest[y*rystride] = s;
+	      ARRAY_ELEM_AT_OFFSET (dest, y * rystride_bytes) = s;
 	    }
 	}
     }
@@ -3016,10 +3039,11 @@ matmul_r10 (gfc_array_r10 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	  s = (GFC_REAL_10) 0;
 	  for (n = 0; n < count; n++)
-	    s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n*bxstride];
+	    s += GFC_DESCRIPTOR1_ELEM (a, n)
+	         * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
 	  GFC_DESCRIPTOR1_ELEM (retarray, y) = s;
 	}
     }
@@ -3046,15 +3070,16 @@ matmul_r10 (gfc_array_r10 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
-	  dest_y = &dest[y*rystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	  dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	  for (x = 0; x < xcount; x++)
 	    {
-	      abase_x = &abase[x*axstride];
+	      abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 	      s = (GFC_REAL_10) 0;
 	      for (n = 0; n < count; n++)
-		s += abase_x[n*aystride] * bbase_y[n*bxstride];
-	      dest_y[x*rxstride] = s;
+		s += ARRAY_ELEM_AT_OFFSET (abase_x, n * aystride_bytes)
+		     * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
+	      ARRAY_ELEM_AT_OFFSET (dest_y, x * rxstride_bytes) = s;
 	    }
 	}
     }
diff --git a/libgfortran/generated/matmul_r16.c b/libgfortran/generated/matmul_r16.c
index dc6d98907ad0..43d7cf4d5140 100644
--- a/libgfortran/generated/matmul_r16.c
+++ b/libgfortran/generated/matmul_r16.c
@@ -94,7 +94,8 @@ matmul_r16_avx (gfc_array_r16 * const restrict retarray,
 
   index_type rxstride, rystride, axstride, aystride, bxstride, bystride;
   index_type x, y, n, count, xcount, ycount;
-  index_type aystride_bytes, bystride_bytes, rystride_bytes;
+  index_type axstride_bytes, aystride_bytes, bxstride_bytes, bystride_bytes,
+	     rxstride_bytes, rystride_bytes;
 
   assert (GFC_DESCRIPTOR_RANK (a) == 2
           || GFC_DESCRIPTOR_RANK (b) == 2);
@@ -183,12 +184,13 @@ matmul_r16_avx (gfc_array_r16 * const restrict retarray,
 	 either as a row or a column matrix. We want both cases to
 	 work. */
       rxstride = rystride = GFC_DESCRIPTOR_STRIDE(retarray,0);
-      rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
+      rxstride_bytes = rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
     }
   else
     {
       rxstride = GFC_DESCRIPTOR_STRIDE(retarray,0);
       rystride = GFC_DESCRIPTOR_STRIDE(retarray,1);
+      rxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
       rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,1);
     }
 
@@ -197,6 +199,7 @@ matmul_r16_avx (gfc_array_r16 * const restrict retarray,
       /* Treat it as a a row matrix A[1,count]. */
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = 1;
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = sizeof (GFC_REAL_16);
 
       xcount = 1;
@@ -206,6 +209,7 @@ matmul_r16_avx (gfc_array_r16 * const restrict retarray,
     {
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = GFC_DESCRIPTOR_STRIDE(a,1);
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,1);
 
       count = GFC_DESCRIPTOR_EXTENT(a,1);
@@ -224,17 +228,20 @@ matmul_r16_avx (gfc_array_r16 * const restrict retarray,
     {
       /* Treat it as a column matrix B[count,1] */
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
 
       /* bystride should never be used for 1-dimensional b.
          The value is only used for calculation of the
          memory by the buffer.  */
       bystride = 256;
+      bystride_bytes = 99999999;
       ycount = 1;
     }
   else
     {
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
       bystride = GFC_DESCRIPTOR_STRIDE(b,1);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
       bystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,1);
       ycount = GFC_DESCRIPTOR_EXTENT(b,1);
     }
@@ -294,12 +301,11 @@ matmul_r16_avx (gfc_array_r16 * const restrict retarray,
 
 	 from netlib.org, translated to C, and modified for matmul.m4.  */
 
-      const GFC_REAL_16 *a, *b;
       GFC_REAL_16 *c;
       const index_type m = xcount, n = ycount, k = count;
 
       /* System generated locals */
-      index_type a_dim1, b_dim1, c_dim1,
+      index_type a_dim1, b_dim1,
 		 i1, i2, i3, i4, i5, i6;
 
       /* Local variables */
@@ -309,25 +315,22 @@ matmul_r16_avx (gfc_array_r16 * const restrict retarray,
       index_type isec, jsec, lsec, uisec, ujsec, ulsec;
       GFC_REAL_16 *t1;
 
-      a = abase;
-      b = bbase;
       c = retarray->base_addr;
 
       /* Parameter adjustments */
-      c_dim1 = rystride;
       a_dim1 = aystride;
       b_dim1 = bystride;
 
 #define A_ARRAY_ELEM(i,j) \
-    a[(i) + (j) * a_dim1]
+    (ARRAY_ELEM_AT_OFFSET (abase, (i) * sizeof (GFC_REAL_16) + (j) * aystride_bytes))
 
 #define B_ARRAY_ELEM(i,j) \
-    b[(i) + (j) * b_dim1]
+    (ARRAY_ELEM_AT_OFFSET (bbase, (i) * sizeof (GFC_REAL_16) + (j) * bystride_bytes))
 
 #define C_ARRAY_ELEM(i,j) \
-    c[(i) + (j) * c_dim1]
+    (ARRAY_ELEM_AT_OFFSET (c, (i) * sizeof (GFC_REAL_16) + (j) * rystride_bytes))
 
-      /* Empty c first.  */
+      /* Empty result first.  */
       for (j=0; j<n; j++)
 	for (i=0; i<m; i++)
 	  C_ARRAY_ELEM (i, j) = (GFC_REAL_16)0;
@@ -575,11 +578,11 @@ matmul_r16_avx (gfc_array_r16 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
-	      dest_y = &dest[y*rystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	      dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	      for (x = 0; x < xcount; x++)
 		{
-		  abase_x = &abase[x*axstride];
+		  abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 		  s = (GFC_REAL_16) 0;
 		  for (n = 0; n < count; n++)
 		    s += abase_x[n] * bbase_y[n];
@@ -594,11 +597,11 @@ matmul_r16_avx (gfc_array_r16 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	      s = (GFC_REAL_16) 0;
 	      for (n = 0; n < count; n++)
 		s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n];
-	      dest[y*rystride] = s;
+	      ARRAY_ELEM_AT_OFFSET (dest, y * rystride_bytes) = s;
 	    }
 	}
     }
@@ -609,10 +612,11 @@ matmul_r16_avx (gfc_array_r16 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	  s = (GFC_REAL_16) 0;
 	  for (n = 0; n < count; n++)
-	    s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n*bxstride];
+	    s += GFC_DESCRIPTOR1_ELEM (a, n)
+	         * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
 	  GFC_DESCRIPTOR1_ELEM (retarray, y) = s;
 	}
     }
@@ -639,15 +643,16 @@ matmul_r16_avx (gfc_array_r16 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
-	  dest_y = &dest[y*rystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	  dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	  for (x = 0; x < xcount; x++)
 	    {
-	      abase_x = &abase[x*axstride];
+	      abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 	      s = (GFC_REAL_16) 0;
 	      for (n = 0; n < count; n++)
-		s += abase_x[n*aystride] * bbase_y[n*bxstride];
-	      dest_y[x*rxstride] = s;
+		s += ARRAY_ELEM_AT_OFFSET (abase_x, n * aystride_bytes)
+		     * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
+	      ARRAY_ELEM_AT_OFFSET (dest_y, x * rxstride_bytes) = s;
 	    }
 	}
     }
@@ -674,7 +679,8 @@ matmul_r16_avx2 (gfc_array_r16 * const restrict retarray,
 
   index_type rxstride, rystride, axstride, aystride, bxstride, bystride;
   index_type x, y, n, count, xcount, ycount;
-  index_type aystride_bytes, bystride_bytes, rystride_bytes;
+  index_type axstride_bytes, aystride_bytes, bxstride_bytes, bystride_bytes,
+	     rxstride_bytes, rystride_bytes;
 
   assert (GFC_DESCRIPTOR_RANK (a) == 2
           || GFC_DESCRIPTOR_RANK (b) == 2);
@@ -763,12 +769,13 @@ matmul_r16_avx2 (gfc_array_r16 * const restrict retarray,
 	 either as a row or a column matrix. We want both cases to
 	 work. */
       rxstride = rystride = GFC_DESCRIPTOR_STRIDE(retarray,0);
-      rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
+      rxstride_bytes = rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
     }
   else
     {
       rxstride = GFC_DESCRIPTOR_STRIDE(retarray,0);
       rystride = GFC_DESCRIPTOR_STRIDE(retarray,1);
+      rxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
       rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,1);
     }
 
@@ -777,6 +784,7 @@ matmul_r16_avx2 (gfc_array_r16 * const restrict retarray,
       /* Treat it as a a row matrix A[1,count]. */
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = 1;
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = sizeof (GFC_REAL_16);
 
       xcount = 1;
@@ -786,6 +794,7 @@ matmul_r16_avx2 (gfc_array_r16 * const restrict retarray,
     {
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = GFC_DESCRIPTOR_STRIDE(a,1);
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,1);
 
       count = GFC_DESCRIPTOR_EXTENT(a,1);
@@ -804,17 +813,20 @@ matmul_r16_avx2 (gfc_array_r16 * const restrict retarray,
     {
       /* Treat it as a column matrix B[count,1] */
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
 
       /* bystride should never be used for 1-dimensional b.
          The value is only used for calculation of the
          memory by the buffer.  */
       bystride = 256;
+      bystride_bytes = 99999999;
       ycount = 1;
     }
   else
     {
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
       bystride = GFC_DESCRIPTOR_STRIDE(b,1);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
       bystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,1);
       ycount = GFC_DESCRIPTOR_EXTENT(b,1);
     }
@@ -874,12 +886,11 @@ matmul_r16_avx2 (gfc_array_r16 * const restrict retarray,
 
 	 from netlib.org, translated to C, and modified for matmul.m4.  */
 
-      const GFC_REAL_16 *a, *b;
       GFC_REAL_16 *c;
       const index_type m = xcount, n = ycount, k = count;
 
       /* System generated locals */
-      index_type a_dim1, b_dim1, c_dim1,
+      index_type a_dim1, b_dim1,
 		 i1, i2, i3, i4, i5, i6;
 
       /* Local variables */
@@ -889,25 +900,22 @@ matmul_r16_avx2 (gfc_array_r16 * const restrict retarray,
       index_type isec, jsec, lsec, uisec, ujsec, ulsec;
       GFC_REAL_16 *t1;
 
-      a = abase;
-      b = bbase;
       c = retarray->base_addr;
 
       /* Parameter adjustments */
-      c_dim1 = rystride;
       a_dim1 = aystride;
       b_dim1 = bystride;
 
 #define A_ARRAY_ELEM(i,j) \
-    a[(i) + (j) * a_dim1]
+    (ARRAY_ELEM_AT_OFFSET (abase, (i) * sizeof (GFC_REAL_16) + (j) * aystride_bytes))
 
 #define B_ARRAY_ELEM(i,j) \
-    b[(i) + (j) * b_dim1]
+    (ARRAY_ELEM_AT_OFFSET (bbase, (i) * sizeof (GFC_REAL_16) + (j) * bystride_bytes))
 
 #define C_ARRAY_ELEM(i,j) \
-    c[(i) + (j) * c_dim1]
+    (ARRAY_ELEM_AT_OFFSET (c, (i) * sizeof (GFC_REAL_16) + (j) * rystride_bytes))
 
-      /* Empty c first.  */
+      /* Empty result first.  */
       for (j=0; j<n; j++)
 	for (i=0; i<m; i++)
 	  C_ARRAY_ELEM (i, j) = (GFC_REAL_16)0;
@@ -1155,11 +1163,11 @@ matmul_r16_avx2 (gfc_array_r16 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
-	      dest_y = &dest[y*rystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	      dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	      for (x = 0; x < xcount; x++)
 		{
-		  abase_x = &abase[x*axstride];
+		  abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 		  s = (GFC_REAL_16) 0;
 		  for (n = 0; n < count; n++)
 		    s += abase_x[n] * bbase_y[n];
@@ -1174,11 +1182,11 @@ matmul_r16_avx2 (gfc_array_r16 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	      s = (GFC_REAL_16) 0;
 	      for (n = 0; n < count; n++)
 		s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n];
-	      dest[y*rystride] = s;
+	      ARRAY_ELEM_AT_OFFSET (dest, y * rystride_bytes) = s;
 	    }
 	}
     }
@@ -1189,10 +1197,11 @@ matmul_r16_avx2 (gfc_array_r16 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	  s = (GFC_REAL_16) 0;
 	  for (n = 0; n < count; n++)
-	    s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n*bxstride];
+	    s += GFC_DESCRIPTOR1_ELEM (a, n)
+	         * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
 	  GFC_DESCRIPTOR1_ELEM (retarray, y) = s;
 	}
     }
@@ -1219,15 +1228,16 @@ matmul_r16_avx2 (gfc_array_r16 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
-	  dest_y = &dest[y*rystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	  dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	  for (x = 0; x < xcount; x++)
 	    {
-	      abase_x = &abase[x*axstride];
+	      abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 	      s = (GFC_REAL_16) 0;
 	      for (n = 0; n < count; n++)
-		s += abase_x[n*aystride] * bbase_y[n*bxstride];
-	      dest_y[x*rxstride] = s;
+		s += ARRAY_ELEM_AT_OFFSET (abase_x, n * aystride_bytes)
+		     * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
+	      ARRAY_ELEM_AT_OFFSET (dest_y, x * rxstride_bytes) = s;
 	    }
 	}
     }
@@ -1254,7 +1264,8 @@ matmul_r16_avx512f (gfc_array_r16 * const restrict retarray,
 
   index_type rxstride, rystride, axstride, aystride, bxstride, bystride;
   index_type x, y, n, count, xcount, ycount;
-  index_type aystride_bytes, bystride_bytes, rystride_bytes;
+  index_type axstride_bytes, aystride_bytes, bxstride_bytes, bystride_bytes,
+	     rxstride_bytes, rystride_bytes;
 
   assert (GFC_DESCRIPTOR_RANK (a) == 2
           || GFC_DESCRIPTOR_RANK (b) == 2);
@@ -1343,12 +1354,13 @@ matmul_r16_avx512f (gfc_array_r16 * const restrict retarray,
 	 either as a row or a column matrix. We want both cases to
 	 work. */
       rxstride = rystride = GFC_DESCRIPTOR_STRIDE(retarray,0);
-      rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
+      rxstride_bytes = rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
     }
   else
     {
       rxstride = GFC_DESCRIPTOR_STRIDE(retarray,0);
       rystride = GFC_DESCRIPTOR_STRIDE(retarray,1);
+      rxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
       rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,1);
     }
 
@@ -1357,6 +1369,7 @@ matmul_r16_avx512f (gfc_array_r16 * const restrict retarray,
       /* Treat it as a a row matrix A[1,count]. */
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = 1;
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = sizeof (GFC_REAL_16);
 
       xcount = 1;
@@ -1366,6 +1379,7 @@ matmul_r16_avx512f (gfc_array_r16 * const restrict retarray,
     {
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = GFC_DESCRIPTOR_STRIDE(a,1);
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,1);
 
       count = GFC_DESCRIPTOR_EXTENT(a,1);
@@ -1384,17 +1398,20 @@ matmul_r16_avx512f (gfc_array_r16 * const restrict retarray,
     {
       /* Treat it as a column matrix B[count,1] */
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
 
       /* bystride should never be used for 1-dimensional b.
          The value is only used for calculation of the
          memory by the buffer.  */
       bystride = 256;
+      bystride_bytes = 99999999;
       ycount = 1;
     }
   else
     {
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
       bystride = GFC_DESCRIPTOR_STRIDE(b,1);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
       bystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,1);
       ycount = GFC_DESCRIPTOR_EXTENT(b,1);
     }
@@ -1454,12 +1471,11 @@ matmul_r16_avx512f (gfc_array_r16 * const restrict retarray,
 
 	 from netlib.org, translated to C, and modified for matmul.m4.  */
 
-      const GFC_REAL_16 *a, *b;
       GFC_REAL_16 *c;
       const index_type m = xcount, n = ycount, k = count;
 
       /* System generated locals */
-      index_type a_dim1, b_dim1, c_dim1,
+      index_type a_dim1, b_dim1,
 		 i1, i2, i3, i4, i5, i6;
 
       /* Local variables */
@@ -1469,25 +1485,22 @@ matmul_r16_avx512f (gfc_array_r16 * const restrict retarray,
       index_type isec, jsec, lsec, uisec, ujsec, ulsec;
       GFC_REAL_16 *t1;
 
-      a = abase;
-      b = bbase;
       c = retarray->base_addr;
 
       /* Parameter adjustments */
-      c_dim1 = rystride;
       a_dim1 = aystride;
       b_dim1 = bystride;
 
 #define A_ARRAY_ELEM(i,j) \
-    a[(i) + (j) * a_dim1]
+    (ARRAY_ELEM_AT_OFFSET (abase, (i) * sizeof (GFC_REAL_16) + (j) * aystride_bytes))
 
 #define B_ARRAY_ELEM(i,j) \
-    b[(i) + (j) * b_dim1]
+    (ARRAY_ELEM_AT_OFFSET (bbase, (i) * sizeof (GFC_REAL_16) + (j) * bystride_bytes))
 
 #define C_ARRAY_ELEM(i,j) \
-    c[(i) + (j) * c_dim1]
+    (ARRAY_ELEM_AT_OFFSET (c, (i) * sizeof (GFC_REAL_16) + (j) * rystride_bytes))
 
-      /* Empty c first.  */
+      /* Empty result first.  */
       for (j=0; j<n; j++)
 	for (i=0; i<m; i++)
 	  C_ARRAY_ELEM (i, j) = (GFC_REAL_16)0;
@@ -1735,11 +1748,11 @@ matmul_r16_avx512f (gfc_array_r16 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
-	      dest_y = &dest[y*rystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	      dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	      for (x = 0; x < xcount; x++)
 		{
-		  abase_x = &abase[x*axstride];
+		  abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 		  s = (GFC_REAL_16) 0;
 		  for (n = 0; n < count; n++)
 		    s += abase_x[n] * bbase_y[n];
@@ -1754,11 +1767,11 @@ matmul_r16_avx512f (gfc_array_r16 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	      s = (GFC_REAL_16) 0;
 	      for (n = 0; n < count; n++)
 		s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n];
-	      dest[y*rystride] = s;
+	      ARRAY_ELEM_AT_OFFSET (dest, y * rystride_bytes) = s;
 	    }
 	}
     }
@@ -1769,10 +1782,11 @@ matmul_r16_avx512f (gfc_array_r16 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	  s = (GFC_REAL_16) 0;
 	  for (n = 0; n < count; n++)
-	    s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n*bxstride];
+	    s += GFC_DESCRIPTOR1_ELEM (a, n)
+	         * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
 	  GFC_DESCRIPTOR1_ELEM (retarray, y) = s;
 	}
     }
@@ -1799,15 +1813,16 @@ matmul_r16_avx512f (gfc_array_r16 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
-	  dest_y = &dest[y*rystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	  dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	  for (x = 0; x < xcount; x++)
 	    {
-	      abase_x = &abase[x*axstride];
+	      abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 	      s = (GFC_REAL_16) 0;
 	      for (n = 0; n < count; n++)
-		s += abase_x[n*aystride] * bbase_y[n*bxstride];
-	      dest_y[x*rxstride] = s;
+		s += ARRAY_ELEM_AT_OFFSET (abase_x, n * aystride_bytes)
+		     * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
+	      ARRAY_ELEM_AT_OFFSET (dest_y, x * rxstride_bytes) = s;
 	    }
 	}
     }
@@ -1848,7 +1863,8 @@ matmul_r16_vanilla (gfc_array_r16 * const restrict retarray,
 
   index_type rxstride, rystride, axstride, aystride, bxstride, bystride;
   index_type x, y, n, count, xcount, ycount;
-  index_type aystride_bytes, bystride_bytes, rystride_bytes;
+  index_type axstride_bytes, aystride_bytes, bxstride_bytes, bystride_bytes,
+	     rxstride_bytes, rystride_bytes;
 
   assert (GFC_DESCRIPTOR_RANK (a) == 2
           || GFC_DESCRIPTOR_RANK (b) == 2);
@@ -1937,12 +1953,13 @@ matmul_r16_vanilla (gfc_array_r16 * const restrict retarray,
 	 either as a row or a column matrix. We want both cases to
 	 work. */
       rxstride = rystride = GFC_DESCRIPTOR_STRIDE(retarray,0);
-      rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
+      rxstride_bytes = rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
     }
   else
     {
       rxstride = GFC_DESCRIPTOR_STRIDE(retarray,0);
       rystride = GFC_DESCRIPTOR_STRIDE(retarray,1);
+      rxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
       rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,1);
     }
 
@@ -1951,6 +1968,7 @@ matmul_r16_vanilla (gfc_array_r16 * const restrict retarray,
       /* Treat it as a a row matrix A[1,count]. */
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = 1;
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = sizeof (GFC_REAL_16);
 
       xcount = 1;
@@ -1960,6 +1978,7 @@ matmul_r16_vanilla (gfc_array_r16 * const restrict retarray,
     {
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = GFC_DESCRIPTOR_STRIDE(a,1);
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,1);
 
       count = GFC_DESCRIPTOR_EXTENT(a,1);
@@ -1978,17 +1997,20 @@ matmul_r16_vanilla (gfc_array_r16 * const restrict retarray,
     {
       /* Treat it as a column matrix B[count,1] */
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
 
       /* bystride should never be used for 1-dimensional b.
          The value is only used for calculation of the
          memory by the buffer.  */
       bystride = 256;
+      bystride_bytes = 99999999;
       ycount = 1;
     }
   else
     {
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
       bystride = GFC_DESCRIPTOR_STRIDE(b,1);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
       bystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,1);
       ycount = GFC_DESCRIPTOR_EXTENT(b,1);
     }
@@ -2048,12 +2070,11 @@ matmul_r16_vanilla (gfc_array_r16 * const restrict retarray,
 
 	 from netlib.org, translated to C, and modified for matmul.m4.  */
 
-      const GFC_REAL_16 *a, *b;
       GFC_REAL_16 *c;
       const index_type m = xcount, n = ycount, k = count;
 
       /* System generated locals */
-      index_type a_dim1, b_dim1, c_dim1,
+      index_type a_dim1, b_dim1,
 		 i1, i2, i3, i4, i5, i6;
 
       /* Local variables */
@@ -2063,25 +2084,22 @@ matmul_r16_vanilla (gfc_array_r16 * const restrict retarray,
       index_type isec, jsec, lsec, uisec, ujsec, ulsec;
       GFC_REAL_16 *t1;
 
-      a = abase;
-      b = bbase;
       c = retarray->base_addr;
 
       /* Parameter adjustments */
-      c_dim1 = rystride;
       a_dim1 = aystride;
       b_dim1 = bystride;
 
 #define A_ARRAY_ELEM(i,j) \
-    a[(i) + (j) * a_dim1]
+    (ARRAY_ELEM_AT_OFFSET (abase, (i) * sizeof (GFC_REAL_16) + (j) * aystride_bytes))
 
 #define B_ARRAY_ELEM(i,j) \
-    b[(i) + (j) * b_dim1]
+    (ARRAY_ELEM_AT_OFFSET (bbase, (i) * sizeof (GFC_REAL_16) + (j) * bystride_bytes))
 
 #define C_ARRAY_ELEM(i,j) \
-    c[(i) + (j) * c_dim1]
+    (ARRAY_ELEM_AT_OFFSET (c, (i) * sizeof (GFC_REAL_16) + (j) * rystride_bytes))
 
-      /* Empty c first.  */
+      /* Empty result first.  */
       for (j=0; j<n; j++)
 	for (i=0; i<m; i++)
 	  C_ARRAY_ELEM (i, j) = (GFC_REAL_16)0;
@@ -2329,11 +2347,11 @@ matmul_r16_vanilla (gfc_array_r16 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
-	      dest_y = &dest[y*rystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	      dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	      for (x = 0; x < xcount; x++)
 		{
-		  abase_x = &abase[x*axstride];
+		  abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 		  s = (GFC_REAL_16) 0;
 		  for (n = 0; n < count; n++)
 		    s += abase_x[n] * bbase_y[n];
@@ -2348,11 +2366,11 @@ matmul_r16_vanilla (gfc_array_r16 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	      s = (GFC_REAL_16) 0;
 	      for (n = 0; n < count; n++)
 		s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n];
-	      dest[y*rystride] = s;
+	      ARRAY_ELEM_AT_OFFSET (dest, y * rystride_bytes) = s;
 	    }
 	}
     }
@@ -2363,10 +2381,11 @@ matmul_r16_vanilla (gfc_array_r16 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	  s = (GFC_REAL_16) 0;
 	  for (n = 0; n < count; n++)
-	    s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n*bxstride];
+	    s += GFC_DESCRIPTOR1_ELEM (a, n)
+	         * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
 	  GFC_DESCRIPTOR1_ELEM (retarray, y) = s;
 	}
     }
@@ -2393,15 +2412,16 @@ matmul_r16_vanilla (gfc_array_r16 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
-	  dest_y = &dest[y*rystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	  dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	  for (x = 0; x < xcount; x++)
 	    {
-	      abase_x = &abase[x*axstride];
+	      abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 	      s = (GFC_REAL_16) 0;
 	      for (n = 0; n < count; n++)
-		s += abase_x[n*aystride] * bbase_y[n*bxstride];
-	      dest_y[x*rxstride] = s;
+		s += ARRAY_ELEM_AT_OFFSET (abase_x, n * aystride_bytes)
+		     * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
+	      ARRAY_ELEM_AT_OFFSET (dest_y, x * rxstride_bytes) = s;
 	    }
 	}
     }
@@ -2501,7 +2521,8 @@ matmul_r16 (gfc_array_r16 * const restrict retarray,
 
   index_type rxstride, rystride, axstride, aystride, bxstride, bystride;
   index_type x, y, n, count, xcount, ycount;
-  index_type aystride_bytes, bystride_bytes, rystride_bytes;
+  index_type axstride_bytes, aystride_bytes, bxstride_bytes, bystride_bytes,
+	     rxstride_bytes, rystride_bytes;
 
   assert (GFC_DESCRIPTOR_RANK (a) == 2
           || GFC_DESCRIPTOR_RANK (b) == 2);
@@ -2590,12 +2611,13 @@ matmul_r16 (gfc_array_r16 * const restrict retarray,
 	 either as a row or a column matrix. We want both cases to
 	 work. */
       rxstride = rystride = GFC_DESCRIPTOR_STRIDE(retarray,0);
-      rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
+      rxstride_bytes = rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
     }
   else
     {
       rxstride = GFC_DESCRIPTOR_STRIDE(retarray,0);
       rystride = GFC_DESCRIPTOR_STRIDE(retarray,1);
+      rxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
       rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,1);
     }
 
@@ -2604,6 +2626,7 @@ matmul_r16 (gfc_array_r16 * const restrict retarray,
       /* Treat it as a a row matrix A[1,count]. */
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = 1;
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = sizeof (GFC_REAL_16);
 
       xcount = 1;
@@ -2613,6 +2636,7 @@ matmul_r16 (gfc_array_r16 * const restrict retarray,
     {
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = GFC_DESCRIPTOR_STRIDE(a,1);
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,1);
 
       count = GFC_DESCRIPTOR_EXTENT(a,1);
@@ -2631,17 +2655,20 @@ matmul_r16 (gfc_array_r16 * const restrict retarray,
     {
       /* Treat it as a column matrix B[count,1] */
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
 
       /* bystride should never be used for 1-dimensional b.
          The value is only used for calculation of the
          memory by the buffer.  */
       bystride = 256;
+      bystride_bytes = 99999999;
       ycount = 1;
     }
   else
     {
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
       bystride = GFC_DESCRIPTOR_STRIDE(b,1);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
       bystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,1);
       ycount = GFC_DESCRIPTOR_EXTENT(b,1);
     }
@@ -2701,12 +2728,11 @@ matmul_r16 (gfc_array_r16 * const restrict retarray,
 
 	 from netlib.org, translated to C, and modified for matmul.m4.  */
 
-      const GFC_REAL_16 *a, *b;
       GFC_REAL_16 *c;
       const index_type m = xcount, n = ycount, k = count;
 
       /* System generated locals */
-      index_type a_dim1, b_dim1, c_dim1,
+      index_type a_dim1, b_dim1,
 		 i1, i2, i3, i4, i5, i6;
 
       /* Local variables */
@@ -2716,25 +2742,22 @@ matmul_r16 (gfc_array_r16 * const restrict retarray,
       index_type isec, jsec, lsec, uisec, ujsec, ulsec;
       GFC_REAL_16 *t1;
 
-      a = abase;
-      b = bbase;
       c = retarray->base_addr;
 
       /* Parameter adjustments */
-      c_dim1 = rystride;
       a_dim1 = aystride;
       b_dim1 = bystride;
 
 #define A_ARRAY_ELEM(i,j) \
-    a[(i) + (j) * a_dim1]
+    (ARRAY_ELEM_AT_OFFSET (abase, (i) * sizeof (GFC_REAL_16) + (j) * aystride_bytes))
 
 #define B_ARRAY_ELEM(i,j) \
-    b[(i) + (j) * b_dim1]
+    (ARRAY_ELEM_AT_OFFSET (bbase, (i) * sizeof (GFC_REAL_16) + (j) * bystride_bytes))
 
 #define C_ARRAY_ELEM(i,j) \
-    c[(i) + (j) * c_dim1]
+    (ARRAY_ELEM_AT_OFFSET (c, (i) * sizeof (GFC_REAL_16) + (j) * rystride_bytes))
 
-      /* Empty c first.  */
+      /* Empty result first.  */
       for (j=0; j<n; j++)
 	for (i=0; i<m; i++)
 	  C_ARRAY_ELEM (i, j) = (GFC_REAL_16)0;
@@ -2982,11 +3005,11 @@ matmul_r16 (gfc_array_r16 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
-	      dest_y = &dest[y*rystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	      dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	      for (x = 0; x < xcount; x++)
 		{
-		  abase_x = &abase[x*axstride];
+		  abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 		  s = (GFC_REAL_16) 0;
 		  for (n = 0; n < count; n++)
 		    s += abase_x[n] * bbase_y[n];
@@ -3001,11 +3024,11 @@ matmul_r16 (gfc_array_r16 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	      s = (GFC_REAL_16) 0;
 	      for (n = 0; n < count; n++)
 		s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n];
-	      dest[y*rystride] = s;
+	      ARRAY_ELEM_AT_OFFSET (dest, y * rystride_bytes) = s;
 	    }
 	}
     }
@@ -3016,10 +3039,11 @@ matmul_r16 (gfc_array_r16 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	  s = (GFC_REAL_16) 0;
 	  for (n = 0; n < count; n++)
-	    s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n*bxstride];
+	    s += GFC_DESCRIPTOR1_ELEM (a, n)
+	         * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
 	  GFC_DESCRIPTOR1_ELEM (retarray, y) = s;
 	}
     }
@@ -3046,15 +3070,16 @@ matmul_r16 (gfc_array_r16 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
-	  dest_y = &dest[y*rystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	  dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	  for (x = 0; x < xcount; x++)
 	    {
-	      abase_x = &abase[x*axstride];
+	      abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 	      s = (GFC_REAL_16) 0;
 	      for (n = 0; n < count; n++)
-		s += abase_x[n*aystride] * bbase_y[n*bxstride];
-	      dest_y[x*rxstride] = s;
+		s += ARRAY_ELEM_AT_OFFSET (abase_x, n * aystride_bytes)
+		     * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
+	      ARRAY_ELEM_AT_OFFSET (dest_y, x * rxstride_bytes) = s;
 	    }
 	}
     }
diff --git a/libgfortran/generated/matmul_r17.c b/libgfortran/generated/matmul_r17.c
index 96b931a10c1e..dc08ed149ef4 100644
--- a/libgfortran/generated/matmul_r17.c
+++ b/libgfortran/generated/matmul_r17.c
@@ -94,7 +94,8 @@ matmul_r17_avx (gfc_array_r17 * const restrict retarray,
 
   index_type rxstride, rystride, axstride, aystride, bxstride, bystride;
   index_type x, y, n, count, xcount, ycount;
-  index_type aystride_bytes, bystride_bytes, rystride_bytes;
+  index_type axstride_bytes, aystride_bytes, bxstride_bytes, bystride_bytes,
+	     rxstride_bytes, rystride_bytes;
 
   assert (GFC_DESCRIPTOR_RANK (a) == 2
           || GFC_DESCRIPTOR_RANK (b) == 2);
@@ -183,12 +184,13 @@ matmul_r17_avx (gfc_array_r17 * const restrict retarray,
 	 either as a row or a column matrix. We want both cases to
 	 work. */
       rxstride = rystride = GFC_DESCRIPTOR_STRIDE(retarray,0);
-      rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
+      rxstride_bytes = rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
     }
   else
     {
       rxstride = GFC_DESCRIPTOR_STRIDE(retarray,0);
       rystride = GFC_DESCRIPTOR_STRIDE(retarray,1);
+      rxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
       rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,1);
     }
 
@@ -197,6 +199,7 @@ matmul_r17_avx (gfc_array_r17 * const restrict retarray,
       /* Treat it as a a row matrix A[1,count]. */
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = 1;
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = sizeof (GFC_REAL_17);
 
       xcount = 1;
@@ -206,6 +209,7 @@ matmul_r17_avx (gfc_array_r17 * const restrict retarray,
     {
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = GFC_DESCRIPTOR_STRIDE(a,1);
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,1);
 
       count = GFC_DESCRIPTOR_EXTENT(a,1);
@@ -224,17 +228,20 @@ matmul_r17_avx (gfc_array_r17 * const restrict retarray,
     {
       /* Treat it as a column matrix B[count,1] */
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
 
       /* bystride should never be used for 1-dimensional b.
          The value is only used for calculation of the
          memory by the buffer.  */
       bystride = 256;
+      bystride_bytes = 99999999;
       ycount = 1;
     }
   else
     {
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
       bystride = GFC_DESCRIPTOR_STRIDE(b,1);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
       bystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,1);
       ycount = GFC_DESCRIPTOR_EXTENT(b,1);
     }
@@ -294,12 +301,11 @@ matmul_r17_avx (gfc_array_r17 * const restrict retarray,
 
 	 from netlib.org, translated to C, and modified for matmul.m4.  */
 
-      const GFC_REAL_17 *a, *b;
       GFC_REAL_17 *c;
       const index_type m = xcount, n = ycount, k = count;
 
       /* System generated locals */
-      index_type a_dim1, b_dim1, c_dim1,
+      index_type a_dim1, b_dim1,
 		 i1, i2, i3, i4, i5, i6;
 
       /* Local variables */
@@ -309,25 +315,22 @@ matmul_r17_avx (gfc_array_r17 * const restrict retarray,
       index_type isec, jsec, lsec, uisec, ujsec, ulsec;
       GFC_REAL_17 *t1;
 
-      a = abase;
-      b = bbase;
       c = retarray->base_addr;
 
       /* Parameter adjustments */
-      c_dim1 = rystride;
       a_dim1 = aystride;
       b_dim1 = bystride;
 
 #define A_ARRAY_ELEM(i,j) \
-    a[(i) + (j) * a_dim1]
+    (ARRAY_ELEM_AT_OFFSET (abase, (i) * sizeof (GFC_REAL_17) + (j) * aystride_bytes))
 
 #define B_ARRAY_ELEM(i,j) \
-    b[(i) + (j) * b_dim1]
+    (ARRAY_ELEM_AT_OFFSET (bbase, (i) * sizeof (GFC_REAL_17) + (j) * bystride_bytes))
 
 #define C_ARRAY_ELEM(i,j) \
-    c[(i) + (j) * c_dim1]
+    (ARRAY_ELEM_AT_OFFSET (c, (i) * sizeof (GFC_REAL_17) + (j) * rystride_bytes))
 
-      /* Empty c first.  */
+      /* Empty result first.  */
       for (j=0; j<n; j++)
 	for (i=0; i<m; i++)
 	  C_ARRAY_ELEM (i, j) = (GFC_REAL_17)0;
@@ -575,11 +578,11 @@ matmul_r17_avx (gfc_array_r17 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
-	      dest_y = &dest[y*rystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	      dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	      for (x = 0; x < xcount; x++)
 		{
-		  abase_x = &abase[x*axstride];
+		  abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 		  s = (GFC_REAL_17) 0;
 		  for (n = 0; n < count; n++)
 		    s += abase_x[n] * bbase_y[n];
@@ -594,11 +597,11 @@ matmul_r17_avx (gfc_array_r17 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	      s = (GFC_REAL_17) 0;
 	      for (n = 0; n < count; n++)
 		s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n];
-	      dest[y*rystride] = s;
+	      ARRAY_ELEM_AT_OFFSET (dest, y * rystride_bytes) = s;
 	    }
 	}
     }
@@ -609,10 +612,11 @@ matmul_r17_avx (gfc_array_r17 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	  s = (GFC_REAL_17) 0;
 	  for (n = 0; n < count; n++)
-	    s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n*bxstride];
+	    s += GFC_DESCRIPTOR1_ELEM (a, n)
+	         * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
 	  GFC_DESCRIPTOR1_ELEM (retarray, y) = s;
 	}
     }
@@ -639,15 +643,16 @@ matmul_r17_avx (gfc_array_r17 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
-	  dest_y = &dest[y*rystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	  dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	  for (x = 0; x < xcount; x++)
 	    {
-	      abase_x = &abase[x*axstride];
+	      abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 	      s = (GFC_REAL_17) 0;
 	      for (n = 0; n < count; n++)
-		s += abase_x[n*aystride] * bbase_y[n*bxstride];
-	      dest_y[x*rxstride] = s;
+		s += ARRAY_ELEM_AT_OFFSET (abase_x, n * aystride_bytes)
+		     * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
+	      ARRAY_ELEM_AT_OFFSET (dest_y, x * rxstride_bytes) = s;
 	    }
 	}
     }
@@ -674,7 +679,8 @@ matmul_r17_avx2 (gfc_array_r17 * const restrict retarray,
 
   index_type rxstride, rystride, axstride, aystride, bxstride, bystride;
   index_type x, y, n, count, xcount, ycount;
-  index_type aystride_bytes, bystride_bytes, rystride_bytes;
+  index_type axstride_bytes, aystride_bytes, bxstride_bytes, bystride_bytes,
+	     rxstride_bytes, rystride_bytes;
 
   assert (GFC_DESCRIPTOR_RANK (a) == 2
           || GFC_DESCRIPTOR_RANK (b) == 2);
@@ -763,12 +769,13 @@ matmul_r17_avx2 (gfc_array_r17 * const restrict retarray,
 	 either as a row or a column matrix. We want both cases to
 	 work. */
       rxstride = rystride = GFC_DESCRIPTOR_STRIDE(retarray,0);
-      rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
+      rxstride_bytes = rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
     }
   else
     {
       rxstride = GFC_DESCRIPTOR_STRIDE(retarray,0);
       rystride = GFC_DESCRIPTOR_STRIDE(retarray,1);
+      rxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
       rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,1);
     }
 
@@ -777,6 +784,7 @@ matmul_r17_avx2 (gfc_array_r17 * const restrict retarray,
       /* Treat it as a a row matrix A[1,count]. */
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = 1;
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = sizeof (GFC_REAL_17);
 
       xcount = 1;
@@ -786,6 +794,7 @@ matmul_r17_avx2 (gfc_array_r17 * const restrict retarray,
     {
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = GFC_DESCRIPTOR_STRIDE(a,1);
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,1);
 
       count = GFC_DESCRIPTOR_EXTENT(a,1);
@@ -804,17 +813,20 @@ matmul_r17_avx2 (gfc_array_r17 * const restrict retarray,
     {
       /* Treat it as a column matrix B[count,1] */
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
 
       /* bystride should never be used for 1-dimensional b.
          The value is only used for calculation of the
          memory by the buffer.  */
       bystride = 256;
+      bystride_bytes = 99999999;
       ycount = 1;
     }
   else
     {
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
       bystride = GFC_DESCRIPTOR_STRIDE(b,1);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
       bystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,1);
       ycount = GFC_DESCRIPTOR_EXTENT(b,1);
     }
@@ -874,12 +886,11 @@ matmul_r17_avx2 (gfc_array_r17 * const restrict retarray,
 
 	 from netlib.org, translated to C, and modified for matmul.m4.  */
 
-      const GFC_REAL_17 *a, *b;
       GFC_REAL_17 *c;
       const index_type m = xcount, n = ycount, k = count;
 
       /* System generated locals */
-      index_type a_dim1, b_dim1, c_dim1,
+      index_type a_dim1, b_dim1,
 		 i1, i2, i3, i4, i5, i6;
 
       /* Local variables */
@@ -889,25 +900,22 @@ matmul_r17_avx2 (gfc_array_r17 * const restrict retarray,
       index_type isec, jsec, lsec, uisec, ujsec, ulsec;
       GFC_REAL_17 *t1;
 
-      a = abase;
-      b = bbase;
       c = retarray->base_addr;
 
       /* Parameter adjustments */
-      c_dim1 = rystride;
       a_dim1 = aystride;
       b_dim1 = bystride;
 
 #define A_ARRAY_ELEM(i,j) \
-    a[(i) + (j) * a_dim1]
+    (ARRAY_ELEM_AT_OFFSET (abase, (i) * sizeof (GFC_REAL_17) + (j) * aystride_bytes))
 
 #define B_ARRAY_ELEM(i,j) \
-    b[(i) + (j) * b_dim1]
+    (ARRAY_ELEM_AT_OFFSET (bbase, (i) * sizeof (GFC_REAL_17) + (j) * bystride_bytes))
 
 #define C_ARRAY_ELEM(i,j) \
-    c[(i) + (j) * c_dim1]
+    (ARRAY_ELEM_AT_OFFSET (c, (i) * sizeof (GFC_REAL_17) + (j) * rystride_bytes))
 
-      /* Empty c first.  */
+      /* Empty result first.  */
       for (j=0; j<n; j++)
 	for (i=0; i<m; i++)
 	  C_ARRAY_ELEM (i, j) = (GFC_REAL_17)0;
@@ -1155,11 +1163,11 @@ matmul_r17_avx2 (gfc_array_r17 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
-	      dest_y = &dest[y*rystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	      dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	      for (x = 0; x < xcount; x++)
 		{
-		  abase_x = &abase[x*axstride];
+		  abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 		  s = (GFC_REAL_17) 0;
 		  for (n = 0; n < count; n++)
 		    s += abase_x[n] * bbase_y[n];
@@ -1174,11 +1182,11 @@ matmul_r17_avx2 (gfc_array_r17 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	      s = (GFC_REAL_17) 0;
 	      for (n = 0; n < count; n++)
 		s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n];
-	      dest[y*rystride] = s;
+	      ARRAY_ELEM_AT_OFFSET (dest, y * rystride_bytes) = s;
 	    }
 	}
     }
@@ -1189,10 +1197,11 @@ matmul_r17_avx2 (gfc_array_r17 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	  s = (GFC_REAL_17) 0;
 	  for (n = 0; n < count; n++)
-	    s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n*bxstride];
+	    s += GFC_DESCRIPTOR1_ELEM (a, n)
+	         * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
 	  GFC_DESCRIPTOR1_ELEM (retarray, y) = s;
 	}
     }
@@ -1219,15 +1228,16 @@ matmul_r17_avx2 (gfc_array_r17 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
-	  dest_y = &dest[y*rystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	  dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	  for (x = 0; x < xcount; x++)
 	    {
-	      abase_x = &abase[x*axstride];
+	      abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 	      s = (GFC_REAL_17) 0;
 	      for (n = 0; n < count; n++)
-		s += abase_x[n*aystride] * bbase_y[n*bxstride];
-	      dest_y[x*rxstride] = s;
+		s += ARRAY_ELEM_AT_OFFSET (abase_x, n * aystride_bytes)
+		     * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
+	      ARRAY_ELEM_AT_OFFSET (dest_y, x * rxstride_bytes) = s;
 	    }
 	}
     }
@@ -1254,7 +1264,8 @@ matmul_r17_avx512f (gfc_array_r17 * const restrict retarray,
 
   index_type rxstride, rystride, axstride, aystride, bxstride, bystride;
   index_type x, y, n, count, xcount, ycount;
-  index_type aystride_bytes, bystride_bytes, rystride_bytes;
+  index_type axstride_bytes, aystride_bytes, bxstride_bytes, bystride_bytes,
+	     rxstride_bytes, rystride_bytes;
 
   assert (GFC_DESCRIPTOR_RANK (a) == 2
           || GFC_DESCRIPTOR_RANK (b) == 2);
@@ -1343,12 +1354,13 @@ matmul_r17_avx512f (gfc_array_r17 * const restrict retarray,
 	 either as a row or a column matrix. We want both cases to
 	 work. */
       rxstride = rystride = GFC_DESCRIPTOR_STRIDE(retarray,0);
-      rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
+      rxstride_bytes = rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
     }
   else
     {
       rxstride = GFC_DESCRIPTOR_STRIDE(retarray,0);
       rystride = GFC_DESCRIPTOR_STRIDE(retarray,1);
+      rxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
       rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,1);
     }
 
@@ -1357,6 +1369,7 @@ matmul_r17_avx512f (gfc_array_r17 * const restrict retarray,
       /* Treat it as a a row matrix A[1,count]. */
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = 1;
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = sizeof (GFC_REAL_17);
 
       xcount = 1;
@@ -1366,6 +1379,7 @@ matmul_r17_avx512f (gfc_array_r17 * const restrict retarray,
     {
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = GFC_DESCRIPTOR_STRIDE(a,1);
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,1);
 
       count = GFC_DESCRIPTOR_EXTENT(a,1);
@@ -1384,17 +1398,20 @@ matmul_r17_avx512f (gfc_array_r17 * const restrict retarray,
     {
       /* Treat it as a column matrix B[count,1] */
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
 
       /* bystride should never be used for 1-dimensional b.
          The value is only used for calculation of the
          memory by the buffer.  */
       bystride = 256;
+      bystride_bytes = 99999999;
       ycount = 1;
     }
   else
     {
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
       bystride = GFC_DESCRIPTOR_STRIDE(b,1);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
       bystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,1);
       ycount = GFC_DESCRIPTOR_EXTENT(b,1);
     }
@@ -1454,12 +1471,11 @@ matmul_r17_avx512f (gfc_array_r17 * const restrict retarray,
 
 	 from netlib.org, translated to C, and modified for matmul.m4.  */
 
-      const GFC_REAL_17 *a, *b;
       GFC_REAL_17 *c;
       const index_type m = xcount, n = ycount, k = count;
 
       /* System generated locals */
-      index_type a_dim1, b_dim1, c_dim1,
+      index_type a_dim1, b_dim1,
 		 i1, i2, i3, i4, i5, i6;
 
       /* Local variables */
@@ -1469,25 +1485,22 @@ matmul_r17_avx512f (gfc_array_r17 * const restrict retarray,
       index_type isec, jsec, lsec, uisec, ujsec, ulsec;
       GFC_REAL_17 *t1;
 
-      a = abase;
-      b = bbase;
       c = retarray->base_addr;
 
       /* Parameter adjustments */
-      c_dim1 = rystride;
       a_dim1 = aystride;
       b_dim1 = bystride;
 
 #define A_ARRAY_ELEM(i,j) \
-    a[(i) + (j) * a_dim1]
+    (ARRAY_ELEM_AT_OFFSET (abase, (i) * sizeof (GFC_REAL_17) + (j) * aystride_bytes))
 
 #define B_ARRAY_ELEM(i,j) \
-    b[(i) + (j) * b_dim1]
+    (ARRAY_ELEM_AT_OFFSET (bbase, (i) * sizeof (GFC_REAL_17) + (j) * bystride_bytes))
 
 #define C_ARRAY_ELEM(i,j) \
-    c[(i) + (j) * c_dim1]
+    (ARRAY_ELEM_AT_OFFSET (c, (i) * sizeof (GFC_REAL_17) + (j) * rystride_bytes))
 
-      /* Empty c first.  */
+      /* Empty result first.  */
       for (j=0; j<n; j++)
 	for (i=0; i<m; i++)
 	  C_ARRAY_ELEM (i, j) = (GFC_REAL_17)0;
@@ -1735,11 +1748,11 @@ matmul_r17_avx512f (gfc_array_r17 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
-	      dest_y = &dest[y*rystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	      dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	      for (x = 0; x < xcount; x++)
 		{
-		  abase_x = &abase[x*axstride];
+		  abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 		  s = (GFC_REAL_17) 0;
 		  for (n = 0; n < count; n++)
 		    s += abase_x[n] * bbase_y[n];
@@ -1754,11 +1767,11 @@ matmul_r17_avx512f (gfc_array_r17 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	      s = (GFC_REAL_17) 0;
 	      for (n = 0; n < count; n++)
 		s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n];
-	      dest[y*rystride] = s;
+	      ARRAY_ELEM_AT_OFFSET (dest, y * rystride_bytes) = s;
 	    }
 	}
     }
@@ -1769,10 +1782,11 @@ matmul_r17_avx512f (gfc_array_r17 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	  s = (GFC_REAL_17) 0;
 	  for (n = 0; n < count; n++)
-	    s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n*bxstride];
+	    s += GFC_DESCRIPTOR1_ELEM (a, n)
+	         * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
 	  GFC_DESCRIPTOR1_ELEM (retarray, y) = s;
 	}
     }
@@ -1799,15 +1813,16 @@ matmul_r17_avx512f (gfc_array_r17 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
-	  dest_y = &dest[y*rystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	  dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	  for (x = 0; x < xcount; x++)
 	    {
-	      abase_x = &abase[x*axstride];
+	      abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 	      s = (GFC_REAL_17) 0;
 	      for (n = 0; n < count; n++)
-		s += abase_x[n*aystride] * bbase_y[n*bxstride];
-	      dest_y[x*rxstride] = s;
+		s += ARRAY_ELEM_AT_OFFSET (abase_x, n * aystride_bytes)
+		     * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
+	      ARRAY_ELEM_AT_OFFSET (dest_y, x * rxstride_bytes) = s;
 	    }
 	}
     }
@@ -1848,7 +1863,8 @@ matmul_r17_vanilla (gfc_array_r17 * const restrict retarray,
 
   index_type rxstride, rystride, axstride, aystride, bxstride, bystride;
   index_type x, y, n, count, xcount, ycount;
-  index_type aystride_bytes, bystride_bytes, rystride_bytes;
+  index_type axstride_bytes, aystride_bytes, bxstride_bytes, bystride_bytes,
+	     rxstride_bytes, rystride_bytes;
 
   assert (GFC_DESCRIPTOR_RANK (a) == 2
           || GFC_DESCRIPTOR_RANK (b) == 2);
@@ -1937,12 +1953,13 @@ matmul_r17_vanilla (gfc_array_r17 * const restrict retarray,
 	 either as a row or a column matrix. We want both cases to
 	 work. */
       rxstride = rystride = GFC_DESCRIPTOR_STRIDE(retarray,0);
-      rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
+      rxstride_bytes = rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
     }
   else
     {
       rxstride = GFC_DESCRIPTOR_STRIDE(retarray,0);
       rystride = GFC_DESCRIPTOR_STRIDE(retarray,1);
+      rxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
       rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,1);
     }
 
@@ -1951,6 +1968,7 @@ matmul_r17_vanilla (gfc_array_r17 * const restrict retarray,
       /* Treat it as a a row matrix A[1,count]. */
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = 1;
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = sizeof (GFC_REAL_17);
 
       xcount = 1;
@@ -1960,6 +1978,7 @@ matmul_r17_vanilla (gfc_array_r17 * const restrict retarray,
     {
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = GFC_DESCRIPTOR_STRIDE(a,1);
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,1);
 
       count = GFC_DESCRIPTOR_EXTENT(a,1);
@@ -1978,17 +1997,20 @@ matmul_r17_vanilla (gfc_array_r17 * const restrict retarray,
     {
       /* Treat it as a column matrix B[count,1] */
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
 
       /* bystride should never be used for 1-dimensional b.
          The value is only used for calculation of the
          memory by the buffer.  */
       bystride = 256;
+      bystride_bytes = 99999999;
       ycount = 1;
     }
   else
     {
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
       bystride = GFC_DESCRIPTOR_STRIDE(b,1);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
       bystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,1);
       ycount = GFC_DESCRIPTOR_EXTENT(b,1);
     }
@@ -2048,12 +2070,11 @@ matmul_r17_vanilla (gfc_array_r17 * const restrict retarray,
 
 	 from netlib.org, translated to C, and modified for matmul.m4.  */
 
-      const GFC_REAL_17 *a, *b;
       GFC_REAL_17 *c;
       const index_type m = xcount, n = ycount, k = count;
 
       /* System generated locals */
-      index_type a_dim1, b_dim1, c_dim1,
+      index_type a_dim1, b_dim1,
 		 i1, i2, i3, i4, i5, i6;
 
       /* Local variables */
@@ -2063,25 +2084,22 @@ matmul_r17_vanilla (gfc_array_r17 * const restrict retarray,
       index_type isec, jsec, lsec, uisec, ujsec, ulsec;
       GFC_REAL_17 *t1;
 
-      a = abase;
-      b = bbase;
       c = retarray->base_addr;
 
       /* Parameter adjustments */
-      c_dim1 = rystride;
       a_dim1 = aystride;
       b_dim1 = bystride;
 
 #define A_ARRAY_ELEM(i,j) \
-    a[(i) + (j) * a_dim1]
+    (ARRAY_ELEM_AT_OFFSET (abase, (i) * sizeof (GFC_REAL_17) + (j) * aystride_bytes))
 
 #define B_ARRAY_ELEM(i,j) \
-    b[(i) + (j) * b_dim1]
+    (ARRAY_ELEM_AT_OFFSET (bbase, (i) * sizeof (GFC_REAL_17) + (j) * bystride_bytes))
 
 #define C_ARRAY_ELEM(i,j) \
-    c[(i) + (j) * c_dim1]
+    (ARRAY_ELEM_AT_OFFSET (c, (i) * sizeof (GFC_REAL_17) + (j) * rystride_bytes))
 
-      /* Empty c first.  */
+      /* Empty result first.  */
       for (j=0; j<n; j++)
 	for (i=0; i<m; i++)
 	  C_ARRAY_ELEM (i, j) = (GFC_REAL_17)0;
@@ -2329,11 +2347,11 @@ matmul_r17_vanilla (gfc_array_r17 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
-	      dest_y = &dest[y*rystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	      dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	      for (x = 0; x < xcount; x++)
 		{
-		  abase_x = &abase[x*axstride];
+		  abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 		  s = (GFC_REAL_17) 0;
 		  for (n = 0; n < count; n++)
 		    s += abase_x[n] * bbase_y[n];
@@ -2348,11 +2366,11 @@ matmul_r17_vanilla (gfc_array_r17 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	      s = (GFC_REAL_17) 0;
 	      for (n = 0; n < count; n++)
 		s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n];
-	      dest[y*rystride] = s;
+	      ARRAY_ELEM_AT_OFFSET (dest, y * rystride_bytes) = s;
 	    }
 	}
     }
@@ -2363,10 +2381,11 @@ matmul_r17_vanilla (gfc_array_r17 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	  s = (GFC_REAL_17) 0;
 	  for (n = 0; n < count; n++)
-	    s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n*bxstride];
+	    s += GFC_DESCRIPTOR1_ELEM (a, n)
+	         * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
 	  GFC_DESCRIPTOR1_ELEM (retarray, y) = s;
 	}
     }
@@ -2393,15 +2412,16 @@ matmul_r17_vanilla (gfc_array_r17 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
-	  dest_y = &dest[y*rystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	  dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	  for (x = 0; x < xcount; x++)
 	    {
-	      abase_x = &abase[x*axstride];
+	      abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 	      s = (GFC_REAL_17) 0;
 	      for (n = 0; n < count; n++)
-		s += abase_x[n*aystride] * bbase_y[n*bxstride];
-	      dest_y[x*rxstride] = s;
+		s += ARRAY_ELEM_AT_OFFSET (abase_x, n * aystride_bytes)
+		     * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
+	      ARRAY_ELEM_AT_OFFSET (dest_y, x * rxstride_bytes) = s;
 	    }
 	}
     }
@@ -2501,7 +2521,8 @@ matmul_r17 (gfc_array_r17 * const restrict retarray,
 
   index_type rxstride, rystride, axstride, aystride, bxstride, bystride;
   index_type x, y, n, count, xcount, ycount;
-  index_type aystride_bytes, bystride_bytes, rystride_bytes;
+  index_type axstride_bytes, aystride_bytes, bxstride_bytes, bystride_bytes,
+	     rxstride_bytes, rystride_bytes;
 
   assert (GFC_DESCRIPTOR_RANK (a) == 2
           || GFC_DESCRIPTOR_RANK (b) == 2);
@@ -2590,12 +2611,13 @@ matmul_r17 (gfc_array_r17 * const restrict retarray,
 	 either as a row or a column matrix. We want both cases to
 	 work. */
       rxstride = rystride = GFC_DESCRIPTOR_STRIDE(retarray,0);
-      rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
+      rxstride_bytes = rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
     }
   else
     {
       rxstride = GFC_DESCRIPTOR_STRIDE(retarray,0);
       rystride = GFC_DESCRIPTOR_STRIDE(retarray,1);
+      rxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
       rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,1);
     }
 
@@ -2604,6 +2626,7 @@ matmul_r17 (gfc_array_r17 * const restrict retarray,
       /* Treat it as a a row matrix A[1,count]. */
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = 1;
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = sizeof (GFC_REAL_17);
 
       xcount = 1;
@@ -2613,6 +2636,7 @@ matmul_r17 (gfc_array_r17 * const restrict retarray,
     {
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = GFC_DESCRIPTOR_STRIDE(a,1);
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,1);
 
       count = GFC_DESCRIPTOR_EXTENT(a,1);
@@ -2631,17 +2655,20 @@ matmul_r17 (gfc_array_r17 * const restrict retarray,
     {
       /* Treat it as a column matrix B[count,1] */
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
 
       /* bystride should never be used for 1-dimensional b.
          The value is only used for calculation of the
          memory by the buffer.  */
       bystride = 256;
+      bystride_bytes = 99999999;
       ycount = 1;
     }
   else
     {
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
       bystride = GFC_DESCRIPTOR_STRIDE(b,1);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
       bystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,1);
       ycount = GFC_DESCRIPTOR_EXTENT(b,1);
     }
@@ -2701,12 +2728,11 @@ matmul_r17 (gfc_array_r17 * const restrict retarray,
 
 	 from netlib.org, translated to C, and modified for matmul.m4.  */
 
-      const GFC_REAL_17 *a, *b;
       GFC_REAL_17 *c;
       const index_type m = xcount, n = ycount, k = count;
 
       /* System generated locals */
-      index_type a_dim1, b_dim1, c_dim1,
+      index_type a_dim1, b_dim1,
 		 i1, i2, i3, i4, i5, i6;
 
       /* Local variables */
@@ -2716,25 +2742,22 @@ matmul_r17 (gfc_array_r17 * const restrict retarray,
       index_type isec, jsec, lsec, uisec, ujsec, ulsec;
       GFC_REAL_17 *t1;
 
-      a = abase;
-      b = bbase;
       c = retarray->base_addr;
 
       /* Parameter adjustments */
-      c_dim1 = rystride;
       a_dim1 = aystride;
       b_dim1 = bystride;
 
 #define A_ARRAY_ELEM(i,j) \
-    a[(i) + (j) * a_dim1]
+    (ARRAY_ELEM_AT_OFFSET (abase, (i) * sizeof (GFC_REAL_17) + (j) * aystride_bytes))
 
 #define B_ARRAY_ELEM(i,j) \
-    b[(i) + (j) * b_dim1]
+    (ARRAY_ELEM_AT_OFFSET (bbase, (i) * sizeof (GFC_REAL_17) + (j) * bystride_bytes))
 
 #define C_ARRAY_ELEM(i,j) \
-    c[(i) + (j) * c_dim1]
+    (ARRAY_ELEM_AT_OFFSET (c, (i) * sizeof (GFC_REAL_17) + (j) * rystride_bytes))
 
-      /* Empty c first.  */
+      /* Empty result first.  */
       for (j=0; j<n; j++)
 	for (i=0; i<m; i++)
 	  C_ARRAY_ELEM (i, j) = (GFC_REAL_17)0;
@@ -2982,11 +3005,11 @@ matmul_r17 (gfc_array_r17 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
-	      dest_y = &dest[y*rystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	      dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	      for (x = 0; x < xcount; x++)
 		{
-		  abase_x = &abase[x*axstride];
+		  abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 		  s = (GFC_REAL_17) 0;
 		  for (n = 0; n < count; n++)
 		    s += abase_x[n] * bbase_y[n];
@@ -3001,11 +3024,11 @@ matmul_r17 (gfc_array_r17 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	      s = (GFC_REAL_17) 0;
 	      for (n = 0; n < count; n++)
 		s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n];
-	      dest[y*rystride] = s;
+	      ARRAY_ELEM_AT_OFFSET (dest, y * rystride_bytes) = s;
 	    }
 	}
     }
@@ -3016,10 +3039,11 @@ matmul_r17 (gfc_array_r17 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	  s = (GFC_REAL_17) 0;
 	  for (n = 0; n < count; n++)
-	    s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n*bxstride];
+	    s += GFC_DESCRIPTOR1_ELEM (a, n)
+	         * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
 	  GFC_DESCRIPTOR1_ELEM (retarray, y) = s;
 	}
     }
@@ -3046,15 +3070,16 @@ matmul_r17 (gfc_array_r17 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
-	  dest_y = &dest[y*rystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	  dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	  for (x = 0; x < xcount; x++)
 	    {
-	      abase_x = &abase[x*axstride];
+	      abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 	      s = (GFC_REAL_17) 0;
 	      for (n = 0; n < count; n++)
-		s += abase_x[n*aystride] * bbase_y[n*bxstride];
-	      dest_y[x*rxstride] = s;
+		s += ARRAY_ELEM_AT_OFFSET (abase_x, n * aystride_bytes)
+		     * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
+	      ARRAY_ELEM_AT_OFFSET (dest_y, x * rxstride_bytes) = s;
 	    }
 	}
     }
diff --git a/libgfortran/generated/matmul_r4.c b/libgfortran/generated/matmul_r4.c
index 127e32b09763..ee36b1ec6d0d 100644
--- a/libgfortran/generated/matmul_r4.c
+++ b/libgfortran/generated/matmul_r4.c
@@ -94,7 +94,8 @@ matmul_r4_avx (gfc_array_r4 * const restrict retarray,
 
   index_type rxstride, rystride, axstride, aystride, bxstride, bystride;
   index_type x, y, n, count, xcount, ycount;
-  index_type aystride_bytes, bystride_bytes, rystride_bytes;
+  index_type axstride_bytes, aystride_bytes, bxstride_bytes, bystride_bytes,
+	     rxstride_bytes, rystride_bytes;
 
   assert (GFC_DESCRIPTOR_RANK (a) == 2
           || GFC_DESCRIPTOR_RANK (b) == 2);
@@ -183,12 +184,13 @@ matmul_r4_avx (gfc_array_r4 * const restrict retarray,
 	 either as a row or a column matrix. We want both cases to
 	 work. */
       rxstride = rystride = GFC_DESCRIPTOR_STRIDE(retarray,0);
-      rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
+      rxstride_bytes = rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
     }
   else
     {
       rxstride = GFC_DESCRIPTOR_STRIDE(retarray,0);
       rystride = GFC_DESCRIPTOR_STRIDE(retarray,1);
+      rxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
       rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,1);
     }
 
@@ -197,6 +199,7 @@ matmul_r4_avx (gfc_array_r4 * const restrict retarray,
       /* Treat it as a a row matrix A[1,count]. */
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = 1;
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = sizeof (GFC_REAL_4);
 
       xcount = 1;
@@ -206,6 +209,7 @@ matmul_r4_avx (gfc_array_r4 * const restrict retarray,
     {
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = GFC_DESCRIPTOR_STRIDE(a,1);
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,1);
 
       count = GFC_DESCRIPTOR_EXTENT(a,1);
@@ -224,17 +228,20 @@ matmul_r4_avx (gfc_array_r4 * const restrict retarray,
     {
       /* Treat it as a column matrix B[count,1] */
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
 
       /* bystride should never be used for 1-dimensional b.
          The value is only used for calculation of the
          memory by the buffer.  */
       bystride = 256;
+      bystride_bytes = 99999999;
       ycount = 1;
     }
   else
     {
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
       bystride = GFC_DESCRIPTOR_STRIDE(b,1);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
       bystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,1);
       ycount = GFC_DESCRIPTOR_EXTENT(b,1);
     }
@@ -294,12 +301,11 @@ matmul_r4_avx (gfc_array_r4 * const restrict retarray,
 
 	 from netlib.org, translated to C, and modified for matmul.m4.  */
 
-      const GFC_REAL_4 *a, *b;
       GFC_REAL_4 *c;
       const index_type m = xcount, n = ycount, k = count;
 
       /* System generated locals */
-      index_type a_dim1, b_dim1, c_dim1,
+      index_type a_dim1, b_dim1,
 		 i1, i2, i3, i4, i5, i6;
 
       /* Local variables */
@@ -309,25 +315,22 @@ matmul_r4_avx (gfc_array_r4 * const restrict retarray,
       index_type isec, jsec, lsec, uisec, ujsec, ulsec;
       GFC_REAL_4 *t1;
 
-      a = abase;
-      b = bbase;
       c = retarray->base_addr;
 
       /* Parameter adjustments */
-      c_dim1 = rystride;
       a_dim1 = aystride;
       b_dim1 = bystride;
 
 #define A_ARRAY_ELEM(i,j) \
-    a[(i) + (j) * a_dim1]
+    (ARRAY_ELEM_AT_OFFSET (abase, (i) * sizeof (GFC_REAL_4) + (j) * aystride_bytes))
 
 #define B_ARRAY_ELEM(i,j) \
-    b[(i) + (j) * b_dim1]
+    (ARRAY_ELEM_AT_OFFSET (bbase, (i) * sizeof (GFC_REAL_4) + (j) * bystride_bytes))
 
 #define C_ARRAY_ELEM(i,j) \
-    c[(i) + (j) * c_dim1]
+    (ARRAY_ELEM_AT_OFFSET (c, (i) * sizeof (GFC_REAL_4) + (j) * rystride_bytes))
 
-      /* Empty c first.  */
+      /* Empty result first.  */
       for (j=0; j<n; j++)
 	for (i=0; i<m; i++)
 	  C_ARRAY_ELEM (i, j) = (GFC_REAL_4)0;
@@ -575,11 +578,11 @@ matmul_r4_avx (gfc_array_r4 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
-	      dest_y = &dest[y*rystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	      dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	      for (x = 0; x < xcount; x++)
 		{
-		  abase_x = &abase[x*axstride];
+		  abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 		  s = (GFC_REAL_4) 0;
 		  for (n = 0; n < count; n++)
 		    s += abase_x[n] * bbase_y[n];
@@ -594,11 +597,11 @@ matmul_r4_avx (gfc_array_r4 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	      s = (GFC_REAL_4) 0;
 	      for (n = 0; n < count; n++)
 		s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n];
-	      dest[y*rystride] = s;
+	      ARRAY_ELEM_AT_OFFSET (dest, y * rystride_bytes) = s;
 	    }
 	}
     }
@@ -609,10 +612,11 @@ matmul_r4_avx (gfc_array_r4 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	  s = (GFC_REAL_4) 0;
 	  for (n = 0; n < count; n++)
-	    s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n*bxstride];
+	    s += GFC_DESCRIPTOR1_ELEM (a, n)
+	         * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
 	  GFC_DESCRIPTOR1_ELEM (retarray, y) = s;
 	}
     }
@@ -639,15 +643,16 @@ matmul_r4_avx (gfc_array_r4 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
-	  dest_y = &dest[y*rystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	  dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	  for (x = 0; x < xcount; x++)
 	    {
-	      abase_x = &abase[x*axstride];
+	      abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 	      s = (GFC_REAL_4) 0;
 	      for (n = 0; n < count; n++)
-		s += abase_x[n*aystride] * bbase_y[n*bxstride];
-	      dest_y[x*rxstride] = s;
+		s += ARRAY_ELEM_AT_OFFSET (abase_x, n * aystride_bytes)
+		     * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
+	      ARRAY_ELEM_AT_OFFSET (dest_y, x * rxstride_bytes) = s;
 	    }
 	}
     }
@@ -674,7 +679,8 @@ matmul_r4_avx2 (gfc_array_r4 * const restrict retarray,
 
   index_type rxstride, rystride, axstride, aystride, bxstride, bystride;
   index_type x, y, n, count, xcount, ycount;
-  index_type aystride_bytes, bystride_bytes, rystride_bytes;
+  index_type axstride_bytes, aystride_bytes, bxstride_bytes, bystride_bytes,
+	     rxstride_bytes, rystride_bytes;
 
   assert (GFC_DESCRIPTOR_RANK (a) == 2
           || GFC_DESCRIPTOR_RANK (b) == 2);
@@ -763,12 +769,13 @@ matmul_r4_avx2 (gfc_array_r4 * const restrict retarray,
 	 either as a row or a column matrix. We want both cases to
 	 work. */
       rxstride = rystride = GFC_DESCRIPTOR_STRIDE(retarray,0);
-      rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
+      rxstride_bytes = rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
     }
   else
     {
       rxstride = GFC_DESCRIPTOR_STRIDE(retarray,0);
       rystride = GFC_DESCRIPTOR_STRIDE(retarray,1);
+      rxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
       rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,1);
     }
 
@@ -777,6 +784,7 @@ matmul_r4_avx2 (gfc_array_r4 * const restrict retarray,
       /* Treat it as a a row matrix A[1,count]. */
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = 1;
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = sizeof (GFC_REAL_4);
 
       xcount = 1;
@@ -786,6 +794,7 @@ matmul_r4_avx2 (gfc_array_r4 * const restrict retarray,
     {
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = GFC_DESCRIPTOR_STRIDE(a,1);
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,1);
 
       count = GFC_DESCRIPTOR_EXTENT(a,1);
@@ -804,17 +813,20 @@ matmul_r4_avx2 (gfc_array_r4 * const restrict retarray,
     {
       /* Treat it as a column matrix B[count,1] */
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
 
       /* bystride should never be used for 1-dimensional b.
          The value is only used for calculation of the
          memory by the buffer.  */
       bystride = 256;
+      bystride_bytes = 99999999;
       ycount = 1;
     }
   else
     {
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
       bystride = GFC_DESCRIPTOR_STRIDE(b,1);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
       bystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,1);
       ycount = GFC_DESCRIPTOR_EXTENT(b,1);
     }
@@ -874,12 +886,11 @@ matmul_r4_avx2 (gfc_array_r4 * const restrict retarray,
 
 	 from netlib.org, translated to C, and modified for matmul.m4.  */
 
-      const GFC_REAL_4 *a, *b;
       GFC_REAL_4 *c;
       const index_type m = xcount, n = ycount, k = count;
 
       /* System generated locals */
-      index_type a_dim1, b_dim1, c_dim1,
+      index_type a_dim1, b_dim1,
 		 i1, i2, i3, i4, i5, i6;
 
       /* Local variables */
@@ -889,25 +900,22 @@ matmul_r4_avx2 (gfc_array_r4 * const restrict retarray,
       index_type isec, jsec, lsec, uisec, ujsec, ulsec;
       GFC_REAL_4 *t1;
 
-      a = abase;
-      b = bbase;
       c = retarray->base_addr;
 
       /* Parameter adjustments */
-      c_dim1 = rystride;
       a_dim1 = aystride;
       b_dim1 = bystride;
 
 #define A_ARRAY_ELEM(i,j) \
-    a[(i) + (j) * a_dim1]
+    (ARRAY_ELEM_AT_OFFSET (abase, (i) * sizeof (GFC_REAL_4) + (j) * aystride_bytes))
 
 #define B_ARRAY_ELEM(i,j) \
-    b[(i) + (j) * b_dim1]
+    (ARRAY_ELEM_AT_OFFSET (bbase, (i) * sizeof (GFC_REAL_4) + (j) * bystride_bytes))
 
 #define C_ARRAY_ELEM(i,j) \
-    c[(i) + (j) * c_dim1]
+    (ARRAY_ELEM_AT_OFFSET (c, (i) * sizeof (GFC_REAL_4) + (j) * rystride_bytes))
 
-      /* Empty c first.  */
+      /* Empty result first.  */
       for (j=0; j<n; j++)
 	for (i=0; i<m; i++)
 	  C_ARRAY_ELEM (i, j) = (GFC_REAL_4)0;
@@ -1155,11 +1163,11 @@ matmul_r4_avx2 (gfc_array_r4 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
-	      dest_y = &dest[y*rystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	      dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	      for (x = 0; x < xcount; x++)
 		{
-		  abase_x = &abase[x*axstride];
+		  abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 		  s = (GFC_REAL_4) 0;
 		  for (n = 0; n < count; n++)
 		    s += abase_x[n] * bbase_y[n];
@@ -1174,11 +1182,11 @@ matmul_r4_avx2 (gfc_array_r4 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	      s = (GFC_REAL_4) 0;
 	      for (n = 0; n < count; n++)
 		s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n];
-	      dest[y*rystride] = s;
+	      ARRAY_ELEM_AT_OFFSET (dest, y * rystride_bytes) = s;
 	    }
 	}
     }
@@ -1189,10 +1197,11 @@ matmul_r4_avx2 (gfc_array_r4 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	  s = (GFC_REAL_4) 0;
 	  for (n = 0; n < count; n++)
-	    s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n*bxstride];
+	    s += GFC_DESCRIPTOR1_ELEM (a, n)
+	         * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
 	  GFC_DESCRIPTOR1_ELEM (retarray, y) = s;
 	}
     }
@@ -1219,15 +1228,16 @@ matmul_r4_avx2 (gfc_array_r4 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
-	  dest_y = &dest[y*rystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	  dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	  for (x = 0; x < xcount; x++)
 	    {
-	      abase_x = &abase[x*axstride];
+	      abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 	      s = (GFC_REAL_4) 0;
 	      for (n = 0; n < count; n++)
-		s += abase_x[n*aystride] * bbase_y[n*bxstride];
-	      dest_y[x*rxstride] = s;
+		s += ARRAY_ELEM_AT_OFFSET (abase_x, n * aystride_bytes)
+		     * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
+	      ARRAY_ELEM_AT_OFFSET (dest_y, x * rxstride_bytes) = s;
 	    }
 	}
     }
@@ -1254,7 +1264,8 @@ matmul_r4_avx512f (gfc_array_r4 * const restrict retarray,
 
   index_type rxstride, rystride, axstride, aystride, bxstride, bystride;
   index_type x, y, n, count, xcount, ycount;
-  index_type aystride_bytes, bystride_bytes, rystride_bytes;
+  index_type axstride_bytes, aystride_bytes, bxstride_bytes, bystride_bytes,
+	     rxstride_bytes, rystride_bytes;
 
   assert (GFC_DESCRIPTOR_RANK (a) == 2
           || GFC_DESCRIPTOR_RANK (b) == 2);
@@ -1343,12 +1354,13 @@ matmul_r4_avx512f (gfc_array_r4 * const restrict retarray,
 	 either as a row or a column matrix. We want both cases to
 	 work. */
       rxstride = rystride = GFC_DESCRIPTOR_STRIDE(retarray,0);
-      rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
+      rxstride_bytes = rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
     }
   else
     {
       rxstride = GFC_DESCRIPTOR_STRIDE(retarray,0);
       rystride = GFC_DESCRIPTOR_STRIDE(retarray,1);
+      rxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
       rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,1);
     }
 
@@ -1357,6 +1369,7 @@ matmul_r4_avx512f (gfc_array_r4 * const restrict retarray,
       /* Treat it as a a row matrix A[1,count]. */
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = 1;
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = sizeof (GFC_REAL_4);
 
       xcount = 1;
@@ -1366,6 +1379,7 @@ matmul_r4_avx512f (gfc_array_r4 * const restrict retarray,
     {
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = GFC_DESCRIPTOR_STRIDE(a,1);
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,1);
 
       count = GFC_DESCRIPTOR_EXTENT(a,1);
@@ -1384,17 +1398,20 @@ matmul_r4_avx512f (gfc_array_r4 * const restrict retarray,
     {
       /* Treat it as a column matrix B[count,1] */
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
 
       /* bystride should never be used for 1-dimensional b.
          The value is only used for calculation of the
          memory by the buffer.  */
       bystride = 256;
+      bystride_bytes = 99999999;
       ycount = 1;
     }
   else
     {
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
       bystride = GFC_DESCRIPTOR_STRIDE(b,1);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
       bystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,1);
       ycount = GFC_DESCRIPTOR_EXTENT(b,1);
     }
@@ -1454,12 +1471,11 @@ matmul_r4_avx512f (gfc_array_r4 * const restrict retarray,
 
 	 from netlib.org, translated to C, and modified for matmul.m4.  */
 
-      const GFC_REAL_4 *a, *b;
       GFC_REAL_4 *c;
       const index_type m = xcount, n = ycount, k = count;
 
       /* System generated locals */
-      index_type a_dim1, b_dim1, c_dim1,
+      index_type a_dim1, b_dim1,
 		 i1, i2, i3, i4, i5, i6;
 
       /* Local variables */
@@ -1469,25 +1485,22 @@ matmul_r4_avx512f (gfc_array_r4 * const restrict retarray,
       index_type isec, jsec, lsec, uisec, ujsec, ulsec;
       GFC_REAL_4 *t1;
 
-      a = abase;
-      b = bbase;
       c = retarray->base_addr;
 
       /* Parameter adjustments */
-      c_dim1 = rystride;
       a_dim1 = aystride;
       b_dim1 = bystride;
 
 #define A_ARRAY_ELEM(i,j) \
-    a[(i) + (j) * a_dim1]
+    (ARRAY_ELEM_AT_OFFSET (abase, (i) * sizeof (GFC_REAL_4) + (j) * aystride_bytes))
 
 #define B_ARRAY_ELEM(i,j) \
-    b[(i) + (j) * b_dim1]
+    (ARRAY_ELEM_AT_OFFSET (bbase, (i) * sizeof (GFC_REAL_4) + (j) * bystride_bytes))
 
 #define C_ARRAY_ELEM(i,j) \
-    c[(i) + (j) * c_dim1]
+    (ARRAY_ELEM_AT_OFFSET (c, (i) * sizeof (GFC_REAL_4) + (j) * rystride_bytes))
 
-      /* Empty c first.  */
+      /* Empty result first.  */
       for (j=0; j<n; j++)
 	for (i=0; i<m; i++)
 	  C_ARRAY_ELEM (i, j) = (GFC_REAL_4)0;
@@ -1735,11 +1748,11 @@ matmul_r4_avx512f (gfc_array_r4 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
-	      dest_y = &dest[y*rystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	      dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	      for (x = 0; x < xcount; x++)
 		{
-		  abase_x = &abase[x*axstride];
+		  abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 		  s = (GFC_REAL_4) 0;
 		  for (n = 0; n < count; n++)
 		    s += abase_x[n] * bbase_y[n];
@@ -1754,11 +1767,11 @@ matmul_r4_avx512f (gfc_array_r4 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	      s = (GFC_REAL_4) 0;
 	      for (n = 0; n < count; n++)
 		s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n];
-	      dest[y*rystride] = s;
+	      ARRAY_ELEM_AT_OFFSET (dest, y * rystride_bytes) = s;
 	    }
 	}
     }
@@ -1769,10 +1782,11 @@ matmul_r4_avx512f (gfc_array_r4 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	  s = (GFC_REAL_4) 0;
 	  for (n = 0; n < count; n++)
-	    s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n*bxstride];
+	    s += GFC_DESCRIPTOR1_ELEM (a, n)
+	         * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
 	  GFC_DESCRIPTOR1_ELEM (retarray, y) = s;
 	}
     }
@@ -1799,15 +1813,16 @@ matmul_r4_avx512f (gfc_array_r4 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
-	  dest_y = &dest[y*rystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	  dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	  for (x = 0; x < xcount; x++)
 	    {
-	      abase_x = &abase[x*axstride];
+	      abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 	      s = (GFC_REAL_4) 0;
 	      for (n = 0; n < count; n++)
-		s += abase_x[n*aystride] * bbase_y[n*bxstride];
-	      dest_y[x*rxstride] = s;
+		s += ARRAY_ELEM_AT_OFFSET (abase_x, n * aystride_bytes)
+		     * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
+	      ARRAY_ELEM_AT_OFFSET (dest_y, x * rxstride_bytes) = s;
 	    }
 	}
     }
@@ -1848,7 +1863,8 @@ matmul_r4_vanilla (gfc_array_r4 * const restrict retarray,
 
   index_type rxstride, rystride, axstride, aystride, bxstride, bystride;
   index_type x, y, n, count, xcount, ycount;
-  index_type aystride_bytes, bystride_bytes, rystride_bytes;
+  index_type axstride_bytes, aystride_bytes, bxstride_bytes, bystride_bytes,
+	     rxstride_bytes, rystride_bytes;
 
   assert (GFC_DESCRIPTOR_RANK (a) == 2
           || GFC_DESCRIPTOR_RANK (b) == 2);
@@ -1937,12 +1953,13 @@ matmul_r4_vanilla (gfc_array_r4 * const restrict retarray,
 	 either as a row or a column matrix. We want both cases to
 	 work. */
       rxstride = rystride = GFC_DESCRIPTOR_STRIDE(retarray,0);
-      rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
+      rxstride_bytes = rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
     }
   else
     {
       rxstride = GFC_DESCRIPTOR_STRIDE(retarray,0);
       rystride = GFC_DESCRIPTOR_STRIDE(retarray,1);
+      rxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
       rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,1);
     }
 
@@ -1951,6 +1968,7 @@ matmul_r4_vanilla (gfc_array_r4 * const restrict retarray,
       /* Treat it as a a row matrix A[1,count]. */
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = 1;
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = sizeof (GFC_REAL_4);
 
       xcount = 1;
@@ -1960,6 +1978,7 @@ matmul_r4_vanilla (gfc_array_r4 * const restrict retarray,
     {
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = GFC_DESCRIPTOR_STRIDE(a,1);
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,1);
 
       count = GFC_DESCRIPTOR_EXTENT(a,1);
@@ -1978,17 +1997,20 @@ matmul_r4_vanilla (gfc_array_r4 * const restrict retarray,
     {
       /* Treat it as a column matrix B[count,1] */
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
 
       /* bystride should never be used for 1-dimensional b.
          The value is only used for calculation of the
          memory by the buffer.  */
       bystride = 256;
+      bystride_bytes = 99999999;
       ycount = 1;
     }
   else
     {
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
       bystride = GFC_DESCRIPTOR_STRIDE(b,1);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
       bystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,1);
       ycount = GFC_DESCRIPTOR_EXTENT(b,1);
     }
@@ -2048,12 +2070,11 @@ matmul_r4_vanilla (gfc_array_r4 * const restrict retarray,
 
 	 from netlib.org, translated to C, and modified for matmul.m4.  */
 
-      const GFC_REAL_4 *a, *b;
       GFC_REAL_4 *c;
       const index_type m = xcount, n = ycount, k = count;
 
       /* System generated locals */
-      index_type a_dim1, b_dim1, c_dim1,
+      index_type a_dim1, b_dim1,
 		 i1, i2, i3, i4, i5, i6;
 
       /* Local variables */
@@ -2063,25 +2084,22 @@ matmul_r4_vanilla (gfc_array_r4 * const restrict retarray,
       index_type isec, jsec, lsec, uisec, ujsec, ulsec;
       GFC_REAL_4 *t1;
 
-      a = abase;
-      b = bbase;
       c = retarray->base_addr;
 
       /* Parameter adjustments */
-      c_dim1 = rystride;
       a_dim1 = aystride;
       b_dim1 = bystride;
 
 #define A_ARRAY_ELEM(i,j) \
-    a[(i) + (j) * a_dim1]
+    (ARRAY_ELEM_AT_OFFSET (abase, (i) * sizeof (GFC_REAL_4) + (j) * aystride_bytes))
 
 #define B_ARRAY_ELEM(i,j) \
-    b[(i) + (j) * b_dim1]
+    (ARRAY_ELEM_AT_OFFSET (bbase, (i) * sizeof (GFC_REAL_4) + (j) * bystride_bytes))
 
 #define C_ARRAY_ELEM(i,j) \
-    c[(i) + (j) * c_dim1]
+    (ARRAY_ELEM_AT_OFFSET (c, (i) * sizeof (GFC_REAL_4) + (j) * rystride_bytes))
 
-      /* Empty c first.  */
+      /* Empty result first.  */
       for (j=0; j<n; j++)
 	for (i=0; i<m; i++)
 	  C_ARRAY_ELEM (i, j) = (GFC_REAL_4)0;
@@ -2329,11 +2347,11 @@ matmul_r4_vanilla (gfc_array_r4 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
-	      dest_y = &dest[y*rystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	      dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	      for (x = 0; x < xcount; x++)
 		{
-		  abase_x = &abase[x*axstride];
+		  abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 		  s = (GFC_REAL_4) 0;
 		  for (n = 0; n < count; n++)
 		    s += abase_x[n] * bbase_y[n];
@@ -2348,11 +2366,11 @@ matmul_r4_vanilla (gfc_array_r4 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	      s = (GFC_REAL_4) 0;
 	      for (n = 0; n < count; n++)
 		s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n];
-	      dest[y*rystride] = s;
+	      ARRAY_ELEM_AT_OFFSET (dest, y * rystride_bytes) = s;
 	    }
 	}
     }
@@ -2363,10 +2381,11 @@ matmul_r4_vanilla (gfc_array_r4 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	  s = (GFC_REAL_4) 0;
 	  for (n = 0; n < count; n++)
-	    s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n*bxstride];
+	    s += GFC_DESCRIPTOR1_ELEM (a, n)
+	         * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
 	  GFC_DESCRIPTOR1_ELEM (retarray, y) = s;
 	}
     }
@@ -2393,15 +2412,16 @@ matmul_r4_vanilla (gfc_array_r4 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
-	  dest_y = &dest[y*rystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	  dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	  for (x = 0; x < xcount; x++)
 	    {
-	      abase_x = &abase[x*axstride];
+	      abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 	      s = (GFC_REAL_4) 0;
 	      for (n = 0; n < count; n++)
-		s += abase_x[n*aystride] * bbase_y[n*bxstride];
-	      dest_y[x*rxstride] = s;
+		s += ARRAY_ELEM_AT_OFFSET (abase_x, n * aystride_bytes)
+		     * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
+	      ARRAY_ELEM_AT_OFFSET (dest_y, x * rxstride_bytes) = s;
 	    }
 	}
     }
@@ -2501,7 +2521,8 @@ matmul_r4 (gfc_array_r4 * const restrict retarray,
 
   index_type rxstride, rystride, axstride, aystride, bxstride, bystride;
   index_type x, y, n, count, xcount, ycount;
-  index_type aystride_bytes, bystride_bytes, rystride_bytes;
+  index_type axstride_bytes, aystride_bytes, bxstride_bytes, bystride_bytes,
+	     rxstride_bytes, rystride_bytes;
 
   assert (GFC_DESCRIPTOR_RANK (a) == 2
           || GFC_DESCRIPTOR_RANK (b) == 2);
@@ -2590,12 +2611,13 @@ matmul_r4 (gfc_array_r4 * const restrict retarray,
 	 either as a row or a column matrix. We want both cases to
 	 work. */
       rxstride = rystride = GFC_DESCRIPTOR_STRIDE(retarray,0);
-      rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
+      rxstride_bytes = rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
     }
   else
     {
       rxstride = GFC_DESCRIPTOR_STRIDE(retarray,0);
       rystride = GFC_DESCRIPTOR_STRIDE(retarray,1);
+      rxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
       rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,1);
     }
 
@@ -2604,6 +2626,7 @@ matmul_r4 (gfc_array_r4 * const restrict retarray,
       /* Treat it as a a row matrix A[1,count]. */
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = 1;
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = sizeof (GFC_REAL_4);
 
       xcount = 1;
@@ -2613,6 +2636,7 @@ matmul_r4 (gfc_array_r4 * const restrict retarray,
     {
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = GFC_DESCRIPTOR_STRIDE(a,1);
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,1);
 
       count = GFC_DESCRIPTOR_EXTENT(a,1);
@@ -2631,17 +2655,20 @@ matmul_r4 (gfc_array_r4 * const restrict retarray,
     {
       /* Treat it as a column matrix B[count,1] */
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
 
       /* bystride should never be used for 1-dimensional b.
          The value is only used for calculation of the
          memory by the buffer.  */
       bystride = 256;
+      bystride_bytes = 99999999;
       ycount = 1;
     }
   else
     {
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
       bystride = GFC_DESCRIPTOR_STRIDE(b,1);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
       bystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,1);
       ycount = GFC_DESCRIPTOR_EXTENT(b,1);
     }
@@ -2701,12 +2728,11 @@ matmul_r4 (gfc_array_r4 * const restrict retarray,
 
 	 from netlib.org, translated to C, and modified for matmul.m4.  */
 
-      const GFC_REAL_4 *a, *b;
       GFC_REAL_4 *c;
       const index_type m = xcount, n = ycount, k = count;
 
       /* System generated locals */
-      index_type a_dim1, b_dim1, c_dim1,
+      index_type a_dim1, b_dim1,
 		 i1, i2, i3, i4, i5, i6;
 
       /* Local variables */
@@ -2716,25 +2742,22 @@ matmul_r4 (gfc_array_r4 * const restrict retarray,
       index_type isec, jsec, lsec, uisec, ujsec, ulsec;
       GFC_REAL_4 *t1;
 
-      a = abase;
-      b = bbase;
       c = retarray->base_addr;
 
       /* Parameter adjustments */
-      c_dim1 = rystride;
       a_dim1 = aystride;
       b_dim1 = bystride;
 
 #define A_ARRAY_ELEM(i,j) \
-    a[(i) + (j) * a_dim1]
+    (ARRAY_ELEM_AT_OFFSET (abase, (i) * sizeof (GFC_REAL_4) + (j) * aystride_bytes))
 
 #define B_ARRAY_ELEM(i,j) \
-    b[(i) + (j) * b_dim1]
+    (ARRAY_ELEM_AT_OFFSET (bbase, (i) * sizeof (GFC_REAL_4) + (j) * bystride_bytes))
 
 #define C_ARRAY_ELEM(i,j) \
-    c[(i) + (j) * c_dim1]
+    (ARRAY_ELEM_AT_OFFSET (c, (i) * sizeof (GFC_REAL_4) + (j) * rystride_bytes))
 
-      /* Empty c first.  */
+      /* Empty result first.  */
       for (j=0; j<n; j++)
 	for (i=0; i<m; i++)
 	  C_ARRAY_ELEM (i, j) = (GFC_REAL_4)0;
@@ -2982,11 +3005,11 @@ matmul_r4 (gfc_array_r4 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
-	      dest_y = &dest[y*rystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	      dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	      for (x = 0; x < xcount; x++)
 		{
-		  abase_x = &abase[x*axstride];
+		  abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 		  s = (GFC_REAL_4) 0;
 		  for (n = 0; n < count; n++)
 		    s += abase_x[n] * bbase_y[n];
@@ -3001,11 +3024,11 @@ matmul_r4 (gfc_array_r4 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	      s = (GFC_REAL_4) 0;
 	      for (n = 0; n < count; n++)
 		s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n];
-	      dest[y*rystride] = s;
+	      ARRAY_ELEM_AT_OFFSET (dest, y * rystride_bytes) = s;
 	    }
 	}
     }
@@ -3016,10 +3039,11 @@ matmul_r4 (gfc_array_r4 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	  s = (GFC_REAL_4) 0;
 	  for (n = 0; n < count; n++)
-	    s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n*bxstride];
+	    s += GFC_DESCRIPTOR1_ELEM (a, n)
+	         * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
 	  GFC_DESCRIPTOR1_ELEM (retarray, y) = s;
 	}
     }
@@ -3046,15 +3070,16 @@ matmul_r4 (gfc_array_r4 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
-	  dest_y = &dest[y*rystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	  dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	  for (x = 0; x < xcount; x++)
 	    {
-	      abase_x = &abase[x*axstride];
+	      abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 	      s = (GFC_REAL_4) 0;
 	      for (n = 0; n < count; n++)
-		s += abase_x[n*aystride] * bbase_y[n*bxstride];
-	      dest_y[x*rxstride] = s;
+		s += ARRAY_ELEM_AT_OFFSET (abase_x, n * aystride_bytes)
+		     * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
+	      ARRAY_ELEM_AT_OFFSET (dest_y, x * rxstride_bytes) = s;
 	    }
 	}
     }
diff --git a/libgfortran/generated/matmul_r8.c b/libgfortran/generated/matmul_r8.c
index 9958ec0da0f9..c67dcc9b7617 100644
--- a/libgfortran/generated/matmul_r8.c
+++ b/libgfortran/generated/matmul_r8.c
@@ -94,7 +94,8 @@ matmul_r8_avx (gfc_array_r8 * const restrict retarray,
 
   index_type rxstride, rystride, axstride, aystride, bxstride, bystride;
   index_type x, y, n, count, xcount, ycount;
-  index_type aystride_bytes, bystride_bytes, rystride_bytes;
+  index_type axstride_bytes, aystride_bytes, bxstride_bytes, bystride_bytes,
+	     rxstride_bytes, rystride_bytes;
 
   assert (GFC_DESCRIPTOR_RANK (a) == 2
           || GFC_DESCRIPTOR_RANK (b) == 2);
@@ -183,12 +184,13 @@ matmul_r8_avx (gfc_array_r8 * const restrict retarray,
 	 either as a row or a column matrix. We want both cases to
 	 work. */
       rxstride = rystride = GFC_DESCRIPTOR_STRIDE(retarray,0);
-      rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
+      rxstride_bytes = rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
     }
   else
     {
       rxstride = GFC_DESCRIPTOR_STRIDE(retarray,0);
       rystride = GFC_DESCRIPTOR_STRIDE(retarray,1);
+      rxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
       rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,1);
     }
 
@@ -197,6 +199,7 @@ matmul_r8_avx (gfc_array_r8 * const restrict retarray,
       /* Treat it as a a row matrix A[1,count]. */
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = 1;
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = sizeof (GFC_REAL_8);
 
       xcount = 1;
@@ -206,6 +209,7 @@ matmul_r8_avx (gfc_array_r8 * const restrict retarray,
     {
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = GFC_DESCRIPTOR_STRIDE(a,1);
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,1);
 
       count = GFC_DESCRIPTOR_EXTENT(a,1);
@@ -224,17 +228,20 @@ matmul_r8_avx (gfc_array_r8 * const restrict retarray,
     {
       /* Treat it as a column matrix B[count,1] */
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
 
       /* bystride should never be used for 1-dimensional b.
          The value is only used for calculation of the
          memory by the buffer.  */
       bystride = 256;
+      bystride_bytes = 99999999;
       ycount = 1;
     }
   else
     {
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
       bystride = GFC_DESCRIPTOR_STRIDE(b,1);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
       bystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,1);
       ycount = GFC_DESCRIPTOR_EXTENT(b,1);
     }
@@ -294,12 +301,11 @@ matmul_r8_avx (gfc_array_r8 * const restrict retarray,
 
 	 from netlib.org, translated to C, and modified for matmul.m4.  */
 
-      const GFC_REAL_8 *a, *b;
       GFC_REAL_8 *c;
       const index_type m = xcount, n = ycount, k = count;
 
       /* System generated locals */
-      index_type a_dim1, b_dim1, c_dim1,
+      index_type a_dim1, b_dim1,
 		 i1, i2, i3, i4, i5, i6;
 
       /* Local variables */
@@ -309,25 +315,22 @@ matmul_r8_avx (gfc_array_r8 * const restrict retarray,
       index_type isec, jsec, lsec, uisec, ujsec, ulsec;
       GFC_REAL_8 *t1;
 
-      a = abase;
-      b = bbase;
       c = retarray->base_addr;
 
       /* Parameter adjustments */
-      c_dim1 = rystride;
       a_dim1 = aystride;
       b_dim1 = bystride;
 
 #define A_ARRAY_ELEM(i,j) \
-    a[(i) + (j) * a_dim1]
+    (ARRAY_ELEM_AT_OFFSET (abase, (i) * sizeof (GFC_REAL_8) + (j) * aystride_bytes))
 
 #define B_ARRAY_ELEM(i,j) \
-    b[(i) + (j) * b_dim1]
+    (ARRAY_ELEM_AT_OFFSET (bbase, (i) * sizeof (GFC_REAL_8) + (j) * bystride_bytes))
 
 #define C_ARRAY_ELEM(i,j) \
-    c[(i) + (j) * c_dim1]
+    (ARRAY_ELEM_AT_OFFSET (c, (i) * sizeof (GFC_REAL_8) + (j) * rystride_bytes))
 
-      /* Empty c first.  */
+      /* Empty result first.  */
       for (j=0; j<n; j++)
 	for (i=0; i<m; i++)
 	  C_ARRAY_ELEM (i, j) = (GFC_REAL_8)0;
@@ -575,11 +578,11 @@ matmul_r8_avx (gfc_array_r8 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
-	      dest_y = &dest[y*rystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	      dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	      for (x = 0; x < xcount; x++)
 		{
-		  abase_x = &abase[x*axstride];
+		  abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 		  s = (GFC_REAL_8) 0;
 		  for (n = 0; n < count; n++)
 		    s += abase_x[n] * bbase_y[n];
@@ -594,11 +597,11 @@ matmul_r8_avx (gfc_array_r8 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	      s = (GFC_REAL_8) 0;
 	      for (n = 0; n < count; n++)
 		s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n];
-	      dest[y*rystride] = s;
+	      ARRAY_ELEM_AT_OFFSET (dest, y * rystride_bytes) = s;
 	    }
 	}
     }
@@ -609,10 +612,11 @@ matmul_r8_avx (gfc_array_r8 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	  s = (GFC_REAL_8) 0;
 	  for (n = 0; n < count; n++)
-	    s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n*bxstride];
+	    s += GFC_DESCRIPTOR1_ELEM (a, n)
+	         * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
 	  GFC_DESCRIPTOR1_ELEM (retarray, y) = s;
 	}
     }
@@ -639,15 +643,16 @@ matmul_r8_avx (gfc_array_r8 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
-	  dest_y = &dest[y*rystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	  dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	  for (x = 0; x < xcount; x++)
 	    {
-	      abase_x = &abase[x*axstride];
+	      abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 	      s = (GFC_REAL_8) 0;
 	      for (n = 0; n < count; n++)
-		s += abase_x[n*aystride] * bbase_y[n*bxstride];
-	      dest_y[x*rxstride] = s;
+		s += ARRAY_ELEM_AT_OFFSET (abase_x, n * aystride_bytes)
+		     * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
+	      ARRAY_ELEM_AT_OFFSET (dest_y, x * rxstride_bytes) = s;
 	    }
 	}
     }
@@ -674,7 +679,8 @@ matmul_r8_avx2 (gfc_array_r8 * const restrict retarray,
 
   index_type rxstride, rystride, axstride, aystride, bxstride, bystride;
   index_type x, y, n, count, xcount, ycount;
-  index_type aystride_bytes, bystride_bytes, rystride_bytes;
+  index_type axstride_bytes, aystride_bytes, bxstride_bytes, bystride_bytes,
+	     rxstride_bytes, rystride_bytes;
 
   assert (GFC_DESCRIPTOR_RANK (a) == 2
           || GFC_DESCRIPTOR_RANK (b) == 2);
@@ -763,12 +769,13 @@ matmul_r8_avx2 (gfc_array_r8 * const restrict retarray,
 	 either as a row or a column matrix. We want both cases to
 	 work. */
       rxstride = rystride = GFC_DESCRIPTOR_STRIDE(retarray,0);
-      rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
+      rxstride_bytes = rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
     }
   else
     {
       rxstride = GFC_DESCRIPTOR_STRIDE(retarray,0);
       rystride = GFC_DESCRIPTOR_STRIDE(retarray,1);
+      rxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
       rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,1);
     }
 
@@ -777,6 +784,7 @@ matmul_r8_avx2 (gfc_array_r8 * const restrict retarray,
       /* Treat it as a a row matrix A[1,count]. */
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = 1;
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = sizeof (GFC_REAL_8);
 
       xcount = 1;
@@ -786,6 +794,7 @@ matmul_r8_avx2 (gfc_array_r8 * const restrict retarray,
     {
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = GFC_DESCRIPTOR_STRIDE(a,1);
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,1);
 
       count = GFC_DESCRIPTOR_EXTENT(a,1);
@@ -804,17 +813,20 @@ matmul_r8_avx2 (gfc_array_r8 * const restrict retarray,
     {
       /* Treat it as a column matrix B[count,1] */
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
 
       /* bystride should never be used for 1-dimensional b.
          The value is only used for calculation of the
          memory by the buffer.  */
       bystride = 256;
+      bystride_bytes = 99999999;
       ycount = 1;
     }
   else
     {
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
       bystride = GFC_DESCRIPTOR_STRIDE(b,1);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
       bystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,1);
       ycount = GFC_DESCRIPTOR_EXTENT(b,1);
     }
@@ -874,12 +886,11 @@ matmul_r8_avx2 (gfc_array_r8 * const restrict retarray,
 
 	 from netlib.org, translated to C, and modified for matmul.m4.  */
 
-      const GFC_REAL_8 *a, *b;
       GFC_REAL_8 *c;
       const index_type m = xcount, n = ycount, k = count;
 
       /* System generated locals */
-      index_type a_dim1, b_dim1, c_dim1,
+      index_type a_dim1, b_dim1,
 		 i1, i2, i3, i4, i5, i6;
 
       /* Local variables */
@@ -889,25 +900,22 @@ matmul_r8_avx2 (gfc_array_r8 * const restrict retarray,
       index_type isec, jsec, lsec, uisec, ujsec, ulsec;
       GFC_REAL_8 *t1;
 
-      a = abase;
-      b = bbase;
       c = retarray->base_addr;
 
       /* Parameter adjustments */
-      c_dim1 = rystride;
       a_dim1 = aystride;
       b_dim1 = bystride;
 
 #define A_ARRAY_ELEM(i,j) \
-    a[(i) + (j) * a_dim1]
+    (ARRAY_ELEM_AT_OFFSET (abase, (i) * sizeof (GFC_REAL_8) + (j) * aystride_bytes))
 
 #define B_ARRAY_ELEM(i,j) \
-    b[(i) + (j) * b_dim1]
+    (ARRAY_ELEM_AT_OFFSET (bbase, (i) * sizeof (GFC_REAL_8) + (j) * bystride_bytes))
 
 #define C_ARRAY_ELEM(i,j) \
-    c[(i) + (j) * c_dim1]
+    (ARRAY_ELEM_AT_OFFSET (c, (i) * sizeof (GFC_REAL_8) + (j) * rystride_bytes))
 
-      /* Empty c first.  */
+      /* Empty result first.  */
       for (j=0; j<n; j++)
 	for (i=0; i<m; i++)
 	  C_ARRAY_ELEM (i, j) = (GFC_REAL_8)0;
@@ -1155,11 +1163,11 @@ matmul_r8_avx2 (gfc_array_r8 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
-	      dest_y = &dest[y*rystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	      dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	      for (x = 0; x < xcount; x++)
 		{
-		  abase_x = &abase[x*axstride];
+		  abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 		  s = (GFC_REAL_8) 0;
 		  for (n = 0; n < count; n++)
 		    s += abase_x[n] * bbase_y[n];
@@ -1174,11 +1182,11 @@ matmul_r8_avx2 (gfc_array_r8 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	      s = (GFC_REAL_8) 0;
 	      for (n = 0; n < count; n++)
 		s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n];
-	      dest[y*rystride] = s;
+	      ARRAY_ELEM_AT_OFFSET (dest, y * rystride_bytes) = s;
 	    }
 	}
     }
@@ -1189,10 +1197,11 @@ matmul_r8_avx2 (gfc_array_r8 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	  s = (GFC_REAL_8) 0;
 	  for (n = 0; n < count; n++)
-	    s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n*bxstride];
+	    s += GFC_DESCRIPTOR1_ELEM (a, n)
+	         * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
 	  GFC_DESCRIPTOR1_ELEM (retarray, y) = s;
 	}
     }
@@ -1219,15 +1228,16 @@ matmul_r8_avx2 (gfc_array_r8 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
-	  dest_y = &dest[y*rystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	  dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	  for (x = 0; x < xcount; x++)
 	    {
-	      abase_x = &abase[x*axstride];
+	      abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 	      s = (GFC_REAL_8) 0;
 	      for (n = 0; n < count; n++)
-		s += abase_x[n*aystride] * bbase_y[n*bxstride];
-	      dest_y[x*rxstride] = s;
+		s += ARRAY_ELEM_AT_OFFSET (abase_x, n * aystride_bytes)
+		     * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
+	      ARRAY_ELEM_AT_OFFSET (dest_y, x * rxstride_bytes) = s;
 	    }
 	}
     }
@@ -1254,7 +1264,8 @@ matmul_r8_avx512f (gfc_array_r8 * const restrict retarray,
 
   index_type rxstride, rystride, axstride, aystride, bxstride, bystride;
   index_type x, y, n, count, xcount, ycount;
-  index_type aystride_bytes, bystride_bytes, rystride_bytes;
+  index_type axstride_bytes, aystride_bytes, bxstride_bytes, bystride_bytes,
+	     rxstride_bytes, rystride_bytes;
 
   assert (GFC_DESCRIPTOR_RANK (a) == 2
           || GFC_DESCRIPTOR_RANK (b) == 2);
@@ -1343,12 +1354,13 @@ matmul_r8_avx512f (gfc_array_r8 * const restrict retarray,
 	 either as a row or a column matrix. We want both cases to
 	 work. */
       rxstride = rystride = GFC_DESCRIPTOR_STRIDE(retarray,0);
-      rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
+      rxstride_bytes = rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
     }
   else
     {
       rxstride = GFC_DESCRIPTOR_STRIDE(retarray,0);
       rystride = GFC_DESCRIPTOR_STRIDE(retarray,1);
+      rxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
       rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,1);
     }
 
@@ -1357,6 +1369,7 @@ matmul_r8_avx512f (gfc_array_r8 * const restrict retarray,
       /* Treat it as a a row matrix A[1,count]. */
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = 1;
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = sizeof (GFC_REAL_8);
 
       xcount = 1;
@@ -1366,6 +1379,7 @@ matmul_r8_avx512f (gfc_array_r8 * const restrict retarray,
     {
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = GFC_DESCRIPTOR_STRIDE(a,1);
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,1);
 
       count = GFC_DESCRIPTOR_EXTENT(a,1);
@@ -1384,17 +1398,20 @@ matmul_r8_avx512f (gfc_array_r8 * const restrict retarray,
     {
       /* Treat it as a column matrix B[count,1] */
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
 
       /* bystride should never be used for 1-dimensional b.
          The value is only used for calculation of the
          memory by the buffer.  */
       bystride = 256;
+      bystride_bytes = 99999999;
       ycount = 1;
     }
   else
     {
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
       bystride = GFC_DESCRIPTOR_STRIDE(b,1);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
       bystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,1);
       ycount = GFC_DESCRIPTOR_EXTENT(b,1);
     }
@@ -1454,12 +1471,11 @@ matmul_r8_avx512f (gfc_array_r8 * const restrict retarray,
 
 	 from netlib.org, translated to C, and modified for matmul.m4.  */
 
-      const GFC_REAL_8 *a, *b;
       GFC_REAL_8 *c;
       const index_type m = xcount, n = ycount, k = count;
 
       /* System generated locals */
-      index_type a_dim1, b_dim1, c_dim1,
+      index_type a_dim1, b_dim1,
 		 i1, i2, i3, i4, i5, i6;
 
       /* Local variables */
@@ -1469,25 +1485,22 @@ matmul_r8_avx512f (gfc_array_r8 * const restrict retarray,
       index_type isec, jsec, lsec, uisec, ujsec, ulsec;
       GFC_REAL_8 *t1;
 
-      a = abase;
-      b = bbase;
       c = retarray->base_addr;
 
       /* Parameter adjustments */
-      c_dim1 = rystride;
       a_dim1 = aystride;
       b_dim1 = bystride;
 
 #define A_ARRAY_ELEM(i,j) \
-    a[(i) + (j) * a_dim1]
+    (ARRAY_ELEM_AT_OFFSET (abase, (i) * sizeof (GFC_REAL_8) + (j) * aystride_bytes))
 
 #define B_ARRAY_ELEM(i,j) \
-    b[(i) + (j) * b_dim1]
+    (ARRAY_ELEM_AT_OFFSET (bbase, (i) * sizeof (GFC_REAL_8) + (j) * bystride_bytes))
 
 #define C_ARRAY_ELEM(i,j) \
-    c[(i) + (j) * c_dim1]
+    (ARRAY_ELEM_AT_OFFSET (c, (i) * sizeof (GFC_REAL_8) + (j) * rystride_bytes))
 
-      /* Empty c first.  */
+      /* Empty result first.  */
       for (j=0; j<n; j++)
 	for (i=0; i<m; i++)
 	  C_ARRAY_ELEM (i, j) = (GFC_REAL_8)0;
@@ -1735,11 +1748,11 @@ matmul_r8_avx512f (gfc_array_r8 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
-	      dest_y = &dest[y*rystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	      dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	      for (x = 0; x < xcount; x++)
 		{
-		  abase_x = &abase[x*axstride];
+		  abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 		  s = (GFC_REAL_8) 0;
 		  for (n = 0; n < count; n++)
 		    s += abase_x[n] * bbase_y[n];
@@ -1754,11 +1767,11 @@ matmul_r8_avx512f (gfc_array_r8 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	      s = (GFC_REAL_8) 0;
 	      for (n = 0; n < count; n++)
 		s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n];
-	      dest[y*rystride] = s;
+	      ARRAY_ELEM_AT_OFFSET (dest, y * rystride_bytes) = s;
 	    }
 	}
     }
@@ -1769,10 +1782,11 @@ matmul_r8_avx512f (gfc_array_r8 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	  s = (GFC_REAL_8) 0;
 	  for (n = 0; n < count; n++)
-	    s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n*bxstride];
+	    s += GFC_DESCRIPTOR1_ELEM (a, n)
+	         * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
 	  GFC_DESCRIPTOR1_ELEM (retarray, y) = s;
 	}
     }
@@ -1799,15 +1813,16 @@ matmul_r8_avx512f (gfc_array_r8 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
-	  dest_y = &dest[y*rystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	  dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	  for (x = 0; x < xcount; x++)
 	    {
-	      abase_x = &abase[x*axstride];
+	      abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 	      s = (GFC_REAL_8) 0;
 	      for (n = 0; n < count; n++)
-		s += abase_x[n*aystride] * bbase_y[n*bxstride];
-	      dest_y[x*rxstride] = s;
+		s += ARRAY_ELEM_AT_OFFSET (abase_x, n * aystride_bytes)
+		     * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
+	      ARRAY_ELEM_AT_OFFSET (dest_y, x * rxstride_bytes) = s;
 	    }
 	}
     }
@@ -1848,7 +1863,8 @@ matmul_r8_vanilla (gfc_array_r8 * const restrict retarray,
 
   index_type rxstride, rystride, axstride, aystride, bxstride, bystride;
   index_type x, y, n, count, xcount, ycount;
-  index_type aystride_bytes, bystride_bytes, rystride_bytes;
+  index_type axstride_bytes, aystride_bytes, bxstride_bytes, bystride_bytes,
+	     rxstride_bytes, rystride_bytes;
 
   assert (GFC_DESCRIPTOR_RANK (a) == 2
           || GFC_DESCRIPTOR_RANK (b) == 2);
@@ -1937,12 +1953,13 @@ matmul_r8_vanilla (gfc_array_r8 * const restrict retarray,
 	 either as a row or a column matrix. We want both cases to
 	 work. */
       rxstride = rystride = GFC_DESCRIPTOR_STRIDE(retarray,0);
-      rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
+      rxstride_bytes = rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
     }
   else
     {
       rxstride = GFC_DESCRIPTOR_STRIDE(retarray,0);
       rystride = GFC_DESCRIPTOR_STRIDE(retarray,1);
+      rxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
       rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,1);
     }
 
@@ -1951,6 +1968,7 @@ matmul_r8_vanilla (gfc_array_r8 * const restrict retarray,
       /* Treat it as a a row matrix A[1,count]. */
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = 1;
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = sizeof (GFC_REAL_8);
 
       xcount = 1;
@@ -1960,6 +1978,7 @@ matmul_r8_vanilla (gfc_array_r8 * const restrict retarray,
     {
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = GFC_DESCRIPTOR_STRIDE(a,1);
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,1);
 
       count = GFC_DESCRIPTOR_EXTENT(a,1);
@@ -1978,17 +1997,20 @@ matmul_r8_vanilla (gfc_array_r8 * const restrict retarray,
     {
       /* Treat it as a column matrix B[count,1] */
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
 
       /* bystride should never be used for 1-dimensional b.
          The value is only used for calculation of the
          memory by the buffer.  */
       bystride = 256;
+      bystride_bytes = 99999999;
       ycount = 1;
     }
   else
     {
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
       bystride = GFC_DESCRIPTOR_STRIDE(b,1);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
       bystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,1);
       ycount = GFC_DESCRIPTOR_EXTENT(b,1);
     }
@@ -2048,12 +2070,11 @@ matmul_r8_vanilla (gfc_array_r8 * const restrict retarray,
 
 	 from netlib.org, translated to C, and modified for matmul.m4.  */
 
-      const GFC_REAL_8 *a, *b;
       GFC_REAL_8 *c;
       const index_type m = xcount, n = ycount, k = count;
 
       /* System generated locals */
-      index_type a_dim1, b_dim1, c_dim1,
+      index_type a_dim1, b_dim1,
 		 i1, i2, i3, i4, i5, i6;
 
       /* Local variables */
@@ -2063,25 +2084,22 @@ matmul_r8_vanilla (gfc_array_r8 * const restrict retarray,
       index_type isec, jsec, lsec, uisec, ujsec, ulsec;
       GFC_REAL_8 *t1;
 
-      a = abase;
-      b = bbase;
       c = retarray->base_addr;
 
       /* Parameter adjustments */
-      c_dim1 = rystride;
       a_dim1 = aystride;
       b_dim1 = bystride;
 
 #define A_ARRAY_ELEM(i,j) \
-    a[(i) + (j) * a_dim1]
+    (ARRAY_ELEM_AT_OFFSET (abase, (i) * sizeof (GFC_REAL_8) + (j) * aystride_bytes))
 
 #define B_ARRAY_ELEM(i,j) \
-    b[(i) + (j) * b_dim1]
+    (ARRAY_ELEM_AT_OFFSET (bbase, (i) * sizeof (GFC_REAL_8) + (j) * bystride_bytes))
 
 #define C_ARRAY_ELEM(i,j) \
-    c[(i) + (j) * c_dim1]
+    (ARRAY_ELEM_AT_OFFSET (c, (i) * sizeof (GFC_REAL_8) + (j) * rystride_bytes))
 
-      /* Empty c first.  */
+      /* Empty result first.  */
       for (j=0; j<n; j++)
 	for (i=0; i<m; i++)
 	  C_ARRAY_ELEM (i, j) = (GFC_REAL_8)0;
@@ -2329,11 +2347,11 @@ matmul_r8_vanilla (gfc_array_r8 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
-	      dest_y = &dest[y*rystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	      dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	      for (x = 0; x < xcount; x++)
 		{
-		  abase_x = &abase[x*axstride];
+		  abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 		  s = (GFC_REAL_8) 0;
 		  for (n = 0; n < count; n++)
 		    s += abase_x[n] * bbase_y[n];
@@ -2348,11 +2366,11 @@ matmul_r8_vanilla (gfc_array_r8 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	      s = (GFC_REAL_8) 0;
 	      for (n = 0; n < count; n++)
 		s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n];
-	      dest[y*rystride] = s;
+	      ARRAY_ELEM_AT_OFFSET (dest, y * rystride_bytes) = s;
 	    }
 	}
     }
@@ -2363,10 +2381,11 @@ matmul_r8_vanilla (gfc_array_r8 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	  s = (GFC_REAL_8) 0;
 	  for (n = 0; n < count; n++)
-	    s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n*bxstride];
+	    s += GFC_DESCRIPTOR1_ELEM (a, n)
+	         * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
 	  GFC_DESCRIPTOR1_ELEM (retarray, y) = s;
 	}
     }
@@ -2393,15 +2412,16 @@ matmul_r8_vanilla (gfc_array_r8 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
-	  dest_y = &dest[y*rystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	  dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	  for (x = 0; x < xcount; x++)
 	    {
-	      abase_x = &abase[x*axstride];
+	      abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 	      s = (GFC_REAL_8) 0;
 	      for (n = 0; n < count; n++)
-		s += abase_x[n*aystride] * bbase_y[n*bxstride];
-	      dest_y[x*rxstride] = s;
+		s += ARRAY_ELEM_AT_OFFSET (abase_x, n * aystride_bytes)
+		     * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
+	      ARRAY_ELEM_AT_OFFSET (dest_y, x * rxstride_bytes) = s;
 	    }
 	}
     }
@@ -2501,7 +2521,8 @@ matmul_r8 (gfc_array_r8 * const restrict retarray,
 
   index_type rxstride, rystride, axstride, aystride, bxstride, bystride;
   index_type x, y, n, count, xcount, ycount;
-  index_type aystride_bytes, bystride_bytes, rystride_bytes;
+  index_type axstride_bytes, aystride_bytes, bxstride_bytes, bystride_bytes,
+	     rxstride_bytes, rystride_bytes;
 
   assert (GFC_DESCRIPTOR_RANK (a) == 2
           || GFC_DESCRIPTOR_RANK (b) == 2);
@@ -2590,12 +2611,13 @@ matmul_r8 (gfc_array_r8 * const restrict retarray,
 	 either as a row or a column matrix. We want both cases to
 	 work. */
       rxstride = rystride = GFC_DESCRIPTOR_STRIDE(retarray,0);
-      rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
+      rxstride_bytes = rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
     }
   else
     {
       rxstride = GFC_DESCRIPTOR_STRIDE(retarray,0);
       rystride = GFC_DESCRIPTOR_STRIDE(retarray,1);
+      rxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
       rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,1);
     }
 
@@ -2604,6 +2626,7 @@ matmul_r8 (gfc_array_r8 * const restrict retarray,
       /* Treat it as a a row matrix A[1,count]. */
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = 1;
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = sizeof (GFC_REAL_8);
 
       xcount = 1;
@@ -2613,6 +2636,7 @@ matmul_r8 (gfc_array_r8 * const restrict retarray,
     {
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = GFC_DESCRIPTOR_STRIDE(a,1);
+      axstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,0);
       aystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,1);
 
       count = GFC_DESCRIPTOR_EXTENT(a,1);
@@ -2631,17 +2655,20 @@ matmul_r8 (gfc_array_r8 * const restrict retarray,
     {
       /* Treat it as a column matrix B[count,1] */
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
 
       /* bystride should never be used for 1-dimensional b.
          The value is only used for calculation of the
          memory by the buffer.  */
       bystride = 256;
+      bystride_bytes = 99999999;
       ycount = 1;
     }
   else
     {
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
       bystride = GFC_DESCRIPTOR_STRIDE(b,1);
+      bxstride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,0);
       bystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,1);
       ycount = GFC_DESCRIPTOR_EXTENT(b,1);
     }
@@ -2701,12 +2728,11 @@ matmul_r8 (gfc_array_r8 * const restrict retarray,
 
 	 from netlib.org, translated to C, and modified for matmul.m4.  */
 
-      const GFC_REAL_8 *a, *b;
       GFC_REAL_8 *c;
       const index_type m = xcount, n = ycount, k = count;
 
       /* System generated locals */
-      index_type a_dim1, b_dim1, c_dim1,
+      index_type a_dim1, b_dim1,
 		 i1, i2, i3, i4, i5, i6;
 
       /* Local variables */
@@ -2716,25 +2742,22 @@ matmul_r8 (gfc_array_r8 * const restrict retarray,
       index_type isec, jsec, lsec, uisec, ujsec, ulsec;
       GFC_REAL_8 *t1;
 
-      a = abase;
-      b = bbase;
       c = retarray->base_addr;
 
       /* Parameter adjustments */
-      c_dim1 = rystride;
       a_dim1 = aystride;
       b_dim1 = bystride;
 
 #define A_ARRAY_ELEM(i,j) \
-    a[(i) + (j) * a_dim1]
+    (ARRAY_ELEM_AT_OFFSET (abase, (i) * sizeof (GFC_REAL_8) + (j) * aystride_bytes))
 
 #define B_ARRAY_ELEM(i,j) \
-    b[(i) + (j) * b_dim1]
+    (ARRAY_ELEM_AT_OFFSET (bbase, (i) * sizeof (GFC_REAL_8) + (j) * bystride_bytes))
 
 #define C_ARRAY_ELEM(i,j) \
-    c[(i) + (j) * c_dim1]
+    (ARRAY_ELEM_AT_OFFSET (c, (i) * sizeof (GFC_REAL_8) + (j) * rystride_bytes))
 
-      /* Empty c first.  */
+      /* Empty result first.  */
       for (j=0; j<n; j++)
 	for (i=0; i<m; i++)
 	  C_ARRAY_ELEM (i, j) = (GFC_REAL_8)0;
@@ -2982,11 +3005,11 @@ matmul_r8 (gfc_array_r8 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
-	      dest_y = &dest[y*rystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	      dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	      for (x = 0; x < xcount; x++)
 		{
-		  abase_x = &abase[x*axstride];
+		  abase_x = PTR_ADD_OFFSET (abase, x * axstride_bytes);
 		  s = (GFC_REAL_8) 0;
 		  for (n = 0; n < count; n++)
 		    s += abase_x[n] * bbase_y[n];
@@ -3001,11 +3024,11 @@ matmul_r8 (gfc_array_r8 * const restrict retarray,
 
 	  for (y = 0; y < ycount; y++)
 	    {
-	      bbase_y = &bbase[y*bystride];
+	      bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	      s = (GFC_REAL_8) 0;
 	      for (n = 0; n < count; n++)
 		s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n];
-	      dest[y*rystride] = s;
+	      ARRAY_ELEM_AT_OFFSET (dest, y * rystride_bytes) = s;
 	    }
 	}
     }
@@ -3016,10 +3039,11 @@ matmul_r8 (gfc_array_r8 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
 	  s = (GFC_REAL_8) 0;
 	  for (n = 0; n < count; n++)
-	    s += GFC_DESCRIPTOR1_ELEM (a, n) * bbase_y[n*bxstride];
+	    s += GFC_DESCRIPTOR1_ELEM (a, n)
+	         * ARRAY_ELEM_AT_OFFSET (bbase_y, n * bxstride_bytes);
 	  GFC_DESCRIPTOR1_ELEM (retarray, y) = s;
 	}
     }
@@ -3046,15 +3070,16 @@ matmul_r8 (gfc_array_r8 * const restrict retarray,
 
       for (y = 0; y < ycount; y++)
 	{
-	  bbase_y = &bbase[y*bystride];
-	  dest_y = &dest[y*rystride];
+	  bbase_y = PTR_ADD_OFFSET (bbase, y * bystride_bytes);
+	  dest_y = PTR_ADD_OFFSET (dest, y * rystride_bytes);
 	  for (x = 0; x < xcount; x++)
 	    {
-	      abase_x = &abase[x[...]

[diff truncated at 524288 bytes]


More information about the Gcc-cvs mailing list