PATCH to regmove.c: snag in the optimize_reg_copy_3 for loop

Brendan Kehoe brendan@cygnus.com
Wed Oct 13 10:29:00 GMT 1999


Path: cygnus.com!newsgate-cygnus!cygnus.com!brendan
Lines: 81
Message-ID: <14315.35766.724110.769077.cygnus.gcc@dalkey.network.home>
NNTP-Posting-Host: runyon.cygnus.com
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Xref: cygnus.com cygnus.gcc:21300

In regmove.c:optimize_reg_copy_3 it does

  for (p = PREV_INSN (insn); p && ! reg_set_p (src_reg, p); p = PREV_INSN (p))
    {
      if (GET_CODE (p) == CODE_LABEL || GET_CODE (p) == JUMP_INSN
	  || (GET_CODE (p) == NOTE
	      && (NOTE_LINE_NUMBER (p) == NOTE_INSN_LOOP_BEG
		  || NOTE_LINE_NUMBER (p) == NOTE_INSN_LOOP_END)))
	return;
	...
     }

In reg_set_p, it starts right off with

  if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
    {
    ...
    }

The RTL that's being handled for one case I'm looking at is actually

-- cut --
(note 2 0 3 "" NOTE_INSN_DELETED)

(note 2 0 3 "" NOTE_INSN_DELETED)

(note 3 2 4 "" NOTE_INSN_FUNCTION_BEG)

(note 4 3 6 "" NOTE_INSN_DELETED)

(note 6 4 47 0 NOTE_INSN_BLOCK_BEG)

(note 47 6 8 [bb 0] NOTE_INSN_BASIC_BLOCK)

(insn 8 47 10 (set (reg:HI 20)
        (zero_extend:HI (reg/v:QI 16))) 104 {zero_extendqihi2} (nil)
    (expr_list:REG_DEAD (reg/v:QI 16)
        (nil)))
... etc ...
-- cut --

It's bogus for it to run itself straight to the beginning, and then continue
on.  In theory, it'll get a null value for the PREV_INSN of the very first
insn, for instance.

Instead, we can check that we've still got an insn to address.  Jeff Law has
already reviewed this patch, and it's been checked in.

Thanks,
B

1999-10-13  Brendan Kehoe  <brendan@cygnus.com>

	* regmove.c (optimize_reg_copy_3): Make sure P is non-nil as we
	climb up the chain of insns.

Index: regmove.c
diff -u -p -r1.71 regmove.c
--- regmove.c	1999/10/03 16:47:51	1.71
+++ regmove.c	1999/10/13 17:24:57
@@ -679,7 +679,7 @@ optimize_reg_copy_3 (insn, dest, src)
       || ! find_reg_note (insn, REG_DEAD, src_reg)
       || REG_N_SETS (src_no) != 1)
     return;
-  for (p = PREV_INSN (insn); ! reg_set_p (src_reg, p); p = PREV_INSN (p))
+  for (p = PREV_INSN (insn); p && ! reg_set_p (src_reg, p); p = PREV_INSN (p))
     {
       if (GET_CODE (p) == CODE_LABEL || GET_CODE (p) == JUMP_INSN
 	  || (GET_CODE (p) == NOTE
@@ -698,6 +698,9 @@ optimize_reg_copy_3 (insn, dest, src)
       if (GET_RTX_CLASS (GET_CODE (p)) != 'i')
 	continue;
     }
+  if (! p)
+    return;
+
   if (! (set = single_set (p))
       || GET_CODE (SET_SRC (set)) != MEM
       || SET_DEST (set) != src_reg)


-- 
Brendan Kehoe

Web page: http://www.zen.org/~brendan/


More information about the Gcc-patches mailing list