This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Fix TBA bug in RTL expander
- From: Eric Botcazou <ebotcazou at adacore dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Mon, 20 Nov 2006 23:05:56 +0100
- Subject: [PATCH] Fix TBA bug in RTL expander
Hi,
We recently run into a wrong code generation on IA-64/Linux with a modified
4.1-based compiler (unfortunately no testcase for FSF compilers).
In expand_expr_real_1:
/* If the result type is BLKmode, store the data into a temporary
of the appropriate type, but with the mode corresponding to the
mode for the data we have (op0's mode). It's tempting to make
this a constant type, since we know it's only being stored once,
but that can cause problems if we are taking the address of this
COMPONENT_REF because the MEM of any reference via that address
will have flags corresponding to the type, which will not
necessarily be constant. */
if (mode == BLKmode)
{
rtx new
= assign_stack_temp_for_type
(ext_mode, GET_MODE_BITSIZE (ext_mode), 0, type);
emit_move_insn (new, op0);
op0 = copy_rtx (new);
PUT_MODE (op0, BLKmode);
set_mem_attributes (op0, exp, 1);
}
(gdb) p debug_rtx(op0)
(reg:TI 346 [ D.518 ])
$46 = void
(gdb) p mode
$47 = BLKmode
(gdb) p ext_mode
$48 = TImode
Then 'new' is created as:
(gdb) p debug_rtx(new)
(mem/s/c:TI (plus:DI (reg/f:DI 335 virtual-stack-vars)
(const_int 32 [0x20])) [3 S16 A128])
and finally 'op' is returned as:
(gdb) p debug_rtx(op0)
(mem/s/j:BLK (plus:DI (reg/f:DI 335 virtual-stack-vars)
(const_int 32 [0x20])) [4 D.518.F+0 S16 A128])
but alias sets 3 and 4 don't conflict so the scheduler will happily swap the 2
memory accesses.
The problem is the first memory access: component_uses_parent_alias_set
returns 1 for the expression so the stack slot cannot merely use the alias
set of the type. Hence the following fix. The drawback is that the slot
cannot be subsequently reused, but I don't think using assign_stack_temp is
safe here because of the call to set_mem_attributes just below.
Bootstrapped/regtested on x86_64-suse-linux. OK for mainline?
2006-11-20 Eric Botcazou <ebotcazou@adacore.com>
* expr.c (expand_expr_real_1) <normal_inner_ref>: If a temporary
is made and the reference doesn't use the alias set of its type,
do not create the temporary using that type.
:ADDPATCH RTL expander:
--
Eric Botcazou
Index: expr.c
===================================================================
--- expr.c (revision 119010)
+++ expr.c (working copy)
@@ -7605,9 +7605,18 @@ expand_expr_real_1 (tree exp, rtx target
necessarily be constant. */
if (mode == BLKmode)
{
- rtx new
- = assign_stack_temp_for_type
- (ext_mode, GET_MODE_BITSIZE (ext_mode), 0, type);
+ HOST_WIDE_INT size = GET_MODE_BITSIZE (ext_mode);
+ rtx new;
+
+ /* If the reference doesn't use the alias set of its type,
+ we cannot create the temporary using that type. */
+ if (component_uses_parent_alias_set (exp))
+ {
+ new = assign_stack_local (ext_mode, size, 0);
+ set_mem_alias_set (new, get_alias_set (exp));
+ }
+ else
+ new = assign_stack_temp_for_type (ext_mode, size, 0, type);
emit_move_insn (new, op0);
op0 = copy_rtx (new);