]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
bitmap: Speed up bitmap_tree_link_element
authorRichard Sandiford <rdsandiford@googlemail.com>
Thu, 4 Jun 2026 15:40:44 +0000 (16:40 +0100)
committerRichard Sandiford <rdsandiford@googlemail.com>
Thu, 4 Jun 2026 15:40:44 +0000 (16:40 +0100)
bitmap_tree_link_element first splays the tree to ensure that the
root is a neighbour of the element that we want to insert.  But the
callers have already done the same kind of splay operation in order
to prove that no existing element has the required index.

Repeating the operation isn't free.  For example, if the first splay
operation leaves the left neighbour N in the root, the second splay
operation would need to search N->right->left (N->next->prev),
and similarly in reverse for a right neighbour.

This gives a reproducible 20% improvement in an artificial test that
inserted 2,000,000 pseudo-random elements (keeping the same sequence
for all tests).

gcc/
* bitmap.cc (bitmap_tree_link_element): Require callers to have
done a splay operation.  Avoid doing another one here.

gcc/bitmap.cc

index 91c1019cb34cf727a15176e71ee8ea624563f852..fdea7200f1da45464483961eb9cba3b6e6df2d7e 100644 (file)
@@ -503,16 +503,18 @@ bitmap_tree_splay (bitmap head, bitmap_element *t, unsigned int indx)
   return t;
 }
 
-/* Link bitmap element E into the current bitmap splay tree.  */
+/* Link bitmap element E into the current bitmap splay tree.  The caller
+   must have called bitmap_tree_find_element first, which guarantees that
+   the current root should become a neighbor of E.  */
 
 static inline void
 bitmap_tree_link_element (bitmap head, bitmap_element *e)
 {
-  if (head->first == NULL)
+  bitmap_element *t = head->first;
+  if (t == NULL)
     e->prev = e->next = NULL;
   else
     {
-      bitmap_element *t = bitmap_tree_splay (head, head->first, e->indx);
       if (e->indx < t->indx)
        {
          e->prev = t->prev;