diff mbox

Add missed adjustment to label_nuses in reload.

Message ID 4F045D38.7060204@arm.com
State New
Headers show

Commit Message

Marcus Shawcroft Jan. 4, 2012, 2:07 p.m. UTC
Reload (find_reloads) has code that can replace a register with a 
label_ref when presented with RTL of the form:

(set (reg) (reg) (notes (rtx_equal (label_ref)))

Label references are initially counted in jump.c:mark_all_labels() and 
friends. This code traverses the RTL and counts each observed label_ref. 
The code inserts REG_LABEL_OPERAND or REG_LABEL_TARGET as appropriate. 
Notes are not traversed therefore the (rtx_equal (label_ref)) shown 
above is not treated as a reference.

Instruction deletion, in cfgrtl.c:delete_insn() does not re-traverse the 
RTL, The code traverses only the notes looking for REG_LABEL_OPERAND and 
REG_TARGET_OPERAND notes in order to count down the label_nuses field.

The code in reload.c:find_reloads() converts a register to a label_ref 
and inserts the associated REG_LABEL_OPERAND but does not adjust 
label_nuses, this may result in the inappropriate deletion of a live label.

This issue was discovered during the development of the ARM aarch64 gcc 
backend and results in an ICE due to deletion of a live jump table.

The issue has not been re-created on another target. The proposed patch 
has been regressed on x86 (and aarch64).

Proposed ChangeLog entry below, patch attached:

2012-01-04  Marcus Shawcroft  <marcus.shawcroft@arm.com>

	* reload.c (find_reloads): Adjust LABEL_NUSES on
	  REG_LABEL_OPERAND insertion.

/Marcus

Comments

Jeff Law Jan. 4, 2012, 7:21 p.m. UTC | #1
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 01/04/12 07:07, Marcus Shawcroft wrote:
> Reload (find_reloads) has code that can replace a register with a 
> label_ref when presented with RTL of the form:
> 
> (set (reg) (reg) (notes (rtx_equal (label_ref)))
> 
> Label references are initially counted in jump.c:mark_all_labels()
> and friends. This code traverses the RTL and counts each observed
> label_ref. The code inserts REG_LABEL_OPERAND or REG_LABEL_TARGET
> as appropriate. Notes are not traversed therefore the (rtx_equal
> (label_ref)) shown above is not treated as a reference.
> 
> Instruction deletion, in cfgrtl.c:delete_insn() does not
> re-traverse the RTL, The code traverses only the notes looking for
> REG_LABEL_OPERAND and REG_TARGET_OPERAND notes in order to count
> down the label_nuses field.
> 
> The code in reload.c:find_reloads() converts a register to a
> label_ref and inserts the associated REG_LABEL_OPERAND but does not
> adjust label_nuses, this may result in the inappropriate deletion
> of a live label.
> 
> This issue was discovered during the development of the ARM aarch64
> gcc backend and results in an ICE due to deletion of a live jump
> table.
> 
> The issue has not been re-created on another target. The proposed
> patch has been regressed on x86 (and aarch64).
> 
> Proposed ChangeLog entry below, patch attached:
> 
> 2012-01-04  Marcus Shawcroft  <marcus.shawcroft@arm.com>
> 
> * reload.c (find_reloads): Adjust LABEL_NUSES on REG_LABEL_OPERAND
> insertion.
Approved after you fix some minor fomatting nits. Your code has:

++ LABEL_NUSES(XEXP (substitution, 0));

The line should be:

++LABEL_NUSES (XEXP (substitution, 0));

No space between autoincrement operator and its operand.
Space before the open paren of the XEXP

Thanks,
Jeff
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQEcBAEBAgAGBQJPBKbUAAoJEBRtltQi2kC7wMcH/3UMAgEj7d7nXwPfuMaZSl84
6lme27/Ox8LxsqFYrqnR3QKdU3/B0aZmS/CVzrPQQoC/xTSy1Y0aPTyBx3+p7tqa
tVkcCl/PgjhNCFROLe0n7YZ9FoS3el8CyC7Yha9Z0C17fiv6tetCElijiSluOxB0
OeOxgzE1qekwsQSZs6ZEiTpxGQJ/POqlhHHC9ILZV+iEUfGTAHW1EdKTupsLx9Q1
o26gXu6mTGsLEuSLkdKLkPJ+1+wV4h3291Ec41FC8Eo1E4fB9H82vBXxvy8fvO35
VnHXuyLrr7LMN0REDiQ6Oz8yh52Un/76l5/+kjFBPdQ6RzNPFsu8qwboNRirWSI=
=fNJ9
-----END PGP SIGNATURE-----
diff mbox

Patch

diff --git a/gcc/reload.c b/gcc/reload.c
index 53dcd2d..206fb36 100644
--- a/gcc/reload.c
+++ b/gcc/reload.c
@@ -4212,7 +4212,12 @@  find_reloads (rtx insn, int replace, int ind_levels, int live_known,
 	      && (!JUMP_P (insn)
 		  || !label_is_jump_target_p (XEXP (substitution, 0),
 					      insn)))
-	    add_reg_note (insn, REG_LABEL_OPERAND, XEXP (substitution, 0));
+	    {
+	      add_reg_note (insn, REG_LABEL_OPERAND, XEXP (substitution, 0));
+	      if (LABEL_P (XEXP (substitution, 0)))
+		++ LABEL_NUSES(XEXP (substitution, 0));
+	    }
+
 	}
       else
 	retval |= (substed_operand[i] != *recog_data.operand_loc[i]);