From patchwork Wed Feb 7 16:58:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Franz Sirl X-Patchwork-Id: 870518 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-472763-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="nVLNSgsI"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3zc6wt2QVkz9ryr for ; Thu, 8 Feb 2018 03:58:53 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:cc:message-id:date:mime-version:content-type; q= dns; s=default; b=wftC7BHGOfzRtkqIhBNPcMN9C6p5Sv30o8sWVxEVVmSPUA FBJ+nAYAl8BSCAsm2GnEaeK3Q8b1nIQtv+eSKS+vcZD/KRueb0SdU+mFllusB6Gj J3l7ubCuCDUkUs7NNYlU+YRUapWSCwrfXsTyv1Lk3B7Z+Ju1gMw24AzJaw98Q= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:cc:message-id:date:mime-version:content-type; s= default; bh=4/tvqChNaP+1Y4p4cz3crF/jkzU=; b=nVLNSgsIfPBa5Tp7kmGu DUI1daCHr6+/Qy9DPKHJDOxwSx/ke4aMKdsGVMpH+ZjjQ67lJtO90us8IrlaDuXi nRGLzTQ3PMUwczBJ836sojqfzDBItxmJwqCjGYWqJvzANIkA+helP39FgK7+lr8W WsltjH7abzra3ob84EXaEFQ= Received: (qmail 79944 invoked by alias); 7 Feb 2018 16:58:45 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 79934 invoked by uid 89); 7 Feb 2018 16:58:44 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-15.0 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=H*r:qmail-ldap-1.03, H*r:envelope-sender, H*u:6.1, H*UA:6.1 X-HELO: smtp1.lauterbach.com Received: from smtp1.lauterbach.com (HELO smtp1.lauterbach.com) (62.154.241.196) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 07 Feb 2018 16:58:42 +0000 Received: (qmail 19499 invoked by uid 484); 7 Feb 2018 16:58:39 -0000 X-Qmail-Scanner-Diagnostics: from 10.2.11.10 by smtp1.lauterbach.com (envelope-from , uid 484) with qmail-scanner-2.11 (mhr: 1.0. clamdscan: 0.99/21437. spamassassin: 3.4.0. Clear:RC:1(10.2.11.10):. Processed in 0.795706 secs); 07 Feb 2018 16:58:39 -0000 Received: from unknown (HELO [10.2.11.10]) (Authenticated_SSL:fsirl@[10.2.11.10]) (envelope-sender ) by smtp1.lauterbach.com (qmail-ldap-1.03) with ECDHE-RSA-AES256-GCM-SHA384 encrypted SMTP for ; 7 Feb 2018 16:58:35 -0000 To: GCC Patches From: Franz Sirl Subject: [RFC][PATCH] Stabilize a few qsort comparison functions Cc: Martin Jambor , Alexander Monakov Message-ID: <59816ffe-61ea-c887-14f7-1ff11c8574ef@lauterbach.com> Date: Wed, 7 Feb 2018 17:58:35 +0100 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:58.0) Gecko/20100101 Thunderbird/58.0 MIME-Version: 1.0 X-IsSubscribed: yes Hi, this is the result of an attempt to minimize the differences between the compile results of a Linux-based and a Cygwin64-based powerpc-eabi cross toolchain. The method used was:     - find the -fverbose-asm assembler files that differ     - compile that file again on both platforms with        -O2 -g3 -fdump-tree-all-all -fdump-rtl-all -fdump-noaddr     - look for the first dump file with differences and check that pass       for qsort's     - stabilize the compare functions With some help on IRC to better understand the passes and some serious debugging of GCC I came up with this patch. On the tested codebase the differences in the assembler sources are now down to 0. If the various pass maintainers have better ideas on how to stabilize the compare functions, I'll be happy to verify them on the codebase. For the SRA patch I already have an alternate version with an additional ID member. Comments? Bootstrapped on linux-x86_64, no testsuite regressions. Franz Sirl 2018-02-07  Franz Sirl     * ira-build.c (object_range_compare_func): Stabilize sort.     * tree-sra.c (compare_access_positions): Likewise.     * varasm.c (output_object_block_compare): Likewise.     * tree-ssa-loop-ivopts.c (group_compare_offset): Likewise.     (struct iv_common_cand): New member.     (record_common_cand): Initialize new member.     (common_cand_cmp): Use new member to stabilize sort.     * tree-vrp.c (struct assert_locus): New member.     (register_new_assert_for): Initialize new member.     (compare_assert_loc): Use new member to stabilize sort. Index: gcc/ira-build.c =================================================================== --- gcc/ira-build.c (revision 257438) +++ gcc/ira-build.c (working copy) @@ -2787,8 +2787,10 @@ object_range_compare_func (const void *v1p, const if ((diff = OBJECT_MIN (obj1) - OBJECT_MIN (obj2)) != 0) return diff; if ((diff = OBJECT_MAX (obj1) - OBJECT_MAX (obj2)) != 0) - return diff; - return ALLOCNO_NUM (a1) - ALLOCNO_NUM (a2); + return diff; + if ((diff = ALLOCNO_NUM (a1) - ALLOCNO_NUM (a2)) != 0) + return diff; + return OBJECT_SUBWORD (obj1) - OBJECT_SUBWORD (obj2); } /* Sort ira_object_id_map and set up conflict id of allocnos. */ Index: gcc/tree-sra.c =================================================================== --- gcc/tree-sra.c (revision 257438) +++ gcc/tree-sra.c (working copy) @@ -1567,7 +1567,13 @@ compare_access_positions (const void *a, const voi if (f1->size == f2->size) { if (f1->type == f2->type) - return 0; + { + if (f1->stmt == f2->stmt) + return 0; + if (f1->stmt && f2->stmt) + return gimple_uid (f1->stmt) - gimple_uid (f2->stmt); + return f1->stmt ? -1 : 1; + } /* Put any non-aggregate type before any aggregate type. */ else if (!is_gimple_reg_type (f1->type) && is_gimple_reg_type (f2->type)) Index: gcc/tree-ssa-loop-ivopts.c =================================================================== --- gcc/tree-ssa-loop-ivopts.c (revision 257438) +++ gcc/tree-ssa-loop-ivopts.c (working copy) @@ -443,6 +443,7 @@ struct iv_common_cand /* IV uses from which this common candidate is derived. */ auto_vec uses; hashval_t hash; + unsigned id; }; /* Hashtable helpers. */ @@ -2617,8 +2618,11 @@ group_compare_offset (const void *a, const void *b { const struct iv_use *const *u1 = (const struct iv_use *const *) a; const struct iv_use *const *u2 = (const struct iv_use *const *) b; + int diff; - return compare_sizes_for_sort ((*u1)->addr_offset, (*u2)->addr_offset); + if ((diff = compare_sizes_for_sort ((*u1)->addr_offset, (*u2)->addr_offset)) != 0) + return diff; + return (*u1)->id - (*u2)->id; } /* Check if small groups should be split. Return true if no group @@ -3378,6 +3382,7 @@ record_common_cand (struct ivopts_data *data, tree struct iv_common_cand ent; struct iv_common_cand **slot; + ent.id = data->iv_common_cands.length (); ent.base = base; ent.step = step; ent.hash = iterative_hash_expr (base, 0); @@ -3387,6 +3392,7 @@ record_common_cand (struct ivopts_data *data, tree if (*slot == NULL) { *slot = new iv_common_cand (); + (*slot)->id = ent.id; (*slot)->base = base; (*slot)->step = step; (*slot)->uses.create (8); @@ -3412,6 +3418,8 @@ common_cand_cmp (const void *p1, const void *p2) n1 = (*ccand1)->uses.length (); n2 = (*ccand2)->uses.length (); + if (n1 == n2) + return (*ccand1)->id - (*ccand2)->id; return n2 - n1; } Index: gcc/tree-vrp.c =================================================================== --- gcc/tree-vrp.c (revision 257438) +++ gcc/tree-vrp.c (working copy) @@ -101,6 +101,8 @@ struct assert_locus /* Predicate code for the ASSERT_EXPR. Must be COMPARISON_CLASS_P. */ enum tree_code comp_code; + unsigned id; + /* Value being compared against. */ tree val; @@ -2814,6 +2816,7 @@ register_new_assert_for (tree name, tree expr, { assert_locus *n, *loc, *last_loc; basic_block dest_bb; + unsigned cnt = 0; gcc_checking_assert (bb == NULL || e == NULL); @@ -2882,6 +2885,7 @@ register_new_assert_for (tree name, tree expr, /* Update the last node of the list and move to the next one. */ last_loc = loc; loc = loc->next; + cnt++; } /* If we didn't find an assertion already registered for @@ -2895,6 +2899,7 @@ register_new_assert_for (tree name, tree expr, n->val = val; n->expr = expr; n->next = NULL; + n->id = cnt; if (last_loc) last_loc->next = n; @@ -4591,9 +4596,15 @@ compare_assert_loc (const void *pa, const void *pb /* Break the tie using hashing and source/bb index. */ if (ha == hb) - return (a->e != NULL - ? a->e->src->index - b->e->src->index - : a->bb->index - b->bb->index); + { + if (a->e != NULL) + { + if (a->e == b->e) + return a->id - b->id; + return a->e->src->index - b->e->src->index; + } + return a->bb->index - b->bb->index; + } return ha > hb ? 1 : -1; } Index: gcc/varasm.c =================================================================== --- gcc/varasm.c (revision 257438) +++ gcc/varasm.c (working copy) @@ -7632,7 +7632,11 @@ output_object_block_compare (const void *x, const unsigned f1 = p1->sect->common.flags; unsigned f2 = p2->sect->common.flags; if (f1 == f2) - return 0; + { + if (p1->anchors && p2->anchors) + return strcmp (XSTR ((*p1->anchors)[0], 0), XSTR ((*p2->anchors)[0], 0)); + return 0; + } return f1 < f2 ? -1 : 1; }