From patchwork Tue Jan 3 09:43:54 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Krebbel X-Patchwork-Id: 710435 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]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3tt8DY26ZKz9s2Q for ; Tue, 3 Jan 2017 20:44:42 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="bT0SEQQ5"; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:in-reply-to:references:message-id; q=dns; s= default; b=TLgcOkegA1FJg0SD3YsB35ClTsOtbS8EltRCfraKmB/r1sH1HUlAm uyrgMlT6berUaXSR5BJBCZcQymMpjV0fzcmXHJPwvOppq07dwXhnTUfJ/BYKZr7g FduiCs6UIyDOFyWS0jCna7xGj+ykhznzxQYfPfd72y01P6tanP7qyQ= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:in-reply-to:references:message-id; s=default; bh=bPD0SSnnTWeXzdxDqZIYKy9yS3o=; b=bT0SEQQ5FTve9PNcI+dBGiJbyfzz cJmeOOdVFR8K30s3mi5dZ5lkzqiFw4eV7WwTasyXueosM4bcSArJKVvOTf6NLsGo CL6xj8eLANRgKX8rmUhtKvM6pij8LTQTb0ci9wXJxZ7f50LWSVCVDWEf9s3oF6pc RWIp6TDWj/mm040= Received: (qmail 20063 invoked by alias); 3 Jan 2017 09:44:07 -0000 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 Received: (qmail 19952 invoked by uid 89); 3 Jan 2017 09:44:06 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.6 required=5.0 tests=BAYES_00, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_DNSWL_LOW autolearn=no version=3.3.2 spammy=emit_insn, s390.c, s390c, UD:s390.c X-HELO: mx0a-001b2d01.pphosted.com Received: from mx0b-001b2d01.pphosted.com (HELO mx0a-001b2d01.pphosted.com) (148.163.158.5) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 03 Jan 2017 09:44:05 +0000 Received: from pps.filterd (m0098414.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.17/8.16.0.17) with SMTP id v039hosx085184 for ; Tue, 3 Jan 2017 04:44:03 -0500 Received: from e06smtp14.uk.ibm.com (e06smtp14.uk.ibm.com [195.75.94.110]) by mx0b-001b2d01.pphosted.com with ESMTP id 27r8dhu4dn-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Tue, 03 Jan 2017 04:44:03 -0500 Received: from localhost by e06smtp14.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 3 Jan 2017 09:44:02 -0000 Received: from d06dlp01.portsmouth.uk.ibm.com (9.149.20.13) by e06smtp14.uk.ibm.com (192.168.101.144) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 3 Jan 2017 09:44:00 -0000 Received: from b06cxnps3074.portsmouth.uk.ibm.com (d06relay09.portsmouth.uk.ibm.com [9.149.109.194]) by d06dlp01.portsmouth.uk.ibm.com (Postfix) with ESMTP id BF3BB17D8062 for ; Tue, 3 Jan 2017 09:46:47 +0000 (GMT) Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v039i05O8257990 for ; Tue, 3 Jan 2017 09:44:00 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9365A4C059 for ; Tue, 3 Jan 2017 08:42:14 +0000 (GMT) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 7AFA94C046 for ; Tue, 3 Jan 2017 08:42:14 +0000 (GMT) Received: from maggie.emea.ibm.com (unknown [9.145.156.199]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTPS for ; Tue, 3 Jan 2017 08:42:14 +0000 (GMT) From: Andreas Krebbel To: gcc-patches@gcc.gnu.org Subject: [PATCH 3/4] S/390: Unroll mvc loop for memcpy with small constant lengths. Date: Tue, 3 Jan 2017 10:43:54 +0100 In-Reply-To: <20170103094355.20933-1-krebbel@linux.vnet.ibm.com> References: <20170103094355.20933-1-krebbel@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 X-Content-Scanned: Fidelis XPS MAILER x-cbid: 17010309-0016-0000-0000-0000036ECA84 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17010309-0017-0000-0000-00002544C0C2 Message-Id: <20170103094355.20933-4-krebbel@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-01-03_07:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=1 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1612050000 definitions=main-1701030160 X-IsSubscribed: yes See the memset unrolling patch. The very same applies to memcpys with constant lengths. 2017-01-03 Andreas Krebbel * config/s390/s390.c (s390_expand_movmem): Unroll MVC loop for small constant length operands. gcc/testsuite/ChangeLog: 2017-01-03 Andreas Krebbel * gcc.target/s390/memcpy-1.c: New test. --- gcc/config/s390/s390.c | 21 +++++++++++-- gcc/testsuite/gcc.target/s390/memcpy-1.c | 53 ++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gcc.target/s390/memcpy-1.c diff --git a/gcc/config/s390/s390.c b/gcc/config/s390/s390.c index 1266f45..9bd98eb 100644 --- a/gcc/config/s390/s390.c +++ b/gcc/config/s390/s390.c @@ -5246,10 +5246,25 @@ s390_expand_movmem (rtx dst, rtx src, rtx len) && (GET_CODE (len) != CONST_INT || INTVAL (len) > (1<<16))) return false; - if (GET_CODE (len) == CONST_INT && INTVAL (len) >= 0 && INTVAL (len) <= 256) + /* Expand memcpy for constant length operands without a loop if it + is shorter that way. + + With a constant length argument a + memcpy loop (without pfd) is 36 bytes -> 6 * mvc */ + if (GET_CODE (len) == CONST_INT + && INTVAL (len) >= 0 + && INTVAL (len) <= 256 * 6 + && (!TARGET_MVCLE || INTVAL (len) <= 256)) { - if (INTVAL (len) > 0) - emit_insn (gen_movmem_short (dst, src, GEN_INT (INTVAL (len) - 1))); + HOST_WIDE_INT o, l; + + for (l = INTVAL (len), o = 0; l > 0; l -= 256, o += 256) + { + rtx newdst = adjust_address (dst, BLKmode, o); + rtx newsrc = adjust_address (src, BLKmode, o); + emit_insn (gen_movmem_short (newdst, newsrc, + GEN_INT (l > 256 ? 255 : l - 1))); + } } else if (TARGET_MVCLE) diff --git a/gcc/testsuite/gcc.target/s390/memcpy-1.c b/gcc/testsuite/gcc.target/s390/memcpy-1.c new file mode 100644 index 0000000..58c1b49 --- /dev/null +++ b/gcc/testsuite/gcc.target/s390/memcpy-1.c @@ -0,0 +1,53 @@ +/* Make sure that short memcpy's with constant length are emitted + without loop statements. */ + +/* { dg-do compile } */ +/* { dg-options "-O3 -mzarch" } */ + +/* 3 MVCs */ +void +*memcpy1(void *dest, const void *src) +{ + return __builtin_memcpy (dest, src, 700); +} + +/* NOP */ +void +*memcpy2(void *dest, const void *src) +{ + return __builtin_memcpy (dest, src, 0); +} + +/* 1 MVC */ +void +*memcpy3(void *dest, const void *src) +{ + return __builtin_memcpy (dest, src, 256); +} + +/* 2 MVCs */ +void +*memcpy4(void *dest, const void *src) +{ + return __builtin_memcpy (dest, src, 512); +} + +/* 3 MVCs */ +void +*memcpy5(void *dest, const void *src) +{ + return __builtin_memcpy (dest, src, 768); +} + +/* Loop with 2 MVCs */ +void +*memcpy6(void *dest, const void *src) +{ + return __builtin_memcpy (dest, src, 1537); +} + +/* memcpy6 uses a loop - check for the two load address instructions + used to increment src and dest. */ +/* { dg-final { scan-assembler-times "la" 2 } } */ + +/* { dg-final { scan-assembler-times "mvc" 11 } } */