Reset proper type on vector types (PR middle-end/88587).
authorMartin Liska <mliska@suse.cz>
Fri, 18 Jan 2019 07:41:05 +0000 (08:41 +0100)
committerMartin Liska <marxin@gcc.gnu.org>
Fri, 18 Jan 2019 07:41:05 +0000 (07:41 +0000)
2019-01-18  Martin Liska  <mliska@suse.cz>
    Richard Biener  <rguenther@suse.de>

PR middle-end/88587
* cgraph.h (create_version_clone_with_body): Add new argument
with attributes.
* cgraphclones.c (cgraph_node::create_version_clone): Add
DECL_ATTRIBUTES to a newly created decl.  And call
valid_attribute_p so that proper cl_target_optimization_node
is set for the newly created declaration.
* multiple_target.c (create_target_clone): Set DECL_ATTRIBUTES
for declaration.
(expand_target_clones): Do not call valid_attribute_p, it must
be already done.
* tree-inline.c (copy_decl_for_dup_finish): Reset mode for
vector types.
2019-01-18  Martin Liska  <mliska@suse.cz>

PR middle-end/88587
* g++.target/i386/pr88587.C: New test.
* gcc.target/i386/mvc13.c: New test.

Co-Authored-By: Richard Biener <rguenther@suse.de>
From-SVN: r268060

gcc/ChangeLog
gcc/cgraph.h
gcc/cgraphclones.c
gcc/multiple_target.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.target/i386/pr88587.C [new file with mode: 0644]
gcc/testsuite/gcc.target/i386/mvc13.c [new file with mode: 0644]
gcc/tree-inline.c

index aa21399f117f95208b6ba53e858f99d0ff68d33d..2a18cf80ee4dbfa63f2138d3c44b4ea2fd05b316 100644 (file)
@@ -1,3 +1,20 @@
+2019-01-18  Martin Liska  <mliska@suse.cz>
+           Richard Biener  <rguenther@suse.de>
+
+       PR middle-end/88587
+       * cgraph.h (create_version_clone_with_body): Add new argument
+       with attributes.
+       * cgraphclones.c (cgraph_node::create_version_clone): Add
+       DECL_ATTRIBUTES to a newly created decl.  And call
+       valid_attribute_p so that proper cl_target_optimization_node
+       is set for the newly created declaration.
+       * multiple_target.c (create_target_clone): Set DECL_ATTRIBUTES
+       for declaration.
+       (expand_target_clones): Do not call valid_attribute_p, it must
+       be already done.
+       * tree-inline.c (copy_decl_for_dup_finish): Reset mode for
+       vector types.
+
 2019-01-17  Jakub Jelinek  <jakub@redhat.com>
 
        PR target/88734
index c016da3875c54add93f74ca3b3c1ef84148e904d..bb2318333288c1b96500a638121c575d139b119e 100644 (file)
@@ -1019,12 +1019,17 @@ public:
      If non-NULL BLOCK_TO_COPY determine what basic blocks to copy.
      If non_NULL NEW_ENTRY determine new entry BB of the clone.
 
+     If TARGET_ATTRIBUTES is non-null, when creating a new declaration,
+     add the attributes to DECL_ATTRIBUTES.  And call valid_attribute_p
+     that will promote value of the attribute DECL_FUNCTION_SPECIFIC_TARGET
+     of the declaration.
+
      Return the new version's cgraph node.  */
   cgraph_node *create_version_clone_with_body
     (vec<cgraph_edge *> redirect_callers,
      vec<ipa_replace_map *, va_gc> *tree_map, bitmap args_to_skip,
      bool skip_return, bitmap bbs_to_copy, basic_block new_entry_block,
-     const char *clone_name);
+     const char *clone_name, tree target_attributes = NULL_TREE);
 
   /* Insert a new cgraph_function_version_info node into cgraph_fnver_htab
      corresponding to cgraph_node.  */
index 4688de91cfe73e176e4448faa4e72814acb71cee..15f7e119d18ea1ad6ad18c827e4d4bd6cfa41364 100644 (file)
@@ -1012,6 +1012,11 @@ cgraph_node::create_version_clone (tree new_decl,
    If non-NULL BLOCK_TO_COPY determine what basic blocks to copy.
    If non_NULL NEW_ENTRY determine new entry BB of the clone.
 
+   If TARGET_ATTRIBUTES is non-null, when creating a new declaration,
+   add the attributes to DECL_ATTRIBUTES.  And call valid_attribute_p
+   that will promote value of the attribute DECL_FUNCTION_SPECIFIC_TARGET
+   of the declaration.
+
    Return the new version's cgraph node.  */
 
 cgraph_node *
@@ -1019,7 +1024,7 @@ cgraph_node::create_version_clone_with_body
   (vec<cgraph_edge *> redirect_callers,
    vec<ipa_replace_map *, va_gc> *tree_map, bitmap args_to_skip,
    bool skip_return, bitmap bbs_to_copy, basic_block new_entry_block,
-   const char *suffix)
+   const char *suffix, tree target_attributes)
 {
   tree old_decl = decl;
   cgraph_node *new_version_node = NULL;
@@ -1044,6 +1049,19 @@ cgraph_node::create_version_clone_with_body
 
   DECL_VIRTUAL_P (new_decl) = 0;
 
+  if (target_attributes)
+    {
+      DECL_ATTRIBUTES (new_decl) = target_attributes;
+
+      location_t saved_loc = input_location;
+      tree v = TREE_VALUE (target_attributes);
+      input_location = DECL_SOURCE_LOCATION (new_decl);
+      bool r = targetm.target_option.valid_attribute_p (new_decl, NULL, v, 0);
+      input_location = saved_loc;
+      if (!r)
+       return NULL;
+    }
+
   /* When the old decl was a con-/destructor make sure the clone isn't.  */
   DECL_STATIC_CONSTRUCTOR (new_decl) = 0;
   DECL_STATIC_DESTRUCTOR (new_decl) = 0;
index 589d059424a31e9dafadc17c79a44417138835ba..6126f42d7bf1294d95e06555a4e17988c290e02c 100644 (file)
@@ -294,7 +294,8 @@ create_new_asm_name (char *old_asm_name, char *new_asm_name)
 /*  Creates target clone of NODE.  */
 
 static cgraph_node *
-create_target_clone (cgraph_node *node, bool definition, char *name)
+create_target_clone (cgraph_node *node, bool definition, char *name,
+                    tree attributes)
 {
   cgraph_node *new_node;
 
@@ -303,13 +304,16 @@ create_target_clone (cgraph_node *node, bool definition, char *name)
       new_node = node->create_version_clone_with_body (vNULL, NULL,
                                                       NULL, false,
                                                       NULL, NULL,
-                                                      name);
+                                                      name, attributes);
+      if (new_node == NULL)
+       return NULL;
       new_node->force_output = true;
     }
   else
     {
       tree new_decl = copy_node (node->decl);
       new_node = cgraph_node::get_create (new_decl);
+      DECL_ATTRIBUTES (new_decl) = attributes;
       /* Generate a new name for the new version.  */
       symtab->change_decl_assembler_name (new_node->decl,
                                          clone_function_name_numbered (
@@ -400,22 +404,16 @@ expand_target_clones (struct cgraph_node *node, bool definition)
 
       create_new_asm_name (attr, suffix);
       /* Create new target clone.  */
-      cgraph_node *new_node = create_target_clone (node, definition, suffix);
-      new_node->local.local = false;
-      XDELETEVEC (suffix);
-
-      /* Set new attribute for the clone.  */
       tree attributes = make_attribute ("target", attr,
-                                       DECL_ATTRIBUTES (new_node->decl));
-      DECL_ATTRIBUTES (new_node->decl) = attributes;
-      location_t saved_loc = input_location;
-      input_location = DECL_SOURCE_LOCATION (node->decl);
-      if (!targetm.target_option.valid_attribute_p (new_node->decl, NULL,
-                                                   TREE_VALUE (attributes),
-                                                   0))
+                                       DECL_ATTRIBUTES (node->decl));
+
+      cgraph_node *new_node = create_target_clone (node, definition, suffix,
+                                                  attributes);
+      if (new_node == NULL)
        return false;
+      new_node->local.local = false;
+      XDELETEVEC (suffix);
 
-      input_location = saved_loc;
       decl2_v = new_node->function_version ();
       if (decl2_v != NULL)
         continue;
@@ -442,13 +440,7 @@ expand_target_clones (struct cgraph_node *node, bool definition)
                                    DECL_ATTRIBUTES (node->decl));
   DECL_ATTRIBUTES (node->decl) = attributes;
   node->local.local = false;
-  location_t saved_loc = input_location;
-  input_location = DECL_SOURCE_LOCATION (node->decl);
-  bool ret
-    = targetm.target_option.valid_attribute_p (node->decl, NULL,
-                                              TREE_VALUE (attributes), 0);
-  input_location = saved_loc;
-  return ret;
+  return true;
 }
 
 /* When NODE is a target clone, consider all callees and redirect
index 5bab822031341aa84eba1ae76ff84ef7ec16131c..49fb9b9c8182825e79b0e4b9c967c903fd6b247e 100644 (file)
@@ -1,3 +1,9 @@
+2019-01-18  Martin Liska  <mliska@suse.cz>
+
+       PR middle-end/88587
+       * g++.target/i386/pr88587.C: New test.
+       * gcc.target/i386/mvc13.c: New test.
+
 2018-01-17  Steve Ellcey  <sellcey@cavium.com>
 
        PR fortran/88898
diff --git a/gcc/testsuite/g++.target/i386/pr88587.C b/gcc/testsuite/g++.target/i386/pr88587.C
new file mode 100644 (file)
index 0000000..6808ab6
--- /dev/null
@@ -0,0 +1,15 @@
+/* { dg-do compile } */
+/* { dg-require-ifunc "" }  */
+/* { dg-options "-O -m32 -g -mno-sse -Wno-attributes" } */
+
+__attribute__((target("default"),always_inline))
+void a()
+{
+  __attribute__((__vector_size__(4 * sizeof(float)))) int b = {};
+}
+
+__attribute__((target("sse2"))) void a2()
+{
+  a ();
+  __attribute__((__vector_size__(4 * sizeof(float)))) int b = {};
+}
diff --git a/gcc/testsuite/gcc.target/i386/mvc13.c b/gcc/testsuite/gcc.target/i386/mvc13.c
new file mode 100644 (file)
index 0000000..9e31ef7
--- /dev/null
@@ -0,0 +1,9 @@
+/* { dg-do compile } */
+/* { dg-require-ifunc "" } */
+/* { dg-options "-O -m32 -g -mno-sse" } */
+
+__attribute__((target_clones("default,sse2")))
+void a()
+{
+  __attribute__((__vector_size__(4 * sizeof(float)))) int b = {};
+}
index 88620770212a16423e12add1ff35cba52104d351..1c2766d47990e97bc6a4228ff467cb61fbd6b99b 100644 (file)
@@ -5479,6 +5479,10 @@ copy_decl_for_dup_finish (copy_body_data *id, tree decl, tree copy)
   if (CODE_CONTAINS_STRUCT (TREE_CODE (copy), TS_DECL_WRTL)
       && !TREE_STATIC (copy) && !DECL_EXTERNAL (copy))
     SET_DECL_RTL (copy, 0);
+  /* For vector typed decls make sure to update DECL_MODE according
+     to the new function context.  */
+  if (VECTOR_TYPE_P (TREE_TYPE (copy)))
+    SET_DECL_MODE (copy, TYPE_MODE (TREE_TYPE (copy)));
 
   /* These args would always appear unused, if not for this.  */
   TREE_USED (copy) = 1;