[Bug tree-optimization/49444] IV-OPTs changes an unaligned loads into aligned loads incorrectly
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=49444 bin.cheng amker.cheng at gmail dot com changed: What|Removed |Added CC||amker.cheng at gmail dot com --- Comment #8 from bin.cheng amker.cheng at gmail dot com --- This should be fixed on trunk now. At least for r211210 and r214864. For Andrew's test, the generated mips assmbly for kernel loop is as below. $L3: lwl$5,1($16) lwl$4,5($16) lwl$3,9($16) lwr$5,4($16) lwr$4,8($16) lwr$3,12($16) lw$2,%gp_rel(ss)($28) addiu$16,$16,13 sw$5,0($2) sw$4,4($2) jalg sw$3,8($2) bne$16,$17,$L3 move$2,$0 For Richard's case (with an explicit conversion when calling foo), the generated mips assembly is as below. foo: .frame$sp,0,$31# vars= 0, regs= 0/0, args= 0, gp= 0 .mask0x,0 .fmask0x,0 .setnoreorder .setnomacro lwl$2,0($4) nop lwr$2,3($4) j$31 nop .setmacro .setreorder .endfoo .sizefoo, .-foo Apparently, lwl/lwr are generated for unalgned memory access. Thanks, bin
[Bug tree-optimization/49444] IV-OPTs changes an unaligned loads into aligned loads incorrectly
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=49444 --- Comment #9 from Richard Biener rguenth at gcc dot gnu.org --- Thus dup of PR61320?
[Bug tree-optimization/49444] IV-OPTs changes an unaligned loads into aligned loads incorrectly
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=49444 Andrew Pinski pinskia at gcc dot gnu.org changed: What|Removed |Added Status|NEW |RESOLVED Resolution|--- |DUPLICATE --- Comment #10 from Andrew Pinski pinskia at gcc dot gnu.org --- (In reply to Richard Biener from comment #9) Thus dup of PR61320? Yes. *** This bug has been marked as a duplicate of bug 61320 ***
[Bug tree-optimization/49444] IV-OPTs changes an unaligned loads into aligned loads incorrectly
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49444 --- Comment #6 from Andrew Pinski pinskia at gcc dot gnu.org 2011-12-16 00:33:10 UTC --- This is the patch which I ended up with: Index: tree-ssa-loop-ivopts.c === --- tree-ssa-loop-ivopts.c(revision 61449) +++ tree-ssa-loop-ivopts.c(revision 61858) @@ -6066,6 +6066,7 @@ rewrite_use_address (struct ivopts_data tree base_hint = NULL_TREE; tree ref, iv; bool ok; + tree type; adjust_iv_update_pos (cand, use); ok = get_computation_aff (data-current_loop, use, cand, use-stmt, aff); @@ -6087,7 +6088,13 @@ rewrite_use_address (struct ivopts_data base_hint = var_at_stmt (data-current_loop, cand, use-stmt); iv = var_at_stmt (data-current_loop, cand, use-stmt); - ref = create_mem_ref (bsi, TREE_TYPE (*use-op_p), aff, + type = TREE_TYPE (*use-op_p); + if (TREE_CODE (*use-op_p) == COMPONENT_REF) +{ + unsigned align = DECL_ALIGN (TREE_OPERAND (*use-op_p, 1)); + type = build_aligned_type (type, align); +} + ref = create_mem_ref (bsi, type, aff, reference_alias_ptr_type (*use-op_p), iv, base_hint, data-speed); copy_ref_info (ref, *use-op_p); --- CUT --- I also implemented on mips the misalignedmove patterns too.
[Bug tree-optimization/49444] IV-OPTs changes an unaligned loads into aligned loads incorrectly
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49444 Eric Botcazou ebotcazou at gcc dot gnu.org changed: What|Removed |Added Status|UNCONFIRMED |NEW Last reconfirmed||2011-12-16 CC||ebotcazou at gcc dot ||gnu.org Ever Confirmed|0 |1 --- Comment #7 from Eric Botcazou ebotcazou at gcc dot gnu.org 2011-12-16 07:46:00 UTC --- Currently this fails and the load from p[i].s is turned into an aligned load. This is an old issue with IVOPTS which is supposed to have been fixed long ago by means of the may_be_unaligned_p predicate. Why is it apparently bypassed here?
[Bug tree-optimization/49444] IV-OPTs changes an unaligned loads into aligned loads incorrectly
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49444 --- Comment #4 from Richard Guenther rguenth at gcc dot gnu.org 2011-06-17 09:06:22 UTC --- (In reply to comment #3) Something like this: Index: tree-ssa-loop-ivopts.c === --- tree-ssa-loop-ivopts.c(revision 61384) +++ tree-ssa-loop-ivopts.c(working copy) @@ -6066,6 +6066,8 @@ rewrite_use_address (struct ivopts_data tree base_hint = NULL_TREE; tree ref, iv; bool ok; + unsigned align; + tree type; adjust_iv_update_pos (cand, use); ok = get_computation_aff (data-current_loop, use, cand, use-stmt, aff); @@ -6087,7 +6089,10 @@ rewrite_use_address (struct ivopts_data base_hint = var_at_stmt (data-current_loop, cand, use-stmt); iv = var_at_stmt (data-current_loop, cand, use-stmt); - ref = create_mem_ref (bsi, TREE_TYPE (*use-op_p), aff, + align = get_object_alignment (*use-op_p, BIGGEST_ALIGNMENT); + type = TREE_TYPE (*use-op_p); + type = build_aligned_type (type, align); + ref = create_mem_ref (bsi, type, aff, reference_alias_ptr_type (*use-op_p), iv, base_hint, data-speed); copy_ref_info (ref, *use-op_p); Well, that will then still run into the indirect-ref issue as the expansion for target-mem-refs and mem-refs works the same way. Only targets that support movmisalign will generate unaligned loads (which targets currently only define for vector modes I think).
[Bug tree-optimization/49444] IV-OPTs changes an unaligned loads into aligned loads incorrectly
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49444 --- Comment #5 from Andrew Pinski pinskia at gcc dot gnu.org 2011-06-17 16:25:04 UTC --- (In reply to comment #4) Well, that will then still run into the indirect-ref issue as the expansion for target-mem-refs and mem-refs works the same way. Only targets that support movmisalign will generate unaligned loads (which targets currently only define for vector modes I think). It works in the case which I reported because the mode is BLKmode. I tried to get a testcase that would still fail after this but I could not find one as IV-OPTs would use a-b for that still. Thanks, Andrew Pinski
[Bug tree-optimization/49444] IV-OPTs changes an unaligned loads into aligned loads incorrectly
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49444 --- Comment #1 from Richard Guenther rguenth at gcc dot gnu.org 2011-06-16 20:08:43 UTC --- Well, I'm 100% sure this is just the age-old bug that GCC can't expand misaligned indirect-refs (or nowadays mem-refs and target-mem-refs) on strict-align targets properly. Try the following on any GCC version: typedef int myint __attribute__((aligned(1))); int foo(myint *p) { return *p; } int main() { char c[5] = {}; return foo(c[1]); } it'll fault on any strict-align target since forever. Now it would indeed be nice if _finally_ somebody would go and fix that ... Dup of
[Bug tree-optimization/49444] IV-OPTs changes an unaligned loads into aligned loads incorrectly
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49444 --- Comment #2 from Andrew Pinski pinskia at gcc dot gnu.org 2011-06-16 20:16:09 UTC --- (In reply to comment #1) Well, I'm 100% sure this is just the age-old bug that GCC can't expand misaligned indirect-refs (or nowadays mem-refs and target-mem-refs) on strict-align targets properly. This has nothing to do with the misalgined indirect-ref issue as it works when IV-opts is disabled.
[Bug tree-optimization/49444] IV-OPTs changes an unaligned loads into aligned loads incorrectly
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49444 --- Comment #3 from Andrew Pinski pinskia at gcc dot gnu.org 2011-06-16 21:10:18 UTC --- Something like this: Index: tree-ssa-loop-ivopts.c === --- tree-ssa-loop-ivopts.c(revision 61384) +++ tree-ssa-loop-ivopts.c(working copy) @@ -6066,6 +6066,8 @@ rewrite_use_address (struct ivopts_data tree base_hint = NULL_TREE; tree ref, iv; bool ok; + unsigned align; + tree type; adjust_iv_update_pos (cand, use); ok = get_computation_aff (data-current_loop, use, cand, use-stmt, aff); @@ -6087,7 +6089,10 @@ rewrite_use_address (struct ivopts_data base_hint = var_at_stmt (data-current_loop, cand, use-stmt); iv = var_at_stmt (data-current_loop, cand, use-stmt); - ref = create_mem_ref (bsi, TREE_TYPE (*use-op_p), aff, + align = get_object_alignment (*use-op_p, BIGGEST_ALIGNMENT); + type = TREE_TYPE (*use-op_p); + type = build_aligned_type (type, align); + ref = create_mem_ref (bsi, type, aff, reference_alias_ptr_type (*use-op_p), iv, base_hint, data-speed); copy_ref_info (ref, *use-op_p);