aboutsummaryrefslogtreecommitdiff
path: root/gcc/lra.c
diff options
context:
space:
mode:
authorAndrew Stubbs <ams@codesourcery.com>2018-12-14 11:49:28 +0000
committerAndrew Stubbs <ams@gcc.gnu.org>2018-12-14 11:49:28 +0000
commitf961ec70ee07768f87e9e2ce2b3cac4160fd065e (patch)
tree126a1387fed88b90136c7fc4ca7555804788d726 /gcc/lra.c
parent65e0a92b2353927e50a26a3a0628a36aebc85b40 (diff)
downloadgcc-f961ec70ee07768f87e9e2ce2b3cac4160fd065e.zip
gcc-f961ec70ee07768f87e9e2ce2b3cac4160fd065e.tar.gz
gcc-f961ec70ee07768f87e9e2ce2b3cac4160fd065e.tar.bz2
Fix LRA bug
This patch fixes an ICE building libgfortran/random.c. The problem was an adddi3 instruction that had an eliminable frame pointer. GCN adddi3 includes a match_scratch, which LRA substitutes with a REG, and checks if it can be converted back to a scratch afterwards. In the meantime, the add was converted to a move, meaning that the instruction pattern completely changed, thus causing a segfault when the instruction is revisited in restore_scratches. 2018-12-14 Andrew Stubbs <ams@codesourcery.com> gcc/ * gcc/lra-int.h (lra_register_new_scratch_op): Add third parameter. * gcc/lra-remat.c (update_scratch_ops): Pass icode to lra_register_new_scratch_op. * gcc/lra.c (struct sloc): Add icode field. (lra_register_new_scratch_op): Add icode parameter. Use icode to skip insns that have changed beyond recognition. From-SVN: r267132
Diffstat (limited to 'gcc/lra.c')
-rw-r--r--gcc/lra.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/gcc/lra.c b/gcc/lra.c
index 537b4ae..ae82b60 100644
--- a/gcc/lra.c
+++ b/gcc/lra.c
@@ -2026,6 +2026,7 @@ struct sloc
{
rtx_insn *insn; /* Insn where the scratch was. */
int nop; /* Number of the operand which was a scratch. */
+ int icode; /* Original icode from which scratch was removed. */
};
typedef struct sloc *sloc_t;
@@ -2057,7 +2058,7 @@ lra_former_scratch_operand_p (rtx_insn *insn, int nop)
/* Register operand NOP in INSN as a former scratch. It will be
changed to scratch back, if it is necessary, at the LRA end. */
void
-lra_register_new_scratch_op (rtx_insn *insn, int nop)
+lra_register_new_scratch_op (rtx_insn *insn, int nop, int icode)
{
lra_insn_recog_data_t id = lra_get_insn_recog_data (insn);
rtx op = *id->operand_loc[nop];
@@ -2065,6 +2066,7 @@ lra_register_new_scratch_op (rtx_insn *insn, int nop)
lra_assert (REG_P (op));
loc->insn = insn;
loc->nop = nop;
+ loc->icode = icode;
scratches.safe_push (loc);
bitmap_set_bit (&scratch_bitmap, REGNO (op));
bitmap_set_bit (&scratch_operand_bitmap,
@@ -2102,7 +2104,7 @@ remove_scratches (void)
*id->operand_loc[i] = reg
= lra_create_new_reg (static_id->operand[i].mode,
*id->operand_loc[i], ALL_REGS, NULL);
- lra_register_new_scratch_op (insn, i);
+ lra_register_new_scratch_op (insn, i, id->icode);
if (lra_dump_file != NULL)
fprintf (lra_dump_file,
"Removing SCRATCH in insn #%u (nop %d)\n",
@@ -2136,6 +2138,12 @@ restore_scratches (void)
last = loc->insn;
id = lra_get_insn_recog_data (last);
}
+ if (loc->icode != id->icode)
+ {
+ /* The icode doesn't match, which means the insn has been modified
+ (e.g. register elimination). The scratch cannot be restored. */
+ continue;
+ }
if (REG_P (*id->operand_loc[loc->nop])
&& ((regno = REGNO (*id->operand_loc[loc->nop]))
>= FIRST_PSEUDO_REGISTER)