http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58253
Bug ID: 58253 Summary: IPA-SRA creates aligned loads from unaligned memory Product: gcc Version: 4.9.0 Status: UNCONFIRMED Keywords: wrong-code Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: amylaar at gcc dot gnu.org CC: amylaar at gcc dot gnu.org, jamborm at gcc dot gnu.org, rguenth at gcc dot gnu.org Depends on: 52402 Target: epiphany-*-* +++ This bug was initially created as a clone of Bug #52402 +++ What I see on epiphany (at O2 and above, enabling SRA) for gcc.dg/torture/pr52402.c is that the call of foo.isra.0 in main is done using an aligned type: Breakpoint 5, epiphany_function_arg (cum_v=..., mode=TImode, type=0xb7c5f960, named=true) at /home/amylaar/adapteva/git/sdk/srcw/gcc/config/epiphany/epiphany.c:2177 2177 CUMULATIVE_ARGS cum = *get_cumulative_args (cum_v); (gdb) call debug_tree(type) <vector_type 0xb7c5f960 type <integer_type 0xb7bed360 int public SI size <integer_cst 0xb7bdd104 constant 32> unit size <integer_cst 0xb7bdd118 constant 4> align 32 symtab 0 alias set 3 canonical type 0xb7bed360 precision 32 min <integer_cst 0xb7bdd2f8 -2147483648> max <integer_cst 0xb7bdd30c 2147483647> pointer_to_this <pointer_type 0xb7beda80>> TI size <integer_cst 0xb7bdd460 type <integer_type 0xb7bed060 bitsizetype> constant 128> unit size <integer_cst 0xb7bdd474 type <integer_type 0xb7bed000 sizetype> constant 16> align 64 symtab 0 alias set 3 canonical type 0xb7c5f960 nunits 4 context <translation_unit_decl 0xb7bf2e58 D.1323> pointer_to_this <pointer_type 0xb7c5fba0>> but when the callee foo.isra.0 was compiled before, it got allegedly passed an unaligned type: Breakpoint 5, epiphany_function_arg (cum_v=..., mode=TImode, type=0xb7c6f300, named=true) at /home/amylaar/adapteva/git/sdk/srcw/gcc/config/epiphany/epiphany.c:2177 2177 CUMULATIVE_ARGS cum = *get_cumulative_args (cum_v); (gdb) call debug_tree(type) <vector_type 0xb7c6f300 v4si type <integer_type 0xb7bed360 int public SI size <integer_cst 0xb7bdd104 constant 32> unit size <integer_cst 0xb7bdd118 constant 4> align 32 symtab 0 alias set 3 canonical type 0xb7bed360 precision 32 min <integer_cst 0xb7bdd2f8 -2147483648> max <integer_cst 0xb7bdd30c 2147483647> pointer_to_this <pointer_type 0xb7beda80>> TI size <integer_cst 0xb7bdd460 type <integer_type 0xb7bed060 bitsizetype> constant 128> unit size <integer_cst 0xb7bdd474 type <integer_type 0xb7bed000 sizetype> constant 16> align 8 symtab 0 alias set -1 canonical type 0xb7c5f960 nunits 4 context <translation_unit_decl 0xb7bf2e58 D.1323>> When passing 64-bit aligned types, the epiphany ABI uses register pair(s) to enable double load-store, thus in this case where r0 has already been used, the argument starts at r2; in the less-aligned case, it starts at r1. Thus, the callee expects the argument in a different place than where it has been put by the caller. Richard Biener: :So you say that on Epiphany the ABI of the function depends on the actual :argument alignment? And this alignment is taken from the _argument_, not :the type of the function prototype? Note, these are the types as passed to TARGET_FUNCTION_ARG. The original function prototype is no longer in the picture because the ipa optimizers have used a cloned/specialized function instead, and the types used when constructing the call are not the same as when generating the callee.