From patchwork Mon Mar 12 14:09:04 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Jambor X-Patchwork-Id: 146110 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 893DCB6FA3 for ; Tue, 13 Mar 2012 01:14:13 +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=1332166455; 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=Mji83FCKkYL9gxAuTrxwMyJn1Y0=; b=RAoLhfliFzmO+Pv 2imDT62IyyBhCwXwfU+dS5QTG5+sqC0UleyldPMVxKCbO/N35ZYj4rCxpAcrr6q3 Cj3T+bB2Vm+AmOKsF2yqUITk6dKVojDisy1xhfRiH+VO495Awh+g9RTc82SkICRc 9ZrVaMgHKiYdBTR722anxNn5Pc0I= 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=ZrDN1MqAcRP5v7AJirxXfByuQgbNGHzIDEIhKfxpWiupstQjVyiTR5ZIJE2C18 K6tpN6MGZuVk40L8qL92fAryQ+fMpxtzN7B6Ov7QobP0vLAi5Nd99uF9V5GdqUZa 9vHpPiDdAbueGNyX/kiC+OFNshyoBE44mVFYtBORU+9hE=; Received: (qmail 13384 invoked by alias); 12 Mar 2012 14:13:43 -0000 Received: (qmail 13271 invoked by uid 22791); 12 Mar 2012 14:13:39 -0000 X-SWARE-Spam-Status: No, hits=-5.7 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, TW_PL, TW_YC 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:21 +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 12DDD93DA1 for ; Mon, 12 Mar 2012 15:13:20 +0100 (CET) Resent-From: Martin Jambor Resent-Date: Mon, 12 Mar 2012 15:13:19 +0100 Resent-Message-ID: <20120312141319.GD2177@virgil.arch.suse.de> Resent-To: GCC Patches Message-Id: <20120312140918.246232556@virgil.suse.cz> User-Agent: quilt/0.48-20.3.1 Date: Mon, 12 Mar 2012 15:09:04 +0100 From: Martin Jambor To: GCC Patches Cc: Richard Guenther Subject: [PATCH 3/3] Misaligned MEM_REF reads References: <20120312140901.004541946@virgil.suse.cz> Content-Disposition: inline; filename=misaligned_read.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 is very similar to the one I posted before (http://gcc.gnu.org/ml/gcc-patches/2012-02/msg01377.html) except that it is now adjusted to sit on top of the new one before this and does not ignore complex numbers. There are more movmisalign_optab generations in this function. There is the TARGET_MEM_REF case which I intend to piggy-back on in the same way like MEM_REF is handled in this patch once it leaves the RFC stage. Finally, movmisalign_optab is also generated in VIEW_CONVERT_EXPR case but as far as I understand the code, misaligned loads are already handled there (only perhaps we should use SLOW_UNALIGNED_ACCESS instead of STRICT_ALIGNMENT there?). The three patches passed bootstrap and testing on x86_64-linux, i686-linux, usparc64-linux (without Java) and ia64-linux (without Ada). I propose to commit it after the previous patch passes review. Thanks, Martin 2012-03-09 Martin Jambor * expr.c (expand_expr_real_1): handle misaligned scalar reads from memory through MEM_REFs by calling extract_bit_field. * testsuite/gcc.dg/misaligned-expand-1.c: New test. Index: src/gcc/expr.c =================================================================== --- src.orig/gcc/expr.c +++ src/gcc/expr.c @@ -9404,21 +9404,27 @@ expand_expr_real_1 (tree exp, rtx target set_mem_addr_space (temp, as); align = get_object_or_type_alignment (exp); if (mode != BLKmode - && align < GET_MODE_ALIGNMENT (mode) - /* If the target does not have special handling for unaligned - loads of mode then it can use regular moves for them. */ - && ((icode = optab_handler (movmisalign_optab, mode)) - != CODE_FOR_nothing)) + && align < GET_MODE_ALIGNMENT (mode)) { - struct expand_operand ops[2]; + if ((icode = optab_handler (movmisalign_optab, mode)) + != CODE_FOR_nothing) + { + struct expand_operand ops[2]; - /* We've already validated the memory, and we're creating a - new pseudo destination. The predicates really can't fail, - nor can the generator. */ - create_output_operand (&ops[0], NULL_RTX, mode); - create_fixed_operand (&ops[1], temp); - expand_insn (icode, 2, ops); - return ops[0].value; + /* We've already validated the memory, and we're creating a + new pseudo destination. The predicates really can't fail, + nor can the generator. */ + create_output_operand (&ops[0], NULL_RTX, mode); + create_fixed_operand (&ops[1], temp); + expand_insn (icode, 2, ops); + return ops[0].value; + } + else if (SLOW_UNALIGNED_ACCESS (mode, align)) + temp = extract_bit_field (temp, GET_MODE_BITSIZE (mode), + 0, TYPE_UNSIGNED (TREE_TYPE (exp)), + true, (modifier == EXPAND_STACK_PARM + ? NULL_RTX : target), + mode, mode); } return temp; } Index: src/gcc/testsuite/gcc.dg/misaligned-expand-1.c =================================================================== --- /dev/null +++ src/gcc/testsuite/gcc.dg/misaligned-expand-1.c @@ -0,0 +1,41 @@ +/* Test that expand can generate correct loads of misaligned data even on + strict alignment platforms. */ + +/* { dg-do run } */ +/* { dg-options "-O0" } */ + +extern void abort (); + +typedef unsigned int myint __attribute__((aligned(1))); + +unsigned int +foo (myint *p) +{ + return *p; +} + +#define cst 0xdeadbeef +#define NUM 8 + +struct blah +{ + char c; + myint i[NUM]; +}; + +struct blah g; + +int +main (int argc, char **argv) +{ + int i, k; + for (k = 0; k < NUM; k++) + { + g.i[k] = cst; + i = foo (&g.i[k]); + + if (i != cst) + abort (); + } + return 0; +} Index: src/gcc/testsuite/gcc.dg/misaligned-expand-3.c =================================================================== --- /dev/null +++ src/gcc/testsuite/gcc.dg/misaligned-expand-3.c @@ -0,0 +1,43 @@ +/* Test that expand can generate correct stores to misaligned data of complex + type even on strict alignment platforms. */ + +/* { dg-do run } */ +/* { dg-options "-O0" } */ + +extern void abort (); + +typedef _Complex float mycmplx __attribute__((aligned(1))); + +void +foo (mycmplx *p, float r, float i) +{ + __real__ *p = r; + __imag__ *p = i; +} + +#define cvr 3.2f +#define cvi 2.5f +#define NUM 8 + +struct blah +{ + char c; + mycmplx x[NUM]; +} __attribute__((packed)); + +struct blah g; + +int +main (int argc, char **argv) +{ + int k; + + for (k = 0; k < NUM; k++) + { + foo (&g.x[k], cvr, cvi); + if (__real__ g.x[k] != cvr + || __imag__ g.x[k] != cvi) + abort (); + } + return 0; +}