From patchwork Wed Feb 16 11:12:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Andre Vieira (lists)" X-Patchwork-Id: 1593632 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=VDtpZdpG; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4JzFgL2pGmz9s1l for ; Wed, 16 Feb 2022 22:13:00 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BE2893857C6E for ; Wed, 16 Feb 2022 11:12:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BE2893857C6E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1645009976; bh=RKsxpWaExmo3TAWF2pQIuWcj3JtMrT+3ZmJhKTXA7w8=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=VDtpZdpGeU6qEpX0guXpjABKJhHbCgDErcpPQzhz6xhlUZQ2EbxUyoiAkePdzESAr QTjVs7suJHDOn3PJkB6xWEZUd1gSgpSwOOAxXDMoCwmrc/8sV3O2hRZeJ6Vg+Pq+IW uBWNkYfouDMkyolPex8nUKu+Z+zdTJI7C5raKOlQ= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by sourceware.org (Postfix) with ESMTP id 573223858D3C for ; Wed, 16 Feb 2022 11:12:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 573223858D3C Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 083C7D6E; Wed, 16 Feb 2022 03:12:36 -0800 (PST) Received: from [10.57.12.187] (unknown [10.57.12.187]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 8549C3F66F; Wed, 16 Feb 2022 03:12:35 -0800 (PST) Message-ID: <9eb88215-8d5c-c39d-7aae-d2f8aa2d8795@arm.com> Date: Wed, 16 Feb 2022 11:12:27 +0000 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.6.0 Content-Language: en-US To: "gcc-patches@gcc.gnu.org" Subject: [PATCH][gcc][middle-end] PR104498: Fix comparing symbol reference X-Spam-Status: No, score=-10.8 required=5.0 tests=BAYES_00, BODY_8BITS, GIT_PATCH_0, KAM_DMARC_STATUS, KAM_STOCKGEN, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: "Andre Vieira \(lists\) via Gcc-patches" From: "Andre Vieira (lists)" Reply-To: "Andre Vieira \(lists\)" Cc: Richard Sandiford , Richard Biener Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Hi, As reported on PR104498, the issue here is that when compare_base_symbol_refs swaps x and y but doesn't take that into account when computing the distance. This patch makes sure that if x and y are swapped, we correct the distance computation by multiplying it by -1 to end up with the correct expected result of the original Y_BASE - X_BASE. Bootstrapped and regression tested on aarch64-none-linux. OK for trunk? gcc/ChangeLog:         PR middle-end/104498         * alias.cc (compare_base_symbol_refs): Correct distance computation when         swapping x and y. diff --git a/gcc/alias.cc b/gcc/alias.cc index 3fd71cff2e2b488bc39fcf7d937e118b96f491ab..8c08452e0acfcbf1bfd8fd2e8cd420b5b929d6b4 100644 --- a/gcc/alias.cc +++ b/gcc/alias.cc @@ -2195,6 +2195,7 @@ compare_base_symbol_refs (const_rtx x_base, const_rtx y_base, tree x_decl = SYMBOL_REF_DECL (x_base); tree y_decl = SYMBOL_REF_DECL (y_base); bool binds_def = true; + bool swap = false; if (XSTR (x_base, 0) == XSTR (y_base, 0)) return 1; @@ -2204,6 +2205,7 @@ compare_base_symbol_refs (const_rtx x_base, const_rtx y_base, { if (!x_decl) { + swap = true; std::swap (x_decl, y_decl); std::swap (x_base, y_base); } @@ -2238,8 +2240,8 @@ compare_base_symbol_refs (const_rtx x_base, const_rtx y_base, if (SYMBOL_REF_BLOCK (x_base) != SYMBOL_REF_BLOCK (y_base)) return 0; if (distance) - *distance += (SYMBOL_REF_BLOCK_OFFSET (y_base) - - SYMBOL_REF_BLOCK_OFFSET (x_base)); + *distance += (swap ? -1 : 1) * (SYMBOL_REF_BLOCK_OFFSET (y_base) + - SYMBOL_REF_BLOCK_OFFSET (x_base)); return binds_def ? 1 : -1; } /* Either the symbols are equal (via aliasing) or they refer to