Unstable build/host qsorts causing differing generated target code

Franz Sirl Franz.Sirl-kernel@lauterbach.com
Thu Jan 25 14:28:00 GMT 2018


Am 2018-01-12 um 19:45 schrieb Jeff Law:
> On 01/12/2018 11:26 AM, Cory Fields wrote:
>> Quick disclaimer: I'm 100% new to GCC code and the dev process, so
>> there are bound to be some faulty assumptions below.
>>
>> I recently worked on a build of gcc, x86_64-pc-linux-gnu ->
>> x86_64-pc-linux-musl. In order to boost my confidence in musl, I
>> decided that I'd like to ensure that 3 (and 4) stage bootstraps
>> succeed and compare equal.
>>
>> I quickly ran into failed object comparisons at stage3. The issue, as
>> it turned out, was that musl's qsort algorithm differs significantly
>> from gcc's, though both (as far as I can tell) are perfectly legal.
>> The c spec allows for different results in the cast of unstable
>> arrays.
> THe key here is the results can differ if the comparison function is not
> stable.  That's inherent in the qsort algorithms.
> 
> But, if the comparison functions are fixed, then the implementation
> differences between the qsorts won't matter.
> 
> Alexander Monokov has led an effort to identify cases where the
> comparison functions do not provide a stable ordering and to fix them.
> Some remain, but the majority have been addressed over the last year.
> His work also includes a qsort checking implementation to try and spot
> these problems as part of GCC's internal consistency checking mechanisms.
> 
> His work is on the development trunk and will show up in the upcoming
> gcc-8 release.

Coincidentally I just stumbled over the differences in assembler code 
for a gcc-6 powerpc-eabi cross-compiler running on Linux, Cygwin64 and 
Solaris. With some help from IRC I found the following 3 trunk revisions
seem to be enough to greatly stabilize gcc-6 (and likely gcc-7) on these 
platforms:

r250395:
2017-07-20  Alexander Monakov  <amonakov@ispras.ru>

      * lra-assigns.c (pseudo_compare_func): Fix comparison step based on
      non_spilled_static_chain_regno_p.

r253207:
2017-09-26  Martin Jambor  <mjambor@suse.cz>

      * tree-sra.c (compare_access_positions): Put integral types first,
      stabilize sorting of integral types, remove conditions putting
      non-full-precision integers last.
      (sort_and_splice_var_accesses): Disable scalarization if a
      non-integert would be represented by a non-full-precision integer.

r256682:
2018-01-14  Cory Fields  <cory-nospam-@coryfields.com>

      * tree-ssa-loop-im.c (sort_bbs_in_loop_postorder_cmp): Stabilize sort.
      * ira-color (allocno_hard_regs_compare): Likewise.


All applied cleanly to the current gcc-6-branch. I'm unsure if it's 
worth backporting them to the branches, but since I already prepared the 
list...

Franz



More information about the Gcc mailing list