optimization/10592: [arm] caller-save incorrectly handles a reloaded SET_DEST operand
Richard Earnshaw
rearnsha@arm.com
Fri May 2 13:45:00 GMT 2003
[Jeff, I've put you on CC because you appear to be the original author of
the relevant code (back in Oct 98).]
Some more detailed analysis...
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).
Jeff, any thoughts?
R.
More information about the Gcc-bugs
mailing list