public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Kyrill Tkachov <kyrylo.tkachov@foss.arm.com>
To: Alexander Monakov <amonakov@ispras.ru>,
	 Segher Boessenkool <segher@kernel.crashing.org>
Cc: gcc-patches@gcc.gnu.org
Subject: Re: [PATCH 2/6] gimple-ssa-store-merging.c: fix sort_by_bitpos
Date: Tue, 25 Jul 2017 08:34:00 -0000	[thread overview]
Message-ID: <59770299.8060501@foss.arm.com> (raw)
In-Reply-To: <alpine.LNX.2.20.13.1707242344510.5204@monopod.intra.ispras.ru>

Hi,

On 24/07/17 21:48, Alexander Monakov wrote:
> On Sat, 22 Jul 2017, Segher Boessenkool wrote:
>
>> On Sat, Jul 15, 2017 at 11:47:45PM +0300, Alexander Monakov wrote:
>>> --- a/gcc/gimple-ssa-store-merging.c
>>> +++ b/gcc/gimple-ssa-store-merging.c
>>> @@ -516,12 +516,12 @@ sort_by_bitpos (const void *x, const void *y)
>>>     store_immediate_info *const *tmp = (store_immediate_info * const *) x;
>>>     store_immediate_info *const *tmp2 = (store_immediate_info * const *) y;
>>>   
>>> -  if ((*tmp)->bitpos <= (*tmp2)->bitpos)
>>> +  if ((*tmp)->bitpos < (*tmp2)->bitpos)
>>>       return -1;
>>>     else if ((*tmp)->bitpos > (*tmp2)->bitpos)
>>>       return 1;
>>> -
>>> -  gcc_unreachable ();
>>> +  else
>>> +    return 0;
>>>   }
>> Does any sort using this comparison function require the sort to be
>> stable?
>>
>> It looks like the <= was simply a typo and should have been <, but
>> the gcc_unreachable was as intended?  (With <= it is trivially
>> unreachable there).
> I think it's best if the original author can chime in - adding Kyrill.
>
> (to be clear, equal bitpos is possible, this issue causes qsort checker errors)

For the uses of this function the order when the bitpos is the same
does not matter, I just wanted to avoid returning zero to avoid perturbations
due to qsort.
IMO the right thing to do here to avoid the qsort checker errors is to break the tie between
store_immediate_info objects with equal bitpos by using the sort_by_order heuristic
i.e. something like "return (*tmp)->order - (*tmp2)->order;".
That should give well-behaved results as the order of two store_immediate_info objects
is guaranteed not to be the same (otherwise something has gone wrong elsewhere).

Thanks,
Kyrill

> Alexander

  reply	other threads:[~2017-07-25  8:34 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-15 20:49 [PATCH 0/6] qsort comparator consistency fixes Alexander Monakov
2017-07-15 20:48 ` [PATCH 3/6] lra-assigns.c: fix pseudo_compare_func Alexander Monakov
2017-07-19  6:50   ` Jeff Law
2017-07-15 20:49 ` [PATCH 2/6] gimple-ssa-store-merging.c: fix sort_by_bitpos Alexander Monakov
2017-07-19  6:50   ` Jeff Law
2017-07-22 11:15   ` Segher Boessenkool
2017-07-24 20:49     ` Alexander Monakov
2017-07-25  8:34       ` Kyrill Tkachov [this message]
2017-07-25  8:47         ` Richard Biener
2017-07-25 16:03         ` Alexander Monakov
2017-07-15 20:49 ` [PATCH 5/6] haifa-sched.c: give up qsort checking when autoprefetch heuristic is in use Alexander Monakov
2017-07-31 17:44   ` Jeff Law
2017-07-15 20:49 ` [PATCH 6/6] qsort comparator consistency checking Alexander Monakov
2017-07-31 18:06   ` Jeff Law
2017-07-31 18:28     ` Alexander Monakov
2017-08-02 17:16       ` Jeff Law
2017-08-02 17:29   ` Jeff Law
2017-08-02 18:00     ` Alexander Monakov
2017-08-02 18:08       ` Jeff Law
2017-08-03 14:25         ` Alexander Monakov
2017-08-03 15:33           ` Jeff Law
2017-08-03 15:53             ` Jakub Jelinek
2017-08-03 16:23               ` Alexander Monakov
2017-08-03 16:27                 ` Oleg Endo
2017-08-03 16:31                   ` Alexander Monakov
2017-08-03 16:35                     ` Oleg Endo
2017-08-03 16:28                 ` Jakub Jelinek
2017-08-07 14:07                 ` Pedro Alves
2017-08-09 16:35                 ` Jeff Law
2017-08-10 13:35                   ` Alexander Monakov
2017-08-24  6:27                     ` Jeff Law
2017-08-09 16:31               ` Jeff Law
2017-07-15 20:49 ` [PATCH 1/6] tree-vrp: fix compare_assert_loc qsort comparator Alexander Monakov
2017-07-19  6:51   ` Jeff Law
2017-07-15 20:49 ` [PATCH 4/6] lra-assigns.c: give up on qsort checking in assign_by_spills Alexander Monakov
2017-07-18 19:51   ` Yuri Gribov
2017-07-31 17:42   ` Jeff Law
2017-07-21 14:30 ` [PATCH 7/6] fortran: fix pair_cmp qsort comparator Alexander Monakov
2017-07-23 11:39   ` Thomas Koenig

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=59770299.8060501@foss.arm.com \
    --to=kyrylo.tkachov@foss.arm.com \
    --cc=amonakov@ispras.ru \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=segher@kernel.crashing.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).