public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH 0/6] qsort comparator consistency fixes
@ 2017-07-15 20:49 Alexander Monakov
  2017-07-15 20:48 ` [PATCH 3/6] lra-assigns.c: fix pseudo_compare_func Alexander Monakov
                   ` (6 more replies)
  0 siblings, 7 replies; 39+ messages in thread
From: Alexander Monakov @ 2017-07-15 20:49 UTC (permalink / raw)
  To: gcc-patches

Hello,

(previous thread here:
https://gcc.gnu.org/ml/gcc-patches/2016-07/msg00944.html )

we still have a few places in GCC where the comparator function passed to qsort
is not actually a proper sorting predicate.  Most commonly it fails to impose
total ordering by lacking transitivity.  It's useful to fix such instances,
because:

- such comparators don't work as intended;
- they lead to issues that can only be reproduced with a specific libc;
- failure usually happens not in qsort, but quite some time later.

(PR 71702 and its duplicates is a good highlight for the latter two, it
could only be observed with qsort from musl libc and manifested as assert
failure in the vectorizer, which was not trivial to diagnose)

The goal of this patchset is to introduce automatic comparator consistency
verification in GCC, with zero impact on release-checking compilers and
minimal workflow disturbance (it should be possible to easily suppress
checking to e.g. unblock bootstrap when there's no obvious fix).

Changes from the last year's patch:

+ both vec::qsort and libc ::qsort are checked (previously only vec::)
+ individual callers can opt out of checking
+ a bit more sensible cutoff for avoiding O(n^2) time complexity
+ unlike a year ago, now this needs 5 accompanying patches for broken
  comparators, meaning new issues have crept in

The first question last year from Richard was about bootstrap time impact.
Last year it appeared to be in the noise, I can do it again if there's
interest.

Patches 1-3 fix broken comparators where the fix is evident, patches 4-5
avoid qsort checking where comparators needs nontrivial fixes, and patch
6 is the actual checking implementation.

  tree-vrp: fix compare_assert_loc qsort comparator
  gimple-ssa-store-merging.c: fix sort_by_bitpos
  lra-assigns.c: fix pseudo_compare_func
  lra-assigns.c: give up on qsort checking in assign_by_spills
  haifa-sched.c: give up qsort checking when autoprefetch heuristic is
    in use
  qsort comparator consistency checking

 gcc/genmodes.c                 |  2 +-
 gcc/gimple-ssa-store-merging.c |  6 +--
 gcc/haifa-sched.c              |  8 ++++
 gcc/lra-assigns.c              | 10 ++---
 gcc/system.h                   | 11 +++++
 gcc/tree-vrp.c                 |  2 +-
 gcc/vec.c                      | 95 ++++++++++++++++++++++++++++++++++++++++++
 7 files changed, 124 insertions(+), 10 deletions(-)

-- 
1.8.3.1

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

end of thread, other threads:[~2017-08-24  6:15 UTC | newest]

Thread overview: 39+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 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 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
2017-07-25  8:47         ` Richard Biener
2017-07-25 16:03         ` Alexander Monakov
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-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-21 14:30 ` [PATCH 7/6] fortran: fix pair_cmp qsort comparator Alexander Monakov
2017-07-23 11:39   ` Thomas Koenig

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).