This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [C++ PATCH] Small performance improvement for constexpr_call_hasher::equal (PR c++/84684)
- From: Jason Merrill <jason at redhat dot com>
- To: Jakub Jelinek <jakub at redhat dot com>
- Cc: Nathan Sidwell <nathan at acm dot org>, gcc-patches List <gcc-patches at gcc dot gnu dot org>
- Date: Mon, 5 Mar 2018 17:08:14 -0500
- Subject: Re: [C++ PATCH] Small performance improvement for constexpr_call_hasher::equal (PR c++/84684)
- Authentication-results: sourceware.org; auth=none
- References: <20180305203103.GQ5867@tucnak>
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