From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by sourceware.org (Postfix) with ESMTPS id D86993858C5F for ; Tue, 19 Dec 2023 06:49:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D86993858C5F 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 ARC-Filter: OpenARC Filter v1.0.0 sourceware.org D86993858C5F Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=148.163.158.5 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702968595; cv=none; b=wGjIkgCcZqP6FOnvtSEeUNnM1oqtULEgQxMItxyx4jSRVmBrNRl20Z4hAeyRUzyOr2VvSpjaWMyLEHJxp9iavHxomdF4BhqcZbGb3K+jYbxixsSHU7SA6U1RwOx+iXgCz0eazlyuVspmrMTWzpZtBLpiaLz88z4kguayRPnVuio= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702968595; c=relaxed/simple; bh=YGX7e8gF1EPASF23QW3FpaVFW901PtuNegMf8TW2+24=; h=DKIM-Signature:Message-ID:Date:Subject:To:From:MIME-Version; b=RuHJnhdMmnmKIyuoTU9jRE4H7/dSMd60RWzsRgDvXZSP5BRFb7L3RAK6hC7dkD0KM0C1PvEk6/WlEAeL/R0dM3sS6jW/moTmeHwGAZDkivjCiF8VfCBfl4c+t9Jbd3u4Gu0vNO8YU6L/vyGHhh2MdA+xnUAMN0p2dslC3FN3slw= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0353723.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3BJ5UvcL016069; Tue, 19 Dec 2023 06:49:52 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=message-id : date : subject : to : cc : references : from : in-reply-to : content-type : content-transfer-encoding : mime-version; s=pp1; bh=eHYRRhX+vsVBu+8gSXYe86umplk47zo0RmzVkEPKsyc=; b=S+3HGeKBgQrIbxgO99BhCidf3TBlXs4WyrNStUDdcEzqKBUiblFszdupfGgiEaIfkbPj Y70TC1NZmGbqMUJdy6odw8WKijQeCi2QkbHCw/cdnTDYTViejJiKz9yTXqMMt/Rs4qZK cvuEcKJppyKhEZXMcI4x24uUaAEOQ3N8/p/tIGmT6SBtDxji5LWVH3rr6W8yHjhBfkel 8gpGOwo1XphyRHrtKaY/saAQADJaaFd13QLSw2obL/0eq2MgBikFpx74bdiWBWDPp+jx v1n3LlvOjIij1VGdIo4qPkzFSQ8Ejq3cjzpEJo+QcRIQicLvcuf1C+tsTrQo4FewZ5vd pg== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3v34m02bvh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 19 Dec 2023 06:49:52 +0000 Received: from m0353723.ppops.net (m0353723.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 3BJ6alqr021297; Tue, 19 Dec 2023 06:49:51 GMT Received: from ppma13.dal12v.mail.ibm.com (dd.9e.1632.ip4.static.sl-reverse.com [50.22.158.221]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3v34m02bv6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 19 Dec 2023 06:49:51 +0000 Received: from pps.filterd (ppma13.dal12v.mail.ibm.com [127.0.0.1]) by ppma13.dal12v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 3BJ5Va8n027086; Tue, 19 Dec 2023 06:49:51 GMT Received: from smtprelay05.fra02v.mail.ibm.com ([9.218.2.225]) by ppma13.dal12v.mail.ibm.com (PPS) with ESMTPS id 3v1rejwgwc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 19 Dec 2023 06:49:50 +0000 Received: from smtpav02.fra02v.mail.ibm.com (smtpav02.fra02v.mail.ibm.com [10.20.54.101]) by smtprelay05.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 3BJ6nmaJ13501080 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 19 Dec 2023 06:49:48 GMT Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 15A2320043; Tue, 19 Dec 2023 06:49:48 +0000 (GMT) Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 18E372004F; Tue, 19 Dec 2023 06:49:46 +0000 (GMT) Received: from [9.197.230.199] (unknown [9.197.230.199]) by smtpav02.fra02v.mail.ibm.com (Postfix) with ESMTP; Tue, 19 Dec 2023 06:49:45 +0000 (GMT) Message-ID: <94b6cacd-0f58-1853-c624-075bc33a53be@linux.ibm.com> Date: Tue, 19 Dec 2023 14:49:44 +0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0) Gecko/20100101 Thunderbird/91.6.1 Subject: Re: [Patchv2, rs6000] Clean up pre-checkings of expand_block_compare Content-Language: en-US To: HAO CHEN GUI Cc: Segher Boessenkool , David , Peter Bergner , gcc-patches References: <15d40d24-f546-4351-9bed-e99b503ec1b9@linux.ibm.com> From: "Kewen.Lin" In-Reply-To: <15d40d24-f546-4351-9bed-e99b503ec1b9@linux.ibm.com> Content-Type: text/plain; charset=UTF-8 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: t76qGDCNKuocFTI8w10Pc4SzrsL4UWVj X-Proofpoint-GUID: h2nEGkIYnKyMCsru5yy8VSkyDODwVysi Content-Transfer-Encoding: 7bit X-Proofpoint-UnRewURL: 0 URL was un-rewritten MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-12-19_02,2023-12-14_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 mlxlogscore=999 clxscore=1015 lowpriorityscore=0 suspectscore=0 impostorscore=0 spamscore=0 bulkscore=0 priorityscore=1501 phishscore=0 malwarescore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2312190048 X-Spam-Status: No, score=-13.5 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,NICE_REPLY_A,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE 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: Hi Haochen, on 2023/12/18 10:44, HAO CHEN GUI wrote: > Hi, > This patch cleans up pre-checkings of expand_block_compare. It does > 1. Assert only P7 above can enter this function as it's already guard > by the expand. > 2. Return false when optimizing for size. > 3. Remove P7 processor test as only P7 above can enter this function and > P7 LE is excluded by targetm.slow_unaligned_access. On P7 BE, the > performance of expand is better than the performance of library when > the length is long. Maybe it's better to split the handling for optimizing for size out to a separated patch, since it's not actually a clean up. Sorry, I should have suggested this in the previous review. For 3, as you have evaluated the performance on Power7, I think it's safe to make this change now, so this patch is ok for trunk, thanks! > > Compared to last version, > https://gcc.gnu.org/pipermail/gcc-patches/2023-December/640082.html > the main change is to add some comments and move the variable definition > closed to its use. > > Bootstrapped and tested on x86 and powerpc64-linux BE and LE with no > regressions. Is this OK for trunk? > > Thanks > Gui Haochen > > ChangeLog > rs6000: Clean up the pre-checkings of expand_block_compare > > gcc/ > * gcc/config/rs6000/rs6000-string.cc (expand_block_compare): Assert > only P7 above can enter this function. Return false (call library) > when it's optimized for size. Remove P7 CPU test as only P7 above > can enter this function and P7 LE is excluded by the checking of > targetm.slow_unaligned_access on word_mode. Also performance test > shows the expand of block compare with 16 bytes to 64 bytes length > is better than library on P7 BE. Nit: You can just describe "what's done" but not "why" here, and put "why" into the commit log instead. BR, Kewen > > gcc/testsuite/ > * gcc.target/powerpc/block-cmp-3.c: New. > > > patch.diff > diff --git a/gcc/config/rs6000/rs6000-string.cc b/gcc/config/rs6000/rs6000-string.cc > index cb9eeef05d8..49670cef4d7 100644 > --- a/gcc/config/rs6000/rs6000-string.cc > +++ b/gcc/config/rs6000/rs6000-string.cc > @@ -1946,36 +1946,32 @@ expand_block_compare_gpr(unsigned HOST_WIDE_INT bytes, unsigned int base_align, > bool > expand_block_compare (rtx operands[]) > { > - rtx target = operands[0]; > - rtx orig_src1 = operands[1]; > - rtx orig_src2 = operands[2]; > - rtx bytes_rtx = operands[3]; > - rtx align_rtx = operands[4]; > + /* TARGET_POPCNTD is already guarded at expand cmpmemsi. */ > + gcc_assert (TARGET_POPCNTD); > > - /* This case is complicated to handle because the subtract > - with carry instructions do not generate the 64-bit > - carry and so we must emit code to calculate it ourselves. > - We choose not to implement this yet. */ > - if (TARGET_32BIT && TARGET_POWERPC64) > + if (optimize_insn_for_size_p ()) > return false; > > - bool isP7 = (rs6000_tune == PROCESSOR_POWER7); > - > /* Allow this param to shut off all expansion. */ > if (rs6000_block_compare_inline_limit == 0) > return false; > > - /* targetm.slow_unaligned_access -- don't do unaligned stuff. > - However slow_unaligned_access returns true on P7 even though the > - performance of this code is good there. */ > - if (!isP7 > - && (targetm.slow_unaligned_access (word_mode, MEM_ALIGN (orig_src1)) > - || targetm.slow_unaligned_access (word_mode, MEM_ALIGN (orig_src2)))) > + /* This case is complicated to handle because the subtract > + with carry instructions do not generate the 64-bit > + carry and so we must emit code to calculate it ourselves. > + We choose not to implement this yet. */ > + if (TARGET_32BIT && TARGET_POWERPC64) > return false; > > - /* Unaligned l*brx traps on P7 so don't do this. However this should > - not affect much because LE isn't really supported on P7 anyway. */ > - if (isP7 && !BYTES_BIG_ENDIAN) > + rtx target = operands[0]; > + rtx orig_src1 = operands[1]; > + rtx orig_src2 = operands[2]; > + rtx bytes_rtx = operands[3]; > + rtx align_rtx = operands[4]; > + > + /* targetm.slow_unaligned_access -- don't do unaligned stuff. */ > + if (targetm.slow_unaligned_access (word_mode, MEM_ALIGN (orig_src1)) > + || targetm.slow_unaligned_access (word_mode, MEM_ALIGN (orig_src2))) > return false; > > /* If this is not a fixed size compare, try generating loop code and > @@ -2023,14 +2019,6 @@ expand_block_compare (rtx operands[]) > if (!IN_RANGE (bytes, 1, max_bytes)) > return expand_compare_loop (operands); > > - /* The code generated for p7 and older is not faster than glibc > - memcmp if alignment is small and length is not short, so bail > - out to avoid those conditions. */ > - if (targetm.slow_unaligned_access (word_mode, UINTVAL (align_rtx)) > - && ((base_align == 1 && bytes > 16) > - || (base_align == 2 && bytes > 32))) > - return false; > - > rtx final_label = NULL; > > if (use_vec) > diff --git a/gcc/testsuite/gcc.target/powerpc/block-cmp-3.c b/gcc/testsuite/gcc.target/powerpc/block-cmp-3.c > new file mode 100644 > index 00000000000..c7e853ad593 > --- /dev/null > +++ b/gcc/testsuite/gcc.target/powerpc/block-cmp-3.c > @@ -0,0 +1,8 @@ > +/* { dg-do compile } */ > +/* { dg-options "-Os" } */ > +/* { dg-final { scan-assembler-times {\mb[l]? memcmp\M} 1 } } */ > + > +int foo (const char* s1, const char* s2) > +{ > + return __builtin_memcmp (s1, s2, 4); > +}