From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by sourceware.org (Postfix) with ESMTPS id 6D81E3858D39 for ; Mon, 27 Feb 2023 22:04:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6D81E3858D39 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=linux.ibm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linux.ibm.com Received: from pps.filterd (m0098399.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 31RLC1P4001263; Mon, 27 Feb 2023 22:04:02 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=message-id : date : mime-version : subject : to : cc : references : from : in-reply-to : content-type : content-transfer-encoding; s=pp1; bh=qznJSgCPXoRcisyZUHDkeplPmSELQp9mzS4b4ggtZZY=; b=sfhxAOj1BZsGMR0t5IdW2wFUDFx8Qee9GOGTFRbkiBWXzUUQCLdRPSP5RS2tatqY2O3L ZH6FX2Cic4kr4Z7CasVT7gbS9cUCOhPaCHIA2IdfdEjFKSxpd8EY7IAUvUqhCjPAXVha UkVQc9Ft0CQdbD54GvpVYGB9XCK1eayQWSkKPoq7dW76L0Cuj7wH6LsI4tyeiROIEV4m xpmlRbtHaBghIb+74xpU9bCHWTw3ncSQ6/TUy7MI8S9QTZ9IZNn4yypk1HQ/LHmeXRrU c9e83+JpJ5wdVoY7LWjCUNO7/9YrumYLfOWBfcGEiMFm2q5i5KxQ6pr7t9YsAaHbcKq8 Dw== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3p147fh38g-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 27 Feb 2023 22:04:01 +0000 Received: from m0098399.ppops.net (m0098399.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 31RLvnDx002121; Mon, 27 Feb 2023 22:04:01 GMT Received: from ppma03dal.us.ibm.com (b.bd.3ea9.ip4.static.sl-reverse.com [169.62.189.11]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3p147fh37n-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 27 Feb 2023 22:04:01 +0000 Received: from pps.filterd (ppma03dal.us.ibm.com [127.0.0.1]) by ppma03dal.us.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 31RLZvfH030157; Mon, 27 Feb 2023 22:04:00 GMT Received: from smtprelay02.wdc07v.mail.ibm.com ([9.208.129.120]) by ppma03dal.us.ibm.com (PPS) with ESMTPS id 3nybcm8wt5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 27 Feb 2023 22:04:00 +0000 Received: from smtpav03.dal12v.mail.ibm.com (smtpav03.dal12v.mail.ibm.com [10.241.53.102]) by smtprelay02.wdc07v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 31RM3wOV6029968 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 27 Feb 2023 22:03:58 GMT Received: from smtpav03.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3FC235805A; Mon, 27 Feb 2023 22:03:58 +0000 (GMT) Received: from smtpav03.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id BBC0158056; Mon, 27 Feb 2023 22:03:57 +0000 (GMT) Received: from [9.65.241.84] (unknown [9.65.241.84]) by smtpav03.dal12v.mail.ibm.com (Postfix) with ESMTPS; Mon, 27 Feb 2023 22:03:57 +0000 (GMT) Message-ID: <44cfd0fa-21b4-0e3c-6082-2a5156f4d141@linux.ibm.com> Date: Mon, 27 Feb 2023 16:03:56 -0600 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.8.0 Subject: Re: [PATCH, rs6000] Tweak modulo define_insns to eliminate register copy Content-Language: en-US To: Segher Boessenkool Cc: GCC Patches , "Kewen.Lin" , David Edelsohn , Peter Bergner References: <3cad2a5e-dd68-2fbe-d52b-e077a7405623@linux.ibm.com> <20230227170835.GA25951@gate.crashing.org> <20578dd1-fba8-858a-a6e5-cdbb3ca0b6c1@linux.ibm.com> <20230227205331.GC25951@gate.crashing.org> From: Pat Haugen In-Reply-To: <20230227205331.GC25951@gate.crashing.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: c98d4Ftz8T1UxZyl6RZFlCvBa54tUVb7 X-Proofpoint-GUID: hYfbprzdcml9phkfv2_WGl9_4f8H-NnC X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.930,Hydra:6.0.562,FMLib:17.11.170.22 definitions=2023-02-27_17,2023-02-27_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 suspectscore=0 spamscore=0 priorityscore=1501 mlxlogscore=947 lowpriorityscore=0 phishscore=0 clxscore=1015 adultscore=0 bulkscore=0 mlxscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2302270176 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 2/27/23 2:53 PM, Segher Boessenkool wrote: > Hi! > > On Mon, Feb 27, 2023 at 02:12:23PM -0600, Pat Haugen wrote: >> On 2/27/23 11:08 AM, Segher Boessenkool wrote: >>> On Mon, Feb 27, 2023 at 09:11:37AM -0600, Pat Haugen wrote: >>>> The define_insns for the modulo operation currently force the target >>>> register >>>> to a distinct reg in preparation for a possible future peephole combining >>>> div/mod. But this can lead to cases of a needless copy being inserted. >>>> Fixed >>>> with the following patch. >>> >>> Have you verified those peepholes still match? >> >> Yes, I verified the peepholes still match and transform the sequence. > > Please add the testcases for that then? Or do we have tests for it > already :-) I don't see one, but can add one. >>> Do those peepholes actually improve performance? On new CPUs? The code >>> here says >>> ;; On machines with modulo support, do a combined div/mod the old fashioned >>> ;; method, since the multiply/subtract is faster than doing the mod >>> instruction >>> ;; after a divide. >>> but that really should not be true: we can do the div and mod in >>> parallel (except in SMT4 perhaps, which we never schedule for anyway), >>> so that should always be strictly faster. >>> >> Since the modulo insns were introduced in Power9, we're just talking >> Power9/Power10. On paper, I would agree that separate div/mod could be >> slightly faster to get the mod result, > > "Slightly". It takes 12 cycles for the two in parallel (64-bit, p9), > but 17 cycles for the "cheaper" sequence (divd+mulld+subf, 12+5+2). It > is all worse if the units are busy of course, or if there are other > problems. > >> but if you throw in another >> independent div or mod in the insn stream then doing the peephole should >> be a clear win since that 3rd insn can execute in parallel with the >> initial divide as opposed to waiting for the one of the first div/mod to >> clear the exclusive stage of the pipe. > > That is the SMT4 case, the one we do not optimise for. SMT2 and ST can > do four in parallel. This means you can start a div or mod every 2nd > cycle on average, so it is very unlikely you will ever be limited by > this on real code. Power9/Power10 only have 2 fixed-point divide units, and are able to issue 2 divides every 9/11 cycles (they aren't fully pipelined), with latencies of 12-24/12-25. Not saying that changes the "best case" scenario, just pointing out a lot of variables in play. -Pat