gimple-parser.c (c_parser_gimple_postfix_expression): Support _Literal (int *) &x...
authorRichard Biener <rguenther@suse.de>
Wed, 10 Jul 2019 13:24:32 +0000 (13:24 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Wed, 10 Jul 2019 13:24:32 +0000 (13:24 +0000)
2019-07-10  Richard Biener  <rguenther@suse.de>

c/
* gimple-parser.c (c_parser_gimple_postfix_expression): Support
_Literal (int *) &x for address literals.

* tree-ssa-sccvn.c (vn_reference_lookup_3): Look at valueized
LHS whenever possible.

* gcc.dg/torture/ssa-fre-5.c: New testcase.
* gcc.dg/torture/ssa-fre-6.c: Likewise.
* gcc.dg/torture/ssa-fre-7.c: Likewise.

From-SVN: r273354

gcc/ChangeLog
gcc/c/ChangeLog
gcc/c/gimple-parser.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/torture/ssa-fre-5.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/torture/ssa-fre-6.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/torture/ssa-fre-7.c [new file with mode: 0644]
gcc/tree-ssa-sccvn.c

index 2f9863383937f5e288f2ec802819cb534671d78f..ac390d65ae7b0ef17e15b7af07682f7ce6089616 100644 (file)
@@ -1,3 +1,8 @@
+2019-07-10  Richard Biener  <rguenther@suse.de>
+
+       * tree-ssa-sccvn.c (vn_reference_lookup_3): Look at valueized
+       LHS whenever possible.
+
 2019-07-09  Jan Hubicka  <hubicka@ucw.cz>
 
        * tree-ssa-alias.c (nonoverlapping_component_refs_p_1): Break out
index 29836ff9595c76c7d3858c6638e62a11b890a61b..bb0573e5401d2f8d3fb70b6553be0686cc8be4a4 100644 (file)
@@ -1,3 +1,8 @@
+2019-07-10  Richard Biener  <rguenther@suse.de>
+
+       * gimple-parser.c (c_parser_gimple_postfix_expression): Support
+       _Literal (int *) &x for address literals.
+
 2019-07-09  Martin Sebor  <msebor@redhat.com>
 
        PR c++/61339
index 9a65394a020f54d42e1116223091b98b15a96d24..a0ea7215984ab01074c5622428ee4d28d25106ec 100644 (file)
@@ -1606,8 +1606,10 @@ c_parser_gimple_postfix_expression (gimple_parser &parser)
                  tree val = c_parser_gimple_postfix_expression (parser).value;
                  if (! val
                      || val == error_mark_node
-                     || ! CONSTANT_CLASS_P (val)
-                     || (addr_p && TREE_CODE (val) != STRING_CST))
+                     || (!CONSTANT_CLASS_P (val)
+                         && !(addr_p
+                              && (TREE_CODE (val) == STRING_CST
+                                  || DECL_P (val)))))
                    {
                      c_parser_error (parser, "invalid _Literal");
                      return expr;
index a953397db9390f50f63c2bad3dad009d3047f35b..840d9c1f251601a40b82941501920775f8ed78bf 100644 (file)
@@ -1,3 +1,9 @@
+2019-07-10  Richard Biener  <rguenther@suse.de>
+
+       * gcc.dg/torture/ssa-fre-5.c: New testcase.
+       * gcc.dg/torture/ssa-fre-6.c: Likewise.
+       * gcc.dg/torture/ssa-fre-7.c: Likewise.
+
 2019-07-10  Ed Schonberg  <schonberg@adacore.com>
 
        * gnat.dg/modular5.adb: New testcase.
diff --git a/gcc/testsuite/gcc.dg/torture/ssa-fre-5.c b/gcc/testsuite/gcc.dg/torture/ssa-fre-5.c
new file mode 100644 (file)
index 0000000..5ee9d64
--- /dev/null
@@ -0,0 +1,27 @@
+/* { dg-do compile } */
+/* { dg-skip-if "" { *-*-* } { "-O0" } { "" } } */
+/* { dg-additional-options "-fgimple -fdump-tree-fre1" } */
+
+typedef int v4si __attribute__((vector_size(16)));
+
+int __GIMPLE (ssa,startwith("fre"))
+foo ()
+{
+  int * p;
+  int i;
+  int x[4];
+  long unsigned int _1;
+  long unsigned int _2;
+  int _7;
+
+  __BB(2):
+  i_3 = 0;
+  _1 = (long unsigned int) i_3;
+  _2 = _1 * 4ul;
+  p_4 = _Literal (int *) &x + _2;
+  __MEM <v4si> ((v4si *)p_4) = _Literal (v4si) { 1, 2, 3, 4 };
+  _7 = x[0];
+  return _7;
+}
+
+/* { dg-final { scan-tree-dump "return 1;" "fre1" } } */
diff --git a/gcc/testsuite/gcc.dg/torture/ssa-fre-6.c b/gcc/testsuite/gcc.dg/torture/ssa-fre-6.c
new file mode 100644 (file)
index 0000000..ecdd8f6
--- /dev/null
@@ -0,0 +1,27 @@
+/* { dg-do compile } */
+/* { dg-skip-if "" { *-*-* } { "-O0" } { "" } } */
+/* { dg-additional-options "-fgimple -fdump-tree-fre1" } */
+
+typedef int v4si __attribute__((vector_size(16)));
+
+int __GIMPLE (ssa,startwith("fre"))
+foo ()
+{
+  int * p;
+  int i;
+  int x[4];
+  long unsigned int _1;
+  long unsigned int _2;
+  int _7;
+
+  __BB(2):
+  i_3 = 0;
+  _1 = (long unsigned int) i_3;
+  _2 = _1 * 4ul;
+  p_4 = _Literal (int *) &x + _2;
+  __MEM <v4si> ((v4si *)p_4) = _Literal (v4si) {};
+  _7 = x[0];
+  return _7;
+}
+
+/* { dg-final { scan-tree-dump "return 0;" "fre1" } } */
diff --git a/gcc/testsuite/gcc.dg/torture/ssa-fre-7.c b/gcc/testsuite/gcc.dg/torture/ssa-fre-7.c
new file mode 100644 (file)
index 0000000..07f3c9d
--- /dev/null
@@ -0,0 +1,29 @@
+/* { dg-do compile } */
+/* { dg-skip-if "" { *-*-* } { "-O0" } { "" } } */
+/* { dg-additional-options "-fgimple -fdump-tree-fre1" } */
+
+typedef int v4si __attribute__((vector_size(16)));
+
+int __GIMPLE (ssa,startwith("fre"))
+foo (int c)
+{
+  int * p;
+  int i;
+  int x[4];
+  long unsigned int _1;
+  long unsigned int _2;
+  int _7;
+  v4si _6;
+
+  __BB(2):
+  i_3 = 0;
+  _1 = (long unsigned int) i_3;
+  _2 = _1 * 4ul;
+  p_4 = _Literal (int *) &x + _2;
+  _6 = _Literal (v4si) { c_5(D), c_5(D), c_5(D), c_5(D) };
+  __MEM <v4si> ((v4si *)p_4) = _6;
+  _7 = x[0];
+  return _7;
+}
+
+/* { dg-final { scan-tree-dump "return c_5\\(D\\);" "fre1" } } */
index 9186f15e39b2cc7373b7c6db180d66892514826a..777cf58e43b7ca5e8fc0dfe029e896cdb38672d0 100644 (file)
@@ -2488,12 +2488,22 @@ vn_reference_lookup_3 (ao_ref *ref, tree vuse, void *data_,
           && gimple_assign_rhs_code (def_stmt) == CONSTRUCTOR
           && CONSTRUCTOR_NELTS (gimple_assign_rhs1 (def_stmt)) == 0)
     {
+      tree lhs = gimple_assign_lhs (def_stmt);
       tree base2;
       poly_int64 offset2, size2, maxsize2;
       HOST_WIDE_INT offset2i, size2i;
       bool reverse;
-      base2 = get_ref_base_and_extent (gimple_assign_lhs (def_stmt),
-                                      &offset2, &size2, &maxsize2, &reverse);
+      if (lhs_ref_ok)
+       {
+         base2 = ao_ref_base (&lhs_ref);
+         offset2 = lhs_ref.offset;
+         size2 = lhs_ref.size;
+         maxsize2 = lhs_ref.max_size;
+         reverse = reverse_storage_order_for_component_p (lhs);
+       }
+      else
+       base2 = get_ref_base_and_extent (lhs,
+                                        &offset2, &size2, &maxsize2, &reverse);
       if (known_size_p (maxsize2)
          && known_eq (maxsize2, size2)
          && adjust_offsets_for_equal_base_address (base, &offset,
@@ -2541,12 +2551,22 @@ vn_reference_lookup_3 (ao_ref *ref, tree vuse, void *data_,
               || (TREE_CODE (gimple_assign_rhs1 (def_stmt)) == SSA_NAME
                   && is_gimple_min_invariant (SSA_VAL (gimple_assign_rhs1 (def_stmt))))))
     {
+      tree lhs = gimple_assign_lhs (def_stmt);
       tree base2;
       poly_int64 offset2, size2, maxsize2;
       HOST_WIDE_INT offset2i, size2i;
       bool reverse;
-      base2 = get_ref_base_and_extent (gimple_assign_lhs (def_stmt),
-                                      &offset2, &size2, &maxsize2, &reverse);
+      if (lhs_ref_ok)
+       {
+         base2 = ao_ref_base (&lhs_ref);
+         offset2 = lhs_ref.offset;
+         size2 = lhs_ref.size;
+         maxsize2 = lhs_ref.max_size;
+         reverse = reverse_storage_order_for_component_p (lhs);
+       }
+      else
+       base2 = get_ref_base_and_extent (lhs,
+                                        &offset2, &size2, &maxsize2, &reverse);
       if (base2
          && !reverse
          && known_eq (maxsize2, size2)
@@ -2627,12 +2647,21 @@ vn_reference_lookup_3 (ao_ref *ref, tree vuse, void *data_,
              downstream, not so much for actually doing the insertion.  */
           && data->partial_defs.is_empty ())
     {
+      tree lhs = gimple_assign_lhs (def_stmt);
       tree base2;
       poly_int64 offset2, size2, maxsize2;
       bool reverse;
-      base2 = get_ref_base_and_extent (gimple_assign_lhs (def_stmt),
-                                      &offset2, &size2, &maxsize2,
-                                      &reverse);
+      if (lhs_ref_ok)
+       {
+         base2 = ao_ref_base (&lhs_ref);
+         offset2 = lhs_ref.offset;
+         size2 = lhs_ref.size;
+         maxsize2 = lhs_ref.max_size;
+         reverse = reverse_storage_order_for_component_p (lhs);
+       }
+      else
+       base2 = get_ref_base_and_extent (lhs,
+                                        &offset2, &size2, &maxsize2, &reverse);
       tree def_rhs = gimple_assign_rhs1 (def_stmt);
       if (!reverse
          && known_size_p (maxsize2)