]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
2019-04-18 Richard Biener <rguenther@suse.de>
authorrguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 18 Apr 2019 07:40:35 +0000 (07:40 +0000)
committerrguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 18 Apr 2019 07:40:35 +0000 (07:40 +0000)
* tree.c (get_qualified_type): Put found type variants at the
head of the variant list.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@270437 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/tree.c

index 3b8a84a5163ab999cd7c911381357aafa9b04803..c8100e2d1877e6e5006323c7bbbefb88389986eb 100644 (file)
@@ -1,3 +1,8 @@
+2019-04-18  Richard Biener  <rguenther@suse.de>
+
+       * tree.c (get_qualified_type): Put found type variants at the
+       head of the variant list.
+
 2018-04-17  Segher Boessenkool  <segher@kernel.crashing.org>
 
        * config/rs6000/rs6000.c (rs6000_register_move_cost): Fix typo.
index a483cc1f225b65550fb84fb10148a7ac026d71f3..73102c4e75bd3bf21815023d93bbef698a724d0d 100644 (file)
@@ -6451,17 +6451,28 @@ check_aligned_type (const_tree cand, const_tree base, unsigned int align)
 tree
 get_qualified_type (tree type, int type_quals)
 {
-  tree t;
-
   if (TYPE_QUALS (type) == type_quals)
     return type;
 
+  tree mv = TYPE_MAIN_VARIANT (type);
+  if (check_qualified_type (mv, type, type_quals))
+    return mv;
+
   /* Search the chain of variants to see if there is already one there just
      like the one we need to have.  If so, use that existing one.  We must
      preserve the TYPE_NAME, since there is code that depends on this.  */
-  for (t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t))
-    if (check_qualified_type (t, type, type_quals))
-      return t;
+  for (tree *tp = &TYPE_NEXT_VARIANT (mv); *tp; tp = &TYPE_NEXT_VARIANT (*tp))
+    if (check_qualified_type (*tp, type, type_quals))
+      {
+       /* Put the found variant at the head of the variant list so
+          frequently searched variants get found faster.  The C++ FE
+          benefits greatly from this.  */
+       tree t = *tp;
+       *tp = TYPE_NEXT_VARIANT (t);
+       TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (mv);
+       TYPE_NEXT_VARIANT (mv) = t;
+       return t;
+      }
 
   return NULL_TREE;
 }