Hi,
One more execution failure for the avr target, this time from
gcc.c-torture/execute/bitfld-3.c.
Steps to reproduce
Enable LRA in avr.cc by removing TARGET_LRA_P hook, build with
$ make all-host && make install-host
and then
$ avr-gcc gcc/testsuite/gcc.c-torture/execute/bitfld-3.c -S -Os -mmcu=avr51
-fdump-rtl-all
When lra_update_fp2sp_elimination runs and pseudos assigned to the
FP have to be spilled to stack slots, they sometimes end up in a
slot that already has a reg with an overlapping live range. This is
because lra_reg_info[regno].live_ranges is NULL for such spilled
pseudos, and therefore when assign_stack_slot_num_and_sort_pseduos
checks if lra_intersected_live_ranges_p, it always returns false.
In the below reload dump, all the pseudos assigned to FP get
allocated to slot 0. The live ranges for some of them (r1241 for
e.g.) conflicts with r603 that was originally assigned to slot 0,
but they still end up in the same slot, causing the execution failure.
<snip>
r472: [86..87]
r473: [0..85]
...
r603: [254..655]
...
r1241: [282..283]
r1242: [268..269]
r1243: [254..255]
r1244: [238..239]
r1245: [222..223]
r1314: [88..89]
<snip>
Ranges after the compression:
r591: [0..1]
r603: [0..1]
r604: [0..1]
r605: [0..1]
r606: [0..1]
r607: [0..1]
r623: [0..1]
r624: [0..1]
r635: [0..1]
r636: [0..1]
r637: [0..1]
r638: [0..1]
r639: [0..1]
r668: [0..1]
r669: [0..1]
r670: [0..1]
r671: [0..1]
r672: [0..1]
Frame pointer can not be eliminated anymore
Spilling non-eliminable hard regs: 28 29
Spilling r472(28)
Spilling r473(28)
Spilling r589(29)
Spilling r590(28)
Spilling r704(29)
Spilling r1241(28)
Spilling r1242(28)
Spilling r1243(28)
Spilling r1244(28)
Spilling r1245(28)
Spilling r1314(28)
Slot 0 regnos (width = 0): 603 1314 1245 1244 1243 1242
1241 704 590 589 473 472
Live ranges for those pseudos is NULL because when
lra_create_live_ranges_1 ran with all_p = false, they were not in
memory (they were assigned to FP). Computing live range info for
pseudos assigned to FP fixes the problem for avr,
Is that the right fix for this problem? After applying the below
patch, the reload dump looks like this
<snip>
Ranges after the compression:
r472: [2..3]
r473: [0..1]
r589: [16..17]
r590: [16..17]
r591: [16..17]
r603: [10..17]
r604: [10..17]
r605: [10..17]
r606: [10..17]
r607: [10..17]
r623: [6..17]
r624: [6..17]
r635: [8..17]
r636: [8..17]
r637: [8..17]
r638: [8..17]
r639: [8..17]
r668: [6..17]
r669: [6..17]
r670: [6..17]
r671: [6..17]
r672: [6..17]
r704: [0..1]
r1241: [14..15]
r1242: [12..13]
r1243: [10..11]
r1244: [8..9]
r1245: [6..7]
r1314: [4..5]
Frame pointer can not be eliminated anymore
Spilling non-eliminable hard regs: 28 29
Spilling r472(28)
Spilling r473(28)
Spilling r589(29)
Spilling r590(28)
Spilling r704(29)
Spilling r1241(28)
Spilling r1242(28)
Spilling r1243(28)
Spilling r1244(28)
Spilling r1245(28)
Spilling r1314(28)
Slot 0 regnos (width = 0): 603 1314 1245 1244 473 472
Slot 1 regnos (width = 0): 604 704
...
Slot 17 regnos (width = 0): 591 1243 1242 1241
Slot 18 regnos (width = 0): 589
Slot 19 regnos (width = 0): 590
Regards
Senthil
diff --git a/gcc/lra-lives.cc b/gcc/lra-lives.cc
index f60e564da82..e4289f13979 100644
--- a/gcc/lra-lives.cc
+++ b/gcc/lra-lives.cc
@@ -250,7 +250,17 @@ update_pseudo_point (int regno, int point, enum point_type
type)
if (HARD_REGISTER_NUM_P (regno))
return;
- if (complete_info_p || lra_get_regno_hard_regno (regno) < 0)
+ /* Pseudos assigned to the FP register could potentially get spilled
+ to stack slots when lra_update_fp2sp_elimination runs, so keep
+ their live range info up to date, even if they aren't in memory
+ right now. */
+ int hard_regno = lra_get_regno_hard_regno (regno);
+ HARD_REG_SET set;
+ CLEAR_HARD_REG_SET(set);
+ add_to_hard_reg_set (&set, Pmode, HARD_FRAME_POINTER_REGNUM);
+
+ if (complete_info_p || hard_regno < 0
+ || overlaps_hard_reg_set_p (set, PSEUDO_REGNO_MODE (regno), hard_regno))
{
if (type == DEF_POINT)
{