middle-end/104467 - fix vector extract simplification
authorRichard Biener <rguenther@suse.de>
Thu, 10 Feb 2022 09:01:20 +0000 (10:01 +0100)
committerRichard Biener <rguenther@suse.de>
Thu, 10 Feb 2022 09:54:43 +0000 (10:54 +0100)
This fixes a bogus vector type used for a CTOR build as part of
vector extract simplification.  The code failed to consider a
CTOR of vector elements.

2022-02-10  Richard Biener  <rguenther@suse.de>

PR middle-end/104467
* match.pd (vector extract simplification): Multiply the
number of CTOR elements with the number of element elements.

* gcc.dg/torture/pr104467.c: New testcase.

gcc/match.pd
gcc/testsuite/gcc.dg/torture/pr104467.c [new file with mode: 0644]

index 4fe590983f3dfdb037f241f3e9dc21c648905416..d9d835910457d7c9c3c790d76b2aea42ff022e7b 100644 (file)
@@ -6943,7 +6943,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
                                          TREE_TYPE (TREE_TYPE (ctor)))
                             ? type
                             : build_vector_type (TREE_TYPE (TREE_TYPE (ctor)),
-                                                 count));
+                                                 count * k));
              res = (constant_p ? build_vector_from_ctor (evtype, vals)
                     : build_constructor (evtype, vals));
            }
diff --git a/gcc/testsuite/gcc.dg/torture/pr104467.c b/gcc/testsuite/gcc.dg/torture/pr104467.c
new file mode 100644 (file)
index 0000000..c3bfb60
--- /dev/null
@@ -0,0 +1,11 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-mavx" { target x86_64-*-* i?86-*-* } } */
+
+unsigned long __attribute__((__vector_size__ (8 * sizeof (long)))) u;
+signed long __attribute__((__vector_size__ (8 * sizeof (long)))) s;
+
+void
+foo (void)
+{
+  s &= u + (0, 0);
+}