public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [C++ PATCH] Small performance improvement for constexpr_call_hasher::equal (PR c++/84684)
@ 2018-03-05 20:31 Jakub Jelinek
  2018-03-05 22:08 ` Jason Merrill
  0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2018-03-05 20:31 UTC (permalink / raw)
  To: Jason Merrill, Nathan Sidwell; +Cc: gcc-patches

Hi!

This doesn't actually fix this PR (Marek is working on that), but
just something I've noticed while analyzing the PR.
We have the hashes saved in the structure (to speed up hash table
expansion), so it is a waste not to test those also in the equal hook,
by giving up cheaply in cases of hash table collisions.

Additionally, the method returns bool, so this patch uses true/false
instead of 1/0.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2018-03-05  Jakub Jelinek  <jakub@redhat.com>

	PR c++/84684
	* constexpr.c (constexpr_call_hasher::equal): Return false if
	lhs->hash != rhs->hash.  Change return 1 to return true and
	return 0 to return false.

--- gcc/cp/constexpr.c.jj	2018-03-05 16:11:08.510165108 +0100
+++ gcc/cp/constexpr.c	2018-03-05 16:14:06.130229884 +0100
@@ -1033,9 +1033,11 @@ constexpr_call_hasher::equal (constexpr_
   tree lhs_bindings;
   tree rhs_bindings;
   if (lhs == rhs)
-    return 1;
+    return true;
+  if (lhs->hash != rhs->hash)
+    return false;
   if (!constexpr_fundef_hasher::equal (lhs->fundef, rhs->fundef))
-    return 0;
+    return false;
   lhs_bindings = lhs->bindings;
   rhs_bindings = rhs->bindings;
   while (lhs_bindings != NULL && rhs_bindings != NULL)
@@ -1044,7 +1046,7 @@ constexpr_call_hasher::equal (constexpr_
       tree rhs_arg = TREE_VALUE (rhs_bindings);
       gcc_assert (TREE_TYPE (lhs_arg) == TREE_TYPE (rhs_arg));
       if (!cp_tree_equal (lhs_arg, rhs_arg))
-        return 0;
+        return false;
       lhs_bindings = TREE_CHAIN (lhs_bindings);
       rhs_bindings = TREE_CHAIN (rhs_bindings);
     }

	Jakub

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [C++ PATCH] Small performance improvement for constexpr_call_hasher::equal (PR c++/84684)
  2018-03-05 20:31 [C++ PATCH] Small performance improvement for constexpr_call_hasher::equal (PR c++/84684) Jakub Jelinek
@ 2018-03-05 22:08 ` Jason Merrill
  0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2018-03-05 22:08 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: Nathan Sidwell, gcc-patches List

OK.

On Mon, Mar 5, 2018 at 3:31 PM, Jakub Jelinek <jakub@redhat.com> wrote:
> Hi!
>
> This doesn't actually fix this PR (Marek is working on that), but
> just something I've noticed while analyzing the PR.
> We have the hashes saved in the structure (to speed up hash table
> expansion), so it is a waste not to test those also in the equal hook,
> by giving up cheaply in cases of hash table collisions.
>
> Additionally, the method returns bool, so this patch uses true/false
> instead of 1/0.
>
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
>
> 2018-03-05  Jakub Jelinek  <jakub@redhat.com>
>
>         PR c++/84684
>         * constexpr.c (constexpr_call_hasher::equal): Return false if
>         lhs->hash != rhs->hash.  Change return 1 to return true and
>         return 0 to return false.
>
> --- gcc/cp/constexpr.c.jj       2018-03-05 16:11:08.510165108 +0100
> +++ gcc/cp/constexpr.c  2018-03-05 16:14:06.130229884 +0100
> @@ -1033,9 +1033,11 @@ constexpr_call_hasher::equal (constexpr_
>    tree lhs_bindings;
>    tree rhs_bindings;
>    if (lhs == rhs)
> -    return 1;
> +    return true;
> +  if (lhs->hash != rhs->hash)
> +    return false;
>    if (!constexpr_fundef_hasher::equal (lhs->fundef, rhs->fundef))
> -    return 0;
> +    return false;
>    lhs_bindings = lhs->bindings;
>    rhs_bindings = rhs->bindings;
>    while (lhs_bindings != NULL && rhs_bindings != NULL)
> @@ -1044,7 +1046,7 @@ constexpr_call_hasher::equal (constexpr_
>        tree rhs_arg = TREE_VALUE (rhs_bindings);
>        gcc_assert (TREE_TYPE (lhs_arg) == TREE_TYPE (rhs_arg));
>        if (!cp_tree_equal (lhs_arg, rhs_arg))
> -        return 0;
> +        return false;
>        lhs_bindings = TREE_CHAIN (lhs_bindings);
>        rhs_bindings = TREE_CHAIN (rhs_bindings);
>      }
>
>         Jakub

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-03-05 22:08 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-05 20:31 [C++ PATCH] Small performance improvement for constexpr_call_hasher::equal (PR c++/84684) Jakub Jelinek
2018-03-05 22:08 ` Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).