This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Speed up qsort in IPA ICF
- From: Alexander Monakov <amonakov at ispras dot ru>
- To: Richard Biener <richard dot guenther at gmail dot com>
- Cc: Martin Liška <mliska at suse dot cz>, GCC Patches <gcc-patches at gcc dot gnu dot org>
- Date: Thu, 19 Sep 2019 16:15:42 +0300 (MSK)
- Subject: Re: [PATCH] Speed up qsort in IPA ICF
- References: <e787c43e-2be4-ee92-7820-b8968856a3ea@suse.cz> <CAFiYyc1sw4x09sODqPN1jgezdDPm9246Sn6KcM0puTHsU=+j7Q@mail.gmail.com> <e51cbe6c-b917-446c-c190-01a3d03b363f@suse.cz> <CAFiYyc36y7x5e1_d1oxMshtJi+gy_de0+fb-=Upj7a050ipi_g@mail.gmail.com>
On Thu, 19 Sep 2019, Richard Biener wrote:
> > Good point, there's a tested patch.
>
> OK.
Hold on, is the new comparator really correct?
@@ -3384,20 +3372,11 @@ sort_congruence_classes_by_decl_uid (const void *a, const void *b)
static int
sort_congruence_class_groups_by_decl_uid (const void *a, const void *b)
{
- const congruence_class_group *g1
- = *(const congruence_class_group * const *)a;
- const congruence_class_group *g2
- = *(const congruence_class_group * const *)b;
-
- int uid1 = DECL_UID (g1->classes[0]->members[0]->decl);
- int uid2 = DECL_UID (g2->classes[0]->members[0]->decl);
-
- if (uid1 < uid2)
- return -1;
- else if (uid1 > uid2)
- return 1;
- else
- return 0;
+ const std::pair<congruence_class_group *, int> *g1
+ = *(const std::pair<congruence_class_group *, int> *const *) a;
+ const std::pair<congruence_class_group *, int> *g2
+ = *(const std::pair<congruence_class_group *, int> *const *) b;
+ return g1->second - g2->second;
}
AFAICT the vec holds pairs, not pointers to pairs, so why does the comparator
cast to a pointer-to-pointer-to-pair? Shouldn't it read
const std::pair<congruence_class_group *, int> *g1
= (const std::pair<congruence_class_group *, int> *) a;
Thanks.
Alexander