From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7997 invoked by alias); 1 Aug 2013 16:48:38 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 7923 invoked by uid 48); 1 Aug 2013 16:48:36 -0000 From: "jamborm at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/58041] Unaligned access to arrays in packed structure Date: Thu, 01 Aug 2013 16:48:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end X-Bugzilla-Version: 4.9.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: jamborm at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: wschmidt at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2013-08/txt/msg00039.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58041 --- Comment #9 from Martin Jambor --- More specifically, if I am correct assuming that the MEM_REF replace_ref builds always accesses exactly the same memory as the previous access *expr does (and only the address is computed better) and that *expr is how the function accessed that memory before, then I think what you need is the following (untested, except that I know it seems to fix the testcase, at least the assembly looks very different :-) *** /tmp/heQHTs_gimple-ssa-strength-reduction.c Thu Aug 1 18:43:45 2013 --- gcc/gimple-ssa-strength-reduction.c Thu Aug 1 18:38:31 2013 *************** dump_incr_vec (void) *** 1728,1738 **** static void replace_ref (tree *expr, slsr_cand_t c) { ! tree add_expr = fold_build2 (POINTER_PLUS_EXPR, TREE_TYPE (c->base_expr), ! c->base_expr, c->stride); ! tree mem_ref = fold_build2 (MEM_REF, TREE_TYPE (*expr), add_expr, ! double_int_to_tree (c->cand_type, c->index)); ! /* Gimplify the base addressing expression for the new MEM_REF tree. */ gimple_stmt_iterator gsi = gsi_for_stmt (c->cand_stmt); TREE_OPERAND (mem_ref, 0) --- 1728,1748 ---- static void replace_ref (tree *expr, slsr_cand_t c) { ! tree add_expr, mem_ref, acc_type = TREE_TYPE (*expr); ! unsigned HOST_WIDE_INT misalign; ! unsigned align; ! ! get_object_alignment_1 (*expr, &align, &misalign); ! if (misalign != 0) ! align = (misalign & -misalign); ! if (align < TYPE_ALIGN (acc_type)) ! acc_type = build_aligned_type (acc_type, align); ! ! add_expr = fold_build2 (POINTER_PLUS_EXPR, TREE_TYPE (c->base_expr), ! c->base_expr, c->stride); ! mem_ref = fold_build2 (MEM_REF, acc_type, add_expr, ! double_int_to_tree (c->cand_type, c->index)); ! /* Gimplify the base addressing expression for the new MEM_REF tree. */ gimple_stmt_iterator gsi = gsi_for_stmt (c->cand_stmt); TREE_OPERAND (mem_ref, 0)