[PATCH] Fix TBA bug in RTL expander

Eric Botcazou ebotcazou@adacore.com
Mon Nov 20 22:26:00 GMT 2006


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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: fa06-017_fsf.diff
Type: text/x-diff
Size: 861 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20061120/c5447ad9/attachment.bin>

More information about the Gcc-patches mailing list