This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH]: PR 10592 caller-save incorrectly handles a reloaded SET_DEST operand


This is a transcript of the analysis in the bug report...

 The problem we have here comes from the use of caller-save register 
 allocation and the failure to allocate a register to a pseudo that is 
 equivalent to a memory location that is derived from a caller-saved 
 register value.  Specifically, we have the sequence prior to reload of
 
 (call_insn:HI 249 227 326 2 0x4067c5d8 (parallel [
             (set (reg:SI 0 r0)
                 (call (mem:SI (symbol_ref:SI ("strncpy") <function_decl 
 0x40330af8 strncpy>) [0 S4 A32])
                     (const_int 0 [0x0])))
             (use (const_int 0 [0x0]))
             (clobber (reg:SI 14 lr))
         ]) 190 {*call_value_symbol} (insn_list:REG_DEP_ANTI 76 (insn_list 
 248 (insn_list 247 (insn_list 246 (insn_list:REG_DEP_ANTI 30 
 (insn_list:REG_DEP_ANTI 172 (insn_list 210 (insn_list:REG_DEP_ANTI 75 
 (insn_list:REG_DEP_ANTI 74 (insn_list 47 (insn_list 227 (nil))))))))))))
     (expr_list:REG_DEAD (reg:SI 1 r1 [ pName ])
         (expr_list:REG_DEAD (reg:SI 2 r2)
             (expr_list:REG_UNUSED (reg:SI 0 r0)
                 (expr_list:REG_UNUSED (reg:SI 14 lr)
                     (expr_list:REG_EH_REGION (const_int 0 [0x0])
                         (nil))))))
     (expr_list (use (reg:SI 2 r2))
         (expr_list (use (reg:SI 1 r1 [ pName ]))
             (expr_list (use (reg:SI 0 r0))
                 (nil)))))
 
 (insn:HI 326 249 331 2 0x40658dc0 (set (reg:SI 98)
         (plus:SI (reg/v:SI 49 [ base ])
             (const_int 156 [0x9c]))) 4 {*arm_addsi3} (insn_list 4 
 (insn_list:REG_DEP_ANTI 249 (nil)))
     (expr_list:REG_EQUIV (mem/s:SI (plus:SI (reg/v/u/f:SI 48 [ this ])
                 (const_int 540 [0x21c])) [39 <variable>.pValue3+0 S4 A32])
         (nil)))
 
 Note that pseudo 98 has a REG_EQUIV of mem(plus (r48, 540)) 
 
 Now global-alloc assigns r48 to the call-clobbered register r12, but 
 spills r98 back into its reg_equiv location.  When 
save_call_clobbered_res
 runs, therefore, r12 is stored to the stack before the call insn, but 
when
 scanning r326 mark_referenced_regs ignores the SET_DEST in insn 326 
 because it is a REG:
 
   if (code == SET || code == CLOBBER)
     {
       x = SET_DEST (x);
       code = GET_CODE (x);
       if (code == REG || code == PC || code == CC0
           || (code == SUBREG && GET_CODE (SUBREG_REG (x)) == REG
               /* If we're setting only part of a multi-word register,
                  we shall mark it as referenced, because the words
                  that are not being set should be restored.  */
               && ((GET_MODE_SIZE (GET_MODE (x))
                    >= GET_MODE_SIZE (GET_MODE (SUBREG_REG (x))))
                   || (GET_MODE_SIZE (GET_MODE (SUBREG_REG (x)))
                       <= UNITS_PER_WORD))))
         return;
 
 We thus end up with the sequence of instructions
 
 	str	ip, [frame+xxx]
 	call	strncpy
 	add	tmp, r9, #156
 	str	tmp, [ip+540]	// ip not restored first
 
 
 I think the fix may be to make mark_referenced_regs only return if REG is 
 a hard register (similarly for SUBREG).
 
Fixed with:

2003-12-17  Richard Earnshaw  <rearnsha@arm.com>

	PR optimization/10592
	* caller-save.c (mark_referenced_regs): Don't short-circuit a reg
	or subreg in SET_DEST if it isn't a hard register.


Attachment: caller-save.patch
Description: caller-save.patch


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]