public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Tobias Burnus <burnus@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r12-8678] OpenMP: Fix folding with simd's linear clause [PR106492]
Date: Wed, 10 Aug 2022 19:23:03 +0000 (GMT)	[thread overview]
Message-ID: <20220810192303.4793E385828C@sourceware.org> (raw)

https://gcc.gnu.org/g:68b8c55c7e7de8438ea97f600cdccac826b8e67d

commit r12-8678-g68b8c55c7e7de8438ea97f600cdccac826b8e67d
Author: Tobias Burnus <tobias@codesourcery.com>
Date:   Tue Aug 9 07:57:40 2022 +0200

    OpenMP: Fix folding with simd's linear clause [PR106492]
    
    gcc/ChangeLog:
    
            PR middle-end/106492
            * omp-low.cc (lower_rec_input_clauses): Add missing folding
            to data type of linear-clause list item.
    
    gcc/testsuite/ChangeLog:
    
            PR middle-end/106492
            * g++.dg/gomp/pr106492.C: New test.
    
    (cherry picked from commit 8a16b9f983824b6b9a25275cd23b6bba8c98b800)

Diff:
---
 gcc/omp-low.cc                       |  6 ++---
 gcc/testsuite/g++.dg/gomp/pr106492.C | 49 ++++++++++++++++++++++++++++++++++++
 2 files changed, 52 insertions(+), 3 deletions(-)

diff --git a/gcc/omp-low.cc b/gcc/omp-low.cc
index bf5779b6543..eefd9107b89 100644
--- a/gcc/omp-low.cc
+++ b/gcc/omp-low.cc
@@ -6205,10 +6205,10 @@ lower_rec_input_clauses (tree clauses, gimple_seq *ilist, gimple_seq *dlist,
 			}
 
 		      if (POINTER_TYPE_P (TREE_TYPE (x)))
-			x = fold_build2 (POINTER_PLUS_EXPR,
-					 TREE_TYPE (x), x, t);
+			x = fold_build_pointer_plus (x, t);
 		      else
-			x = fold_build2 (PLUS_EXPR, TREE_TYPE (x), x, t);
+			x = fold_build2 (PLUS_EXPR, TREE_TYPE (x), x,
+					 fold_convert (TREE_TYPE (x), t));
 		    }
 
 		  if ((OMP_CLAUSE_CODE (c) != OMP_CLAUSE_LINEAR
diff --git a/gcc/testsuite/g++.dg/gomp/pr106492.C b/gcc/testsuite/g++.dg/gomp/pr106492.C
new file mode 100644
index 00000000000..f263bb42710
--- /dev/null
+++ b/gcc/testsuite/g++.dg/gomp/pr106492.C
@@ -0,0 +1,49 @@
+/* PR middle-end/106492 */
+
+template <typename T>
+struct S {
+  T a : 12;
+  S () : a(0)
+  {
+#pragma omp for simd linear(a)
+    for (int k = 0; k < 64; ++k)
+      a++;
+  }
+};
+struct U {
+  int a : 12;
+  U () : a(0)
+  {
+#pragma omp for simd linear(a)
+    for (int k = 0; k < 64; ++k)
+      a++;
+  }
+};
+
+S<int> s;
+U u;
+
+
+template <typename T>
+struct Sptr {
+  T a;
+  Sptr (T init) : a(init)
+  {
+#pragma omp for simd linear(a)
+    for (int k = 0; k < 64; ++k)
+      a++;
+  }
+};
+struct Uptr {
+  int *a;
+  Uptr (int *init) : a(init)
+  {
+#pragma omp for simd linear(a)
+    for (int k = 0; k < 64; ++k)
+      a++;
+  }
+};
+
+int i[1024];
+Sptr<int *> sptr(i);
+Uptr uptr(&i[100]);


                 reply	other threads:[~2022-08-10 19:23 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220810192303.4793E385828C@sourceware.org \
    --to=burnus@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).