public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [patch] fix regrename pass to ensure renamings produce valid insns
@ 2015-06-17 17:36 Sandra Loosemore
  2015-06-17 19:23 ` Richard Sandiford
                   ` (2 more replies)
  0 siblings, 3 replies; 25+ messages in thread
From: Sandra Loosemore @ 2015-06-17 17:36 UTC (permalink / raw)
  To: GCC Patches; +Cc: Chung-Lin Tang

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

We ran across problems with the regrename pass introducing invalid insns 
while working on support for new load/store multiple instructions on 
nios2.  We're using an implementation similar to what ARM already does, 
with a match_parallel predicate testing for restrictions on the 
underlying machine instructions that can't be expressed using GCC 
register constraints.  (E.g., the register numbers do not have to be 
sequential, but they do have to be ascending/descending and a 
combination that can be encoded in the machine instruction.)

The attached patch teaches regrename to validate insns affected by each 
register renaming before making the change.  I can see at least two 
other ways to handle this -- earlier, by rejecting renamings that result 
in invalid instructions when it's searching for the best renaming; or 
later, by validating the entire set of renamings as a group instead of 
incrementally for each one -- but doing it all in regname_do_replace 
seems least disruptive and risky in terms of the existing code.

There are a couple of old bugzilla tickets for 
instruction-doesn't-satisfy-its-constraints ICEs in regrename that might 
or might not be related to this.  The symptom we saw was not an ICE, 
just bad code being emitted that resulted in assembler errors.

I've bootstrapped and regression-tested this on x86_64-linux-gnu in 
addition to our testing with the pending nios2 patch set.  OK to commit?

-Sandra


[-- Attachment #2: regrename.log --]
[-- Type: text/x-log, Size: 180 bytes --]

2015-06-17  Chung-Lin Tang <cltang@codesourcery.com>
	    Sandra Loosemore <sandra@codesourcery.com>

	gcc/
	* regrename.c (regrename_do_replace): Re-validate the modified
	insns.

[-- Attachment #3: regrename.patch --]
[-- Type: text/x-patch, Size: 1081 bytes --]

Index: gcc/regrename.c
===================================================================
--- gcc/regrename.c	(revision 224532)
+++ gcc/regrename.c	(working copy)
@@ -942,19 +942,22 @@ regrename_do_replace (struct du_head *he
       int reg_ptr = REG_POINTER (*chain->loc);
 
       if (DEBUG_INSN_P (chain->insn) && REGNO (*chain->loc) != base_regno)
-	INSN_VAR_LOCATION_LOC (chain->insn) = gen_rtx_UNKNOWN_VAR_LOC ();
+	validate_change (chain->insn, &(INSN_VAR_LOCATION_LOC (chain->insn)),
+			 gen_rtx_UNKNOWN_VAR_LOC (), true);
       else
 	{
-	  *chain->loc = gen_raw_REG (GET_MODE (*chain->loc), reg);
+	  validate_change (chain->insn, chain->loc, 
+			   gen_raw_REG (GET_MODE (*chain->loc), reg), true);
 	  if (regno >= FIRST_PSEUDO_REGISTER)
 	    ORIGINAL_REGNO (*chain->loc) = regno;
 	  REG_ATTRS (*chain->loc) = attr;
 	  REG_POINTER (*chain->loc) = reg_ptr;
 	}
-
-      df_insn_rescan (chain->insn);
     }
 
+  if (!apply_change_group ())
+    return;
+
   mode = GET_MODE (*head->first->loc);
   head->regno = reg;
   head->nregs = hard_regno_nregs[reg][mode];

^ permalink raw reply	[flat|nested] 25+ messages in thread

end of thread, other threads:[~2015-11-13 15:13 UTC | newest]

Thread overview: 25+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-17 17:36 [patch] fix regrename pass to ensure renamings produce valid insns Sandra Loosemore
2015-06-17 19:23 ` Richard Sandiford
2015-06-18 18:26 ` Eric Botcazou
2015-06-24  3:31   ` Sandra Loosemore
2015-06-24  7:59     ` Ramana Radhakrishnan
2015-06-24 14:57       ` Sandra Loosemore
2015-06-24 16:50     ` Eric Botcazou
2015-06-24 16:59       ` Eric Botcazou
2015-06-25  3:53     ` Jeff Law
2015-06-25 12:30       ` Bernd Schmidt
2015-06-25 13:54         ` Eric Botcazou
2015-06-25 13:59           ` Bernd Schmidt
2015-06-29  0:18       ` Sandra Loosemore
2015-06-30  3:54         ` Kito Cheng
2015-06-30  5:08           ` Sandra Loosemore
2015-06-30  5:26             ` Chung-Lin Tang
2015-06-30  6:11               ` Chung-Lin Tang
2015-06-30  9:08                 ` Eric Botcazou
2015-06-30 11:03                   ` Chung-Lin Tang
2015-06-30 19:11                   ` Sandra Loosemore
2015-06-30 21:31                     ` Eric Botcazou
2015-07-01 17:03         ` Jeff Law
2015-11-06 10:48 ` Bernd Schmidt
2015-11-06 19:51   ` Jeff Law
2015-11-13 15:13     ` Bernd Schmidt

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