public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Alan Modra <amodra@gmail.com>
To: binutils@sourceware.org
Subject: [PATCH 2/2] Constant fold view increment expressions
Date: Wed,  9 Mar 2022 15:55:06 +1030	[thread overview]
Message-ID: <20220309052506.4000271-3-amodra@gmail.com> (raw)
In-Reply-To: <20220309052506.4000271-1-amodra@gmail.com>

The idea here is to replace expressions like v + 1 + 1 + 1 with v + 3.

	* dwarf2dbg.c (set_or_check_view): Remove useless assertion.
	Resolve multiple view increments.
	* testsuite/gas/elf/dwarf2-18.d: Don't xfail mep.

diff --git a/gas/dwarf2dbg.c b/gas/dwarf2dbg.c
index 7269c4cdf87..ba97b5f0126 100644
--- a/gas/dwarf2dbg.c
+++ b/gas/dwarf2dbg.c
@@ -402,18 +402,27 @@ set_or_check_view (struct line_entry *e, struct line_entry *p,
   if (viewx.X_op != O_constant || viewx.X_add_number)
     {
       expressionS incv;
+      expressionS *p_view;
 
       if (!p->loc.u.view)
-	{
-	  p->loc.u.view = symbol_temp_make ();
-	  gas_assert (!S_IS_DEFINED (p->loc.u.view));
-	}
+	p->loc.u.view = symbol_temp_make ();
 
       memset (&incv, 0, sizeof (incv));
       incv.X_unsigned = 1;
       incv.X_op = O_symbol;
       incv.X_add_symbol = p->loc.u.view;
       incv.X_add_number = 1;
+      p_view = symbol_get_value_expression (p->loc.u.view);
+      if (p_view->X_op == O_constant || p_view->X_op == O_symbol)
+	{
+	  /* If we can, constant fold increments so that a chain of
+	     expressions v + 1 + 1 ... + 1 is not created.
+	     resolve_expression isn't ideal for this purpose.  The
+	     base v might not be resolvable until later.  */
+	  incv.X_op = p_view->X_op;
+	  incv.X_add_symbol = p_view->X_add_symbol;
+	  incv.X_add_number = p_view->X_add_number + 1;
+	}
 
       if (viewx.X_op == O_constant)
 	{
diff --git a/gas/testsuite/gas/elf/dwarf2-18.d b/gas/testsuite/gas/elf/dwarf2-18.d
index db7a4f9f20b..fbaebaa9019 100644
--- a/gas/testsuite/gas/elf/dwarf2-18.d
+++ b/gas/testsuite/gas/elf/dwarf2-18.d
@@ -2,9 +2,8 @@
 #readelf: -x.rodata -wL
 #name: DWARF2 18
 # The am33 cr16 crx ft32 mn10 msp430 nds32 and rl78 targets do not evaluate the subtraction of symbols at assembly time.
-# The mep targets turns some view computations into complex relocations.
 # The riscv targets do not support the subtraction of symbols.
-#xfail: am3*-* cr16-* crx-* ft32*-* mep-* mn10*-* msp430-* nds32*-* riscv*-* rl78-*
+#xfail: am3*-* cr16-* crx-* ft32*-* mn10*-* msp430-* nds32*-* riscv*-* rl78-*
 
 Hex dump of section '\.rodata':
   0x00000000 0100 *.*

  parent reply	other threads:[~2022-03-09  5:25 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-09  5:25 [PATCH 0/2] rh2059646 - compilation of prusa-slicer hangs Alan Modra
2022-03-09  5:25 ` [PATCH 1/2] Reduce duplicated symbol_clone_if_forward_ref work Alan Modra
2022-03-09  5:25 ` Alan Modra [this message]
2022-03-09  9:23   ` Fix for bug 28924 Viorel Preoteasa
2022-03-09 11:42     ` Nick Clifton
2022-03-16 19:10       ` Viorel Preoteasa

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=20220309052506.4000271-3-amodra@gmail.com \
    --to=amodra@gmail.com \
    --cc=binutils@sourceware.org \
    /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).