http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47893
--- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> 2011-02-25 16:06:14 UTC --- I guess not including the space added in add_frame_space by the assign_stack_local_1 call in temp_slot's size/full_size, while it would be easy to do (just walk the beginning of the frame_space list looking for slots that overlap with what we'd like to include in size/full_size), would result in too big stack wastage (e.g. in the given testcase suddenly the fn7 and fn2 return slot couldn't be shared, even when it isn't clear if something would actually like to use it or not). Similarly not queuing anything into frame_space lists when assign_stack_local is called from within assign_stack_temp_for_type would kill most of the savings Bernds' original patch had. Perhaps we could add pointers from temp_slots to frame_space list and back, when deciding to reuse an earlier temp_slot in assign_stack_temp_for_type we'd walk the referenced list and remove frame_space entries that overlap it and similarly when assign_stack_local_1 decides it wants to use a frame_space we'd decrease size/full_size of the temp_slot that overlaps it. We could of course try to prefer frame_space slots that don't overlap any temp_slots. Or perhaps don't try to use frame_space slots until virtuals_instantiated, assuming assign_stack_temp_for_type/assign_stack_temp/assign_temp aren't called after virtuals_instantiated is set, then we could just have links from temp_slots to frame_space and not vice versa. OT, on the other side, perhaps add_frame_space could be called e.g. for the padding inserted in expand_used_vars by: /* If the target requires that FRAME_OFFSET be aligned, do it. */ if (STACK_ALIGNMENT_NEEDED) { HOST_WIDE_INT align = PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT; if (!FRAME_GROWS_DOWNWARD) frame_offset += align - 1; frame_offset &= -align; } and perhaps also without -fstack-protector for inter-variable padding (alloc_stack_frame_space - with -fstack-protector it would be a security risk to place spills above any arrays). But this OT isn't stage 4 matter.