]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
lto/96591 - walk VECTOR_CST elements in walk_tree
authorRichard Biener <rguenther@suse.de>
Mon, 8 Feb 2021 08:52:56 +0000 (09:52 +0100)
committerRichard Biener <rguenther@suse.de>
Mon, 8 Feb 2021 12:05:44 +0000 (13:05 +0100)
This implements walking of VECTOR_CST elements in walk_tree, mimicing
the walk of COMPLEX_CST elements.  Without this free-lang-data fails
to see some types in case they are only refered to via tree constants
used only as VECTOR_CST elements.

2021-02-08  Richard Biener  <rguenther@suse.de>

PR lto/96591
* tree.c (walk_tree_1): Walk VECTOR_CST elements.

* g++.dg/lto/pr96591_0.C: New testcase.

gcc/testsuite/g++.dg/lto/pr96591_0.C [new file with mode: 0644]
gcc/tree.c

diff --git a/gcc/testsuite/g++.dg/lto/pr96591_0.C b/gcc/testsuite/g++.dg/lto/pr96591_0.C
new file mode 100644 (file)
index 0000000..ae2dc98
--- /dev/null
@@ -0,0 +1,45 @@
+// { dg-lto-do assemble }
+// { dg-lto-options { { -O -flto } } }
+
+template <typename scalar_t, unsigned length>
+struct builtin_simd
+{
+  using type [[gnu::vector_size(sizeof(scalar_t) * length)]] = scalar_t;
+};
+
+struct simd_traits
+{
+  using scalar_type = int;
+
+  template <typename new_scalar_type>
+  using rebind = typename builtin_simd<new_scalar_type, 1>::type;
+};
+
+template <typename simd_t>
+constexpr simd_t fill(typename simd_traits::scalar_type const scalar)
+{
+  return simd_t{scalar};
+}
+
+class Test
+{
+    using score_type = typename builtin_simd<int, 1>::type;
+    score_type data[1]{fill<score_type>(8)};
+};
+
+struct TestFactoryBase
+{
+  virtual Test *CreateTest() = 0;
+};
+
+template <class TestClass>
+struct TestFactoryImpl : public TestFactoryBase
+{
+  Test *CreateTest() override { return new TestClass; }
+};
+
+void MakeAndRegisterTestInfo(TestFactoryBase *factory);
+
+int main() {
+  MakeAndRegisterTestInfo(new TestFactoryImpl<Test>);
+}
index 430b76168b2b0203fe0bae98a9e380bb0a9b1252..c09434d7293b69afebb52888459fe773641dd340 100644 (file)
@@ -12131,7 +12131,6 @@ walk_tree_1 (tree *tp, walk_tree_fn func, void *data,
     case INTEGER_CST:
     case REAL_CST:
     case FIXED_CST:
-    case VECTOR_CST:
     case STRING_CST:
     case BLOCK:
     case PLACEHOLDER_EXPR:
@@ -12162,6 +12161,18 @@ walk_tree_1 (tree *tp, walk_tree_fn func, void *data,
        WALK_SUBTREE_TAIL (TREE_VEC_ELT (*tp, 0));
       }
 
+    case VECTOR_CST:
+      {
+       unsigned len = vector_cst_encoded_nelts (*tp);
+       if (len == 0)
+         break;
+       /* Walk all elements but the first.  */
+       while (--len)
+         WALK_SUBTREE (VECTOR_CST_ENCODED_ELT (*tp, len));
+       /* Now walk the first one as a tail call.  */
+       WALK_SUBTREE_TAIL (VECTOR_CST_ENCODED_ELT (*tp, 0));
+      }
+
     case COMPLEX_CST:
       WALK_SUBTREE (TREE_REALPART (*tp));
       WALK_SUBTREE_TAIL (TREE_IMAGPART (*tp));