[PATCH] Speed up qsort in IPA ICF

Martin Liška mliska@suse.cz
Thu Sep 19 13:32:00 GMT 2019


On 9/19/19 3:18 PM, Richard Biener wrote:
> On Thu, Sep 19, 2019 at 3:15 PM Alexander Monakov <amonakov@ispras.ru> wrote:
>>
>> 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;
> 
> Indeed.  We need static type correctness for the comparator :/

Ooops, sorry for the mistake. I'm testing the following patch.
I checked in debugger that uids are valid for a simple test-case.

Martin

> 
> Richard.
> 
>> Thanks.
>> Alexander

-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Fix-cast-in-sort_congruence_class_groups_by_decl_uid.patch
Type: text/x-patch
Size: 1084 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20190919/585fd34b/attachment.bin>


More information about the Gcc-patches mailing list