public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [SH][committed] Avoid potential slient wrong-code with reg+reg addr. modes
@ 2016-06-04  6:11 Oleg Endo
  0 siblings, 0 replies; only message in thread
From: Oleg Endo @ 2016-06-04  6:11 UTC (permalink / raw)
  To: gcc-patches

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

Hi,

The attached patch removes the hardcoded "r0" when printing reg+reg
addressing mode mems on SH.

Tested on sh-elf with
make -k check RUNTESTFLAGS="--target_board=sh-sim\{-m2/-ml,-m2/-mb,
-m2a/-mb,-m4/-ml,-m4/-mb,-m4a/-ml,-m4a/-mb}"

Committed as r237088.

Cheers,
Oleg

gcc/ChangeLog:
	* config/sh/sh.c (sh_print_operand_address): Don't use hardcoded 'r0'
	for reg+reg addressing mode.

[-- Attachment #2: sh_reg_reg_addr_mode_printing.patch --]
[-- Type: text/x-patch, Size: 873 bytes --]

diff --git a/gcc/config/sh/sh.c b/gcc/config/sh/sh.c
index 2bd917a..74327aa 100644
--- a/gcc/config/sh/sh.c
+++ b/gcc/config/sh/sh.c
@@ -1038,8 +1038,16 @@ sh_print_operand_address (FILE *stream, machine_mode /*mode*/, rtx x)
 	      int base_num = true_regnum (base);
 	      int index_num = true_regnum (index);
 
-	      fprintf (stream, "@(r0,%s)",
-		       reg_names[MAX (base_num, index_num)]);
+	      /* If base or index is R0, make sure that it comes first.
+		 Usually one of them will be R0, but the order might be wrong.
+		 If neither base nor index are R0 it's an error and we just
+		 pass it on to the assembler.  This avoids silent wrong code
+		 bugs.  */
+	      if (base_num == 0 && index_num != 0)
+		std::swap (base_num, index_num);
+
+	      fprintf (stream, "@(%s,%s)", reg_names[index_num],
+					   reg_names[base_num]);
 	      break;
 	    }
 

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2016-06-04  6:11 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-04  6:11 [SH][committed] Avoid potential slient wrong-code with reg+reg addr. modes Oleg Endo

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).