public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Andre Vieira (lists)" <andre.simoesdiasvieira@arm.com>
To: "gcc-patches@gcc.gnu.org" <gcc-patches@gcc.gnu.org>
Cc: Richard Sandiford <richard.sandiford@arm.com>,
	Richard Biener <rguenther@suse.de>
Subject: [PATCH][gcc][middle-end] PR104498: Fix comparing symbol reference
Date: Wed, 16 Feb 2022 11:12:27 +0000	[thread overview]
Message-ID: <9eb88215-8d5c-c39d-7aae-d2f8aa2d8795@arm.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 604 bytes --]

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.

[-- Attachment #2: pr104498.patch --]
[-- Type: text/plain, Size: 1152 bytes --]

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

             reply	other threads:[~2022-02-16 11:12 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-16 11:12 Andre Vieira (lists) [this message]
2022-02-17  9:54 ` Richard Biener

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9eb88215-8d5c-c39d-7aae-d2f8aa2d8795@arm.com \
    --to=andre.simoesdiasvieira@arm.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=rguenther@suse.de \
    --cc=richard.sandiford@arm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).