From patchwork Fri Jul 20 19:34:53 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 172334 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 80E972C03EB for ; Sat, 21 Jul 2012 05:35:19 +1000 (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=1343417720; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Received:Received:Received:From:To:Subject:Date: Message-ID:Content-Type:MIME-Version:Mailing-List:Precedence: List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender: Delivered-To; bh=kc3sxWVqppA1Eb3dgmb4c4rmMwY=; b=JtGGhSHE5kzSFms gEWxuqfW6/TJ9opkMqF7Anc4yG5MZ9ROB6i05qYha9zgCNdnrprx0dgsjINdEw8e oiMVQsaxsjl7P2FoJidA2BGSOHULmY/vbXZAUGMGMeLHrXUaGITgjKxBn/e8raf0 3gU5P9yb83BVV5EvqK2C+PBqbw1M= 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:Received:X-Forefront-Antispam-Report:X-SpamScore:X-BigFish:Received:Received:Received:Received:From:To:Subject:Date:Message-ID:Content-Type:MIME-Version:X-OriginatorOrg:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=w+nrQqcdK6LksOZbZyfxKAUm8HK8b09aPH03cMZdEp+00VfY2YFdlzhEEUTtnQ UUQI7oPlhQXsfSEsN/O0J/bSRx5MaCHHC94wkBVzfHMxdWrMpqE8yfd8pp1ex8wJ uVYOXr0gIUGl3DD1qYsNKjl6z8PDov3VIL62EkFn4fFLQ=; Received: (qmail 1807 invoked by alias); 20 Jul 2012 19:35:15 -0000 Received: (qmail 1176 invoked by uid 22791); 20 Jul 2012 19:35:13 -0000 X-SWARE-Spam-Status: No, hits=-4.2 required=5.0 tests=BAYES_00, KHOP_RCVD_UNTRUST, RCVD_IN_DNSWL_LOW, RCVD_IN_HOSTKARMA_NO, RCVD_IN_HOSTKARMA_W, RCVD_IN_HOSTKARMA_WL, TW_XT X-Spam-Check-By: sourceware.org Received: from am1ehsobe004.messaging.microsoft.com (HELO am1outboundpool.messaging.microsoft.com) (213.199.154.207) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 20 Jul 2012 19:34:59 +0000 Received: from mail120-am1-R.bigfish.com (10.3.201.230) by AM1EHSOBE001.bigfish.com (10.3.204.21) with Microsoft SMTP Server id 14.1.225.23; Fri, 20 Jul 2012 19:34:57 +0000 Received: from mail120-am1 (localhost [127.0.0.1]) by mail120-am1-R.bigfish.com (Postfix) with ESMTP id 7D2AF420346 for ; Fri, 20 Jul 2012 19:34:57 +0000 (UTC) X-Forefront-Antispam-Report: CIP:157.56.236.133; KIP:(null); UIP:(null); IPV:NLI; H:BY2PRD0710HT001.namprd07.prod.outlook.com; RD:none; EFVD:NLI X-SpamScore: -6 X-BigFish: PS-6(zzc85fh154dM4015Izz1202hzzz2dh2a8h668h839hd25hf0ah107ah34h) Received: from mail120-am1 (localhost.localdomain [127.0.0.1]) by mail120-am1 (MessageSwitch) id 1342812895527611_2235; Fri, 20 Jul 2012 19:34:55 +0000 (UTC) Received: from AM1EHSMHS015.bigfish.com (unknown [10.3.201.231]) by mail120-am1.bigfish.com (Postfix) with ESMTP id 7544A60258 for ; Fri, 20 Jul 2012 19:34:55 +0000 (UTC) Received: from BY2PRD0710HT001.namprd07.prod.outlook.com (157.56.236.133) by AM1EHSMHS015.bigfish.com (10.3.207.153) with Microsoft SMTP Server (TLS) id 14.1.225.23; Fri, 20 Jul 2012 19:34:55 +0000 Received: from BY2PRD0710MB377.namprd07.prod.outlook.com ([169.254.2.224]) by BY2PRD0710HT001.namprd07.prod.outlook.com ([10.255.86.36]) with mapi id 14.16.0175.005; Fri, 20 Jul 2012 19:34:54 +0000 From: "Pinski, Andrew" To: "gcc-patches@gcc.gnu.org" Subject: [PATCH MIPS] Improve unaligned 32bits load on MIPS64 Date: Fri, 20 Jul 2012 19:34:53 +0000 Message-ID: MIME-Version: 1.0 X-OriginatorOrg: caviumnetworks.com 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, Currently doing a 32bit unaligned load on MIPS64, produces 4 byte loads, this can be improved to using lwl/lwr instead. The problem is the code in mips_expand_ext_as_unaligned_load that handles this case does handle the case where the register is DImode but the width is 32. This patch fixes the problem by creating a new temp register of SImode and then using that as the destination and then extending (zero or sign depending on the if it is extv or extzv) into the original destination. OK? Bootstrapped and tested on mips64-linux-gnu with no regressions. Thanks, Andrew Pinski ChangeLog: * config/mips/mips-protos.h (mips_expand_ext_as_unaligned_load): Add a bool argument. * config/mips/mips.c (mips_block_move_straight): Update call to mips_expand_ext_as_unaligned_load. (mips_expand_ext_as_unaligned_load): Add unsigned_p argument. Accept DImode dest when the width is that of SImode. Index: testsuite/gcc.target/mips/unaligned-1.c =================================================================== --- testsuite/gcc.target/mips/unaligned-1.c (revision 0) +++ testsuite/gcc.target/mips/unaligned-1.c (revision 0) @@ -0,0 +1,44 @@ +/* { dg-options "-O2 -mgp64" } */ +/* { dg-final { scan-assembler-times "sdl\t" 1 } } */ +/* { dg-final { scan-assembler-times "sdr\t" 1 } } */ +/* { dg-final { scan-assembler-times "ldl\t" 1 } } */ +/* { dg-final { scan-assembler-times "ldr\t" 1 } } */ +/* { dg-final { scan-assembler-times "swl\t" 1 } } */ +/* { dg-final { scan-assembler-times "swr\t" 1 } } */ +/* { dg-final { scan-assembler-times "lwl\t" 1 } } */ +/* { dg-final { scan-assembler-times "lwr\t" 1 } } */ +/* { dg-final { scan-assembler-not "nop" } } */ + +/* Test to make sure we produce the unaligned load/store for + both 64bit and 32bits sized accesses. */ + +struct s +{ + char c; + int i; + long long l; +} __attribute__ ((packed)) s __attribute__((aligned(1) )); + +void +sd (long long l) +{ + s.l = l; +} + +long long +ld () +{ + return s.l; +} + +void +sw (int i) +{ + s.i = i; +} + +int +lw () +{ + return s.i; +} Index: config/mips/mips.md =================================================================== --- config/mips/mips.md (revision 189724) +++ config/mips/mips.md (working copy) @@ -3653,7 +3653,8 @@ (define_expand "extv" { if (mips_expand_ext_as_unaligned_load (operands[0], operands[1], INTVAL (operands[2]), - INTVAL (operands[3]))) + INTVAL (operands[3]), + /*unsigned=*/ false)) DONE; else if (register_operand (operands[1], GET_MODE (operands[0])) && ISA_HAS_EXTS && UINTVAL (operands[2]) <= 32) @@ -3690,7 +3691,8 @@ (define_expand "extzv" { if (mips_expand_ext_as_unaligned_load (operands[0], operands[1], INTVAL (operands[2]), - INTVAL (operands[3]))) + INTVAL (operands[3]), + /*unsigned=*/true)) DONE; else if (mips_use_ins_ext_p (operands[1], INTVAL (operands[2]), INTVAL (operands[3]))) Index: config/mips/mips-protos.h =================================================================== --- config/mips/mips-protos.h (revision 189724) +++ config/mips/mips-protos.h (working copy) @@ -241,7 +241,7 @@ extern bool mips_pad_arg_upward (enum ma extern bool mips_pad_reg_upward (enum machine_mode, tree); extern bool mips_expand_ext_as_unaligned_load (rtx, rtx, HOST_WIDE_INT, - HOST_WIDE_INT); + HOST_WIDE_INT, bool); extern bool mips_expand_ins_as_unaligned_store (rtx, rtx, HOST_WIDE_INT, HOST_WIDE_INT); extern bool mips_mem_fits_mode_p (enum machine_mode mode, rtx x); Index: config/mips/mips.c =================================================================== --- config/mips/mips.c (revision 189724) +++ config/mips/mips.c (working copy) @@ -6916,7 +6916,7 @@ mips_block_move_straight (rtx dest, rtx else { rtx part = adjust_address (src, BLKmode, offset); - if (!mips_expand_ext_as_unaligned_load (regs[i], part, bits, 0)) + if (!mips_expand_ext_as_unaligned_load (regs[i], part, bits, 0, 0)) gcc_unreachable (); } } @@ -7248,9 +7248,10 @@ mips_get_unaligned_mem (rtx *op, HOST_WI bool mips_expand_ext_as_unaligned_load (rtx dest, rtx src, HOST_WIDE_INT width, - HOST_WIDE_INT bitpos) + HOST_WIDE_INT bitpos, bool unsigned_p) { rtx left, right, temp; + rtx dest1 = NULL_RTX; /* If TARGET_64BIT, the destination of a 32-bit "extz" or "extzv" will be a paradoxical word_mode subreg. This is the only case in which @@ -7260,6 +7261,16 @@ mips_expand_ext_as_unaligned_load (rtx d && GET_MODE (SUBREG_REG (dest)) == SImode) dest = SUBREG_REG (dest); + /* If TARGET_64BIT, the destination of a 32-bit "extz" or "extzv" will + be a DImode, create a new temp and emit a zero extend at the end. */ + if (GET_MODE (dest) == DImode + && REG_P (dest) + && GET_MODE_BITSIZE (SImode) == width) + { + dest1 = dest; + dest = gen_reg_rtx (SImode); + } + /* After the above adjustment, the destination must be the same width as the source. */ if (GET_MODE_BITSIZE (GET_MODE (dest)) != width) @@ -7279,6 +7290,16 @@ mips_expand_ext_as_unaligned_load (rtx d emit_insn (gen_mov_lwl (temp, src, left)); emit_insn (gen_mov_lwr (dest, copy_rtx (src), right, temp)); } + + /* If we were loading 32bits and the original register was DI then + sign/zero extend into the orignal dest. */ + if (dest1) + { + if (unsigned_p) + emit_insn (gen_zero_extendsidi2 (dest1, dest)); + else + emit_insn (gen_extendsidi2 (dest1, dest)); + } return true; }