From patchwork Mon Mar 12 14:09:02 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Jambor X-Patchwork-Id: 146109 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 137DEB6FA3 for ; Tue, 13 Mar 2012 01:13:54 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1332166435; h=Comment: DomainKey-Signature:Received:Received:Received:Received: Resent-From:Resent-Date:Resent-Message-ID:Resent-To:Message-Id: User-Agent:Date:From:To:Cc:Subject:References: Content-Disposition:Mailing-List:Precedence:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:Sender: Delivered-To; bh=4QMEn0AokgNpjkGMrRdMXxG0w9Q=; b=dRgl7vsXGvz6Scd UB3LqwqdpOURXPAZ8KrOi18Z//A6wF0TRbJ6T53e8lBaJxPbyns7hpkaflsAZSkn Isg7/VlJedpzpqjIyhZCAyNqndRtB0odMU1WQBBE9o0SZqOWQ0EFS94VyAXxYi1A xkKsCG9/v1Dyz+5GdirEQWaOgXUs= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Resent-From:Resent-Date:Resent-Message-ID:Resent-To:Message-Id:User-Agent:Date:From:To:Cc:Subject:References:Content-Disposition:X-IsSubscribed:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=b3tIehT2XYjmvvQu7dQq0sTtMP3Bw6f/b8gJKRuf8UC21BdcqJxwBcnPRD5Jqy 0zH7NmmHydbOEQBwrTcIEbXBZHDUtI/UnLp+br6WQxWH3FdD8an8MrrflAdmWw/M 8gViUt6x74V/kvilCJrnkZVPaVKyZZ6YBzqEJDjKyA5/M=; Received: (qmail 13316 invoked by alias); 12 Mar 2012 14:13:42 -0000 Received: (qmail 13270 invoked by uid 22791); 12 Mar 2012 14:13:39 -0000 X-SWARE-Spam-Status: No, hits=-5.8 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI X-Spam-Check-By: sourceware.org Received: from cantor2.suse.de (HELO mx2.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 12 Mar 2012 14:13:20 +0000 Received: from relay1.suse.de (unknown [195.135.220.254]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx2.suse.de (Postfix) with ESMTP id 3DFFE90B1D for ; Mon, 12 Mar 2012 15:13:19 +0100 (CET) Resent-From: Martin Jambor Resent-Date: Mon, 12 Mar 2012 15:13:18 +0100 Resent-Message-ID: <20120312141318.GB2177@virgil.arch.suse.de> Resent-To: GCC Patches Message-Id: <20120312140917.965987328@virgil.suse.cz> User-Agent: quilt/0.48-20.3.1 Date: Mon, 12 Mar 2012 15:09:02 +0100 From: Martin Jambor To: GCC Patches Cc: Richard Guenther Subject: [PATCH 1/3] Misaligned top level MEM_REFs on LHS of assignments References: <20120312140901.004541946@virgil.suse.cz> Content-Disposition: inline; filename=misaligned_write-first.diff X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Hi, this patch has not changed since I posted it the last time (http://gcc.gnu.org/ml/gcc-patches/2012-02/msg01375.html) except for a fixed formatting of a comment. It has been already approved by Richi (http://gcc.gnu.org/ml/gcc-patches/2012-02/msg01389.html) and I intend to commit it this week even if the other patches still undergo review. Thanks, Martin 2012-03-08 Martin Jambor * expr.c (expand_assignment): Handle misaligned scalar writes to memory through top-level MEM_REFs by calling store_bit_field. * testsuite/gcc.dg/misaligned-expand-2.c: New test. Index: src/gcc/expr.c =================================================================== --- src.orig/gcc/expr.c +++ src/gcc/expr.c @@ -4593,10 +4593,12 @@ expand_assignment (tree to, tree from, b if ((TREE_CODE (to) == MEM_REF || TREE_CODE (to) == TARGET_MEM_REF) && mode != BLKmode + && !mem_ref_refers_to_non_mem_p (to) && ((align = get_object_or_type_alignment (to)) < GET_MODE_ALIGNMENT (mode)) - && ((icode = optab_handler (movmisalign_optab, mode)) - != CODE_FOR_nothing)) + && (((icode = optab_handler (movmisalign_optab, mode)) + != CODE_FOR_nothing) + || SLOW_UNALIGNED_ACCESS (mode, align))) { addr_space_t as = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (to, 0)))); @@ -4639,11 +4641,17 @@ expand_assignment (tree to, tree from, b if (TREE_THIS_VOLATILE (to)) MEM_VOLATILE_P (mem) = 1; - create_fixed_operand (&ops[0], mem); - create_input_operand (&ops[1], reg, mode); - /* The movmisalign pattern cannot fail, else the assignment would - silently be omitted. */ - expand_insn (icode, 2, ops); + if (icode != CODE_FOR_nothing) + { + create_fixed_operand (&ops[0], mem); + create_input_operand (&ops[1], reg, mode); + /* The movmisalign pattern cannot fail, else the assignment + would silently be omitted. */ + expand_insn (icode, 2, ops); + } + else + store_bit_field (mem, GET_MODE_BITSIZE (mode), + 0, 0, 0, mode, reg); return; } Index: src/gcc/testsuite/gcc.dg/misaligned-expand-2.c =================================================================== --- /dev/null +++ src/gcc/testsuite/gcc.dg/misaligned-expand-2.c @@ -0,0 +1,42 @@ +/* Test that expand can generate correct stores to misaligned data even on + strict alignment platforms. */ + +/* { dg-do run } */ +/* { dg-options "-O0" } */ + +extern void abort (); + +typedef unsigned int myint __attribute__((aligned(1))); + +void +foo (myint *p, unsigned int i) +{ + *p = i; +} + +#define cst 0xdeadbeef +#define NUM 8 + +struct blah +{ + char c; + myint i[NUM]; +}; + +struct blah g; + +#define cst 0xdeadbeef + +int +main (int argc, char **argv) +{ + int k; + + for (k = 0; k < NUM; k++) + { + foo (&g.i[k], cst); + if (g.i[k] != cst) + abort (); + } + return 0; +}