From patchwork Mon Aug 6 15:01:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Krebbel X-Patchwork-Id: 953935 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-483237-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.ibm.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="ZvjfyFVP"; dkim-atps=neutral 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 41kgq86mRrz9s0n for ; Tue, 7 Aug 2018 01:02:12 +1000 (AEST) 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:cc:subject:date:message-id; q=dns; s=default; b=xrWWxC/2NdL8 CdxhP9WbYjip0jPS/XrWaYN9FzeVohtpBi/e7+GlTAIA5FqEo5k2qy5ZCePn/PEX gvsZVGGDgT/Qo6MZQsfOuYremp/IS7216+LfsXqZ6OrPpdu8Rmjsq8+cUqSvLJvp MNK5hUDhJ3njM3OaP77JEfK67cYlSYw= 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:cc:subject:date:message-id; s=default; bh=actOKPwz9ihvHdLBeI F7wfII8hM=; b=ZvjfyFVP2f/qPwhudR9itxDT91MCWD95JKUakjrXgmOMeLYYhO IA/0JQpfJij0jW9nceJtJmMTq4wUUxa/6J6zHAzDwmVXpd5dABBaKpbjliG/R+hQ X58x0r+YMDje6p2gJ30s4IG3t/x6TqJBSRtHGENXu8fZ41nGygrezH53c= Received: (qmail 13967 invoked by alias); 6 Aug 2018 15:02:06 -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 13952 invoked by uid 89); 6 Aug 2018 15:02:05 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.0 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 spammy=z13, H*Ad:D*vnet.ibm.com 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; Mon, 06 Aug 2018 15:01:59 +0000 Received: from pps.filterd (m0098414.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w76Exa23114040 for ; Mon, 6 Aug 2018 11:01:58 -0400 Received: from e06smtp07.uk.ibm.com (e06smtp07.uk.ibm.com [195.75.94.103]) by mx0b-001b2d01.pphosted.com with ESMTP id 2kpnqcrm98-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 06 Aug 2018 11:01:54 -0400 Received: from localhost by e06smtp07.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 6 Aug 2018 16:01:52 +0100 Received: from b06cxnps3074.portsmouth.uk.ibm.com (9.149.109.194) by e06smtp07.uk.ibm.com (192.168.101.137) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Mon, 6 Aug 2018 16:01:51 +0100 Received: from d06av21.portsmouth.uk.ibm.com (d06av21.portsmouth.uk.ibm.com [9.149.105.232]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w76F1ob519857524 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 6 Aug 2018 15:01:50 GMT Received: from d06av21.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 85EB752059; Mon, 6 Aug 2018 18:01:58 +0100 (BST) Received: from maggie.boeblingen.de.ibm.com (unknown [9.152.222.136]) by d06av21.portsmouth.uk.ibm.com (Postfix) with ESMTPS id 700D35206D; Mon, 6 Aug 2018 18:01:58 +0100 (BST) From: Andreas Krebbel To: gcc-patches@gcc.gnu.org Cc: Andreas Krebbel Subject: [Committed] S/390: Don't unroll memory blk op loops Date: Mon, 6 Aug 2018 17:01:49 +0200 x-cbid: 18080615-0028-0000-0000-000002E63FAE X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18080615-0029-0000-0000-0000239E629D Message-Id: <20180806150149.13537-1-krebbel@linux.ibm.com> From: Andreas Krebbel gcc/ChangeLog: 2018-08-06 Andreas Krebbel * config/s390/s390.c (s390_loop_unroll_adjust): Prevent small loops with memory block operations from getting unrolled. gcc/testsuite/ChangeLog: 2018-08-06 Andreas Krebbel * gcc.target/s390/nomemloopunroll-1.c: New test. --- gcc/config/s390/s390.c | 31 ++++++++++++++++++++--- gcc/testsuite/gcc.target/s390/nomemloopunroll-1.c | 27 ++++++++++++++++++++ 2 files changed, 55 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gcc.target/s390/nomemloopunroll-1.c diff --git a/gcc/config/s390/s390.c b/gcc/config/s390/s390.c index ec588a2..aa34f56 100644 --- a/gcc/config/s390/s390.c +++ b/gcc/config/s390/s390.c @@ -390,6 +390,11 @@ static unsigned vfu_longrunning[NUM_SIDES]; base and index are registers of the class ADDR_REGS, displacement is an unsigned 12-bit immediate constant. */ +/* The max number of insns of backend generated memset/memcpy/memcmp + loops. This value is used in the unroll adjust hook to detect such + loops. Current max is 9 coming from the memcmp loop. */ +#define BLOCK_MEM_OPS_LOOP_INSNS 9 + struct s390_address { rtx base; @@ -15385,9 +15390,29 @@ s390_loop_unroll_adjust (unsigned nunroll, struct loop *loop) for (i = 0; i < loop->num_nodes; i++) FOR_BB_INSNS (bbs[i], insn) if (INSN_P (insn) && INSN_CODE (insn) != -1) - FOR_EACH_SUBRTX (iter, array, PATTERN (insn), NONCONST) - if (MEM_P (*iter)) - mem_count += 1; + { + rtx set; + + /* The runtime of small loops with memory block operations + will be determined by the memory operation. Doing + unrolling doesn't help here. Measurements to confirm + this where only done on recent CPU levels. So better do + not change anything for older CPUs. */ + if (s390_tune >= PROCESSOR_2964_Z13 + && loop->ninsns <= BLOCK_MEM_OPS_LOOP_INSNS + && ((set = single_set (insn)) != NULL_RTX) + && ((GET_MODE (SET_DEST (set)) == BLKmode + && (GET_MODE (SET_SRC (set)) == BLKmode + || SET_SRC (set) == const0_rtx)) + || (GET_CODE (SET_SRC (set)) == COMPARE + && GET_MODE (XEXP (SET_SRC (set), 0)) == BLKmode + && GET_MODE (XEXP (SET_SRC (set), 1)) == BLKmode))) + return 1; + + FOR_EACH_SUBRTX (iter, array, PATTERN (insn), NONCONST) + if (MEM_P (*iter)) + mem_count += 1; + } free (bbs); /* Prevent division by zero, and we do not need to adjust nunroll in this case. */ diff --git a/gcc/testsuite/gcc.target/s390/nomemloopunroll-1.c b/gcc/testsuite/gcc.target/s390/nomemloopunroll-1.c new file mode 100644 index 0000000..695d925 --- /dev/null +++ b/gcc/testsuite/gcc.target/s390/nomemloopunroll-1.c @@ -0,0 +1,27 @@ +/* { dg-do compile } */ +/* { dg-options "-O3 -funroll-loops -march=z13" } */ + +/* 2x mvc */ +void * +foo (char *a, int c, long len) +{ + return __builtin_memset (a, c, len); +} + +/* 2x mvc */ +void +bar (char *a, char *b) +{ + __builtin_memcpy (a, b, 30000); +} + +/* 2x clc */ + +int +baz (char *a, char *b) +{ + return __builtin_memcmp (a, b, 30000); +} + +/* { dg-final { scan-assembler-times "\\\smvc\\\s" 4 } } */ +/* { dg-final { scan-assembler-times "\\\sclc\\\s" 2 } } */