public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-3319] tree-optimization/111048 - avoid flawed logic in fold_vec_perm
@ 2023-08-18  8:24 Richard Biener
  0 siblings, 0 replies; only message in thread
From: Richard Biener @ 2023-08-18  8:24 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:f5f47cc1ce75b00427756939a2dab94d3d125f6a

commit r14-3319-gf5f47cc1ce75b00427756939a2dab94d3d125f6a
Author: Richard Biener <rguenther@suse.de>
Date:   Fri Aug 18 09:41:56 2023 +0200

    tree-optimization/111048 - avoid flawed logic in fold_vec_perm
    
    The following avoids running into somehow flawed logic in fold_vec_perm
    for non-VLA vectors.
    
            PR tree-optimization/111048
            * fold-const.cc (fold_vec_perm_cst): Check for non-VLA
            vectors first.
    
            * gcc.dg/torture/pr111048.c: New testcase.

Diff:
---
 gcc/fold-const.cc                       | 12 ++++++------
 gcc/testsuite/gcc.dg/torture/pr111048.c | 24 ++++++++++++++++++++++++
 2 files changed, 30 insertions(+), 6 deletions(-)

diff --git a/gcc/fold-const.cc b/gcc/fold-const.cc
index c6fb083027db..08530b6ae809 100644
--- a/gcc/fold-const.cc
+++ b/gcc/fold-const.cc
@@ -10625,6 +10625,11 @@ fold_vec_perm_cst (tree type, tree arg0, tree arg1, const vec_perm_indices &sel,
   unsigned res_npatterns, res_nelts_per_pattern;
   unsigned HOST_WIDE_INT res_nelts;
 
+  if (TYPE_VECTOR_SUBPARTS (type).is_constant (&res_nelts))
+    {
+      res_npatterns = res_nelts;
+      res_nelts_per_pattern = 1;
+    }
   /* (1) If SEL is a suitable mask as determined by
      valid_mask_for_fold_vec_perm_cst_p, then:
      res_npatterns = max of npatterns between ARG0, ARG1, and SEL
@@ -10634,7 +10639,7 @@ fold_vec_perm_cst (tree type, tree arg0, tree arg1, const vec_perm_indices &sel,
      res_npatterns = nelts in result vector.
      res_nelts_per_pattern = 1.
      This exception is made so that VLS ARG0, ARG1 and SEL work as before.  */
-  if (valid_mask_for_fold_vec_perm_cst_p (arg0, arg1, sel, reason))
+  else if (valid_mask_for_fold_vec_perm_cst_p (arg0, arg1, sel, reason))
     {
       res_npatterns
 	= std::max (VECTOR_CST_NPATTERNS (arg0),
@@ -10648,11 +10653,6 @@ fold_vec_perm_cst (tree type, tree arg0, tree arg1, const vec_perm_indices &sel,
 
       res_nelts = res_npatterns * res_nelts_per_pattern;
     }
-  else if (TYPE_VECTOR_SUBPARTS (type).is_constant (&res_nelts))
-    {
-      res_npatterns = res_nelts;
-      res_nelts_per_pattern = 1;
-    }
   else
     return NULL_TREE;
 
diff --git a/gcc/testsuite/gcc.dg/torture/pr111048.c b/gcc/testsuite/gcc.dg/torture/pr111048.c
new file mode 100644
index 000000000000..475978aae2be
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr111048.c
@@ -0,0 +1,24 @@
+/* { dg-do run } */
+/* { dg-additional-options "-mavx2" { target avx2_runtime } } */
+
+typedef unsigned char u8;
+
+__attribute__((noipa))
+static void check(const u8 * v) {
+    if (*v != 15) __builtin_trap();
+}
+
+__attribute__((noipa))
+static void bug(void) {
+    u8 in_lanes[32];
+    for (unsigned i = 0; i < 32; i += 2) {
+      in_lanes[i + 0] = 0;
+      in_lanes[i + 1] = ((u8)0xff) >> (i & 7);
+    }
+
+    check(&in_lanes[13]);
+  }
+
+int main() {
+    bug();
+}

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-08-18  8:24 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-18  8:24 [gcc r14-3319] tree-optimization/111048 - avoid flawed logic in fold_vec_perm Richard Biener

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).