From patchwork Wed Sep 13 13:02:16 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kyrill Tkachov X-Patchwork-Id: 813426 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-462030-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="g9AaW8UM"; 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 3xshdz551sz9sNr for ; Wed, 13 Sep 2017 23:02:29 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:subject:content-type; q= dns; s=default; b=KcXFQBkRR9L4XtOvVYYqN4+0yZbWDPX85sK+mQNfBl3xdM BBdvDc/ZFqqBadaXMkvDwKhM3yHYBMDPG3PGR1si3gc+dvyJaM06oHREXmoqFtgD lPuXnBHWyjHjg77Lus5/mX2LYBFLmFkHH+gC+WE8iaU6SoV1jG63qA9/+iM0Y= 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 :message-id:date:from:mime-version:to:subject:content-type; s= default; bh=niFB38ybIOOQHk1wHZwb87aq9U8=; b=g9AaW8UMOXz3ZnDJrG4O bnsaGrrMRRq8UBIkhGdMuT8AOAl59vczN8dXkDo2x1nMBFJLLtXPeEQDkH6uNUWZ OTJf2OX4cLUUdonbWMZpqzlQTbLs6EtDd8lk0GDvx1FeiXxCcmOY7ceI6FK5/LFp tQVeZ79wePjLT1/ETSfR7e4= Received: (qmail 32479 invoked by alias); 13 Sep 2017 13:02:22 -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 32465 invoked by uid 89); 13 Sep 2017 13:02:21 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=Hx-languages-length:1295 X-HELO: foss.arm.com Received: from foss.arm.com (HELO foss.arm.com) (217.140.101.70) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 13 Sep 2017 13:02:20 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 2EDEC1596 for ; Wed, 13 Sep 2017 06:02:18 -0700 (PDT) Received: from [10.2.207.77] (e100706-lin.cambridge.arm.com [10.2.207.77]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id CBADF3F58C for ; Wed, 13 Sep 2017 06:02:17 -0700 (PDT) Message-ID: <59B92C58.6070204@foss.arm.com> Date: Wed, 13 Sep 2017 14:02:16 +0100 From: Kyrill Tkachov User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.2.0 MIME-Version: 1.0 To: "gcc-patches@gcc.gnu.org" Subject: [PATCH][store-merging] Use store order as tie-breaker in sort_by_bitpos Hi all, As Alexander pointed out in the thread starting at [1] the sort_by_bitpos sorting function was behaving badly when we had multiple stores at the same position. He fixed that (thanks!) but we can do better by not returning zero when the bitpositions are equal but by falling back to comparing the order the stores appear in, which is guaranteed to be unique (barring other bugs elsewhere). This patch does that. Bootstrapped and tested on aarch64-none-linux-gnu. Ok for trunk? Thanks, Kyrill [1] https://gcc.gnu.org/ml/gcc-patches/2017-07/msg00895.html 2017-09-13 Kyrylo Tkachov * gimple-ssa-store-merging.c (sort_by_bitpos): Compare store order when bitposition is the same. diff --git a/gcc/gimple-ssa-store-merging.c b/gcc/gimple-ssa-store-merging.c index c60d56a..3260c56 100644 --- a/gcc/gimple-ssa-store-merging.c +++ b/gcc/gimple-ssa-store-merging.c @@ -521,7 +521,9 @@ sort_by_bitpos (const void *x, const void *y) else if ((*tmp)->bitpos > (*tmp2)->bitpos) return 1; else - return 0; + /* If they are the same let's use the order which is guaranteed to + be different. */ + return (*tmp)->order - (*tmp2)->order; } /* Sorting function for store_immediate_info objects.