From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2610 invoked by alias); 6 Apr 2017 12:40:11 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 1656 invoked by uid 89); 6 Apr 2017 12:40:10 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.1 required=5.0 tests=BAYES_00,GIT_PATCH_2,GIT_PATCH_3,KAM_ASCII_DIVIDERS,RP_MATCHES_RCVD,SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mx2.suse.de Received: from mx2.suse.de (HELO mx2.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 06 Apr 2017 12:40:09 +0000 Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 687F5ACE9 for ; Thu, 6 Apr 2017 12:40:08 +0000 (UTC) Date: Thu, 06 Apr 2017 12:40:00 -0000 From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix PR80334 Message-ID: User-Agent: Alpine 2.20 (LSU 67 2015-01-07) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-SW-Source: 2017-04/txt/msg00282.txt.bz2 The following patch makes sure to preserve (mis-)alignment of memory references when IVOPTs generates TARGET_MEM_REFs for them. Bootstrapped on x86_64-unknown-linux-gnu, testing in progress. Richard. 2017-04-06 Richard Biener PR tree-optimization/80334 * tree-ssa-loop-ivopts.c (rewrite_use_address): Properly preserve alignment of accesses. * g++.dg/torture/pr80334.C: New testcase. Index: gcc/tree-ssa-loop-ivopts.c =================================================================== --- gcc/tree-ssa-loop-ivopts.c (revision 246724) +++ gcc/tree-ssa-loop-ivopts.c (working copy) @@ -7396,7 +7396,11 @@ 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, + tree type = TREE_TYPE (*use->op_p); + unsigned int align = get_object_alignment (*use->op_p); + if (align != TYPE_ALIGN (type)) + 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); Index: gcc/testsuite/g++.dg/torture/pr80334.C =================================================================== --- gcc/testsuite/g++.dg/torture/pr80334.C (nonexistent) +++ gcc/testsuite/g++.dg/torture/pr80334.C (working copy) @@ -0,0 +1,18 @@ +// { dg-do run } + +struct A { alignas(16) char c; }; +struct B { A unpacked; char d; } __attribute__((packed)); + +char x; + +int +main() +{ + alignas(16) B b[3]; + for (int i = 0; i < 3; i++) b[i].unpacked.c = 'a' + i; + for (int i = 0; i < 3; i++) + { + auto a = new A(b[i].unpacked); + x = a->c; + } +}