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 D8F0738582BD for ; Thu, 21 Dec 2023 06:28:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D8F0738582BD 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 D8F0738582BD Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=148.163.156.1 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1703140123; cv=none; b=FVv1QB+rl0q6WAAHfAWpCXNpKzyd2X2mEywLcAUg7uACmkMsNKx7FPTNgFLcsfuBHnh40BxzUfCluKB55R2pTxoowlSUOxTj6HVrNLMA73097vkzzdg8YehMWs8ojCcQgltM9nIIfQ82DVANBtsu/JBNwms2aZJGkRFqzPtskLs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1703140123; c=relaxed/simple; bh=cNKrRxvf/N1k66VoiYhSWGsAJ5faZE4RnLTo2hBsJeY=; h=DKIM-Signature:Message-ID:Date:Subject:To:From:MIME-Version; b=SqpV9mpc4PIL6W0Uw2tbrIMhtiA3EyeZ+tEaQ5m1R1utDfWakvHA9O6iRdFnN2glu7qLpqV+ZoCaOdtJ0roJGzEOlyAkRPJ2D2JjQr1Z7qfoi3i4r7XV41xuMhtdTkuv+n+RNhW74Cfmk+CXMGuQyo5R046gj7szezBf2gD4s40= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0353729.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3BL5xLoR031015; Thu, 21 Dec 2023 06:28:41 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=b7/iSQBbroN+L28h3nwpxwVg1S0N6gsvcqnGb2U3j+E=; b=e9masK06FrNkluVcdMMhu7CoS+HSsqscN7XQekmRDE5i+k/x+TvxLGKJYu/GJLLv77AC 8NvasTFDwowa6ND66N63KjH1pw9LVR6Km2CQUtYsPqCRq2f6N4xN9/vwUdncILAw1LKa uereIvx6HfEn2nDfLxdrjgFG9lHEZplkGlikI+dfac7KIF4doeKLpzOnYJWdhOV3agXi sGwGSbAasPMAbwK1G46h3679dFcDNf5h8H3HiCPRS4RMZ0Us6E928EvmBil57FO3oRj1 rDXRkq2Nc1q6/ChUkxh0dyh6wTPMXfICuU5xD29NMGTRayFSZGm7lst54SQA7xV8nXcU dQ== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3v4cxy7991-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 21 Dec 2023 06:28:40 +0000 Received: from m0353729.ppops.net (m0353729.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 3BL5s1BR006210; Thu, 21 Dec 2023 06:28:40 GMT Received: from ppma22.wdc07v.mail.ibm.com (5c.69.3da9.ip4.static.sl-reverse.com [169.61.105.92]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3v4cxy797j-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 21 Dec 2023 06:28:40 +0000 Received: from pps.filterd (ppma22.wdc07v.mail.ibm.com [127.0.0.1]) by ppma22.wdc07v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 3BL5lvQ7004828; Thu, 21 Dec 2023 06:28:38 GMT Received: from smtprelay02.fra02v.mail.ibm.com ([9.218.2.226]) by ppma22.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3v1pm03e56-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 21 Dec 2023 06:28:38 +0000 Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay02.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 3BL6SZ1P5440002 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 21 Dec 2023 06:28:35 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9604F20043; Thu, 21 Dec 2023 06:28:35 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A219F20040; Thu, 21 Dec 2023 06:28:33 +0000 (GMT) Received: from [9.197.228.79] (unknown [9.197.228.79]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP; Thu, 21 Dec 2023 06:28:33 +0000 (GMT) Message-ID: <342d3b13-c6eb-3ad0-92fd-0d1e4d8010fe@linux.ibm.com> Date: Thu, 21 Dec 2023 14:28:32 +0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0) Gecko/20100101 Thunderbird/91.6.1 Subject: Re: [Patchv3, 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: <138fd05a-75c8-4a4b-b358-9633e087da20@linux.ibm.com> From: "Kewen.Lin" In-Reply-To: <138fd05a-75c8-4a4b-b358-9633e087da20@linux.ibm.com> Content-Type: text/plain; charset=UTF-8 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: OwWJoxHAR96hz2aNUpm1awXdn61In5DG X-Proofpoint-ORIG-GUID: 3JEsJ8JTOjsv_iTvqET0_v4MTkwJBvgg 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-21_02,2023-12-20_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 suspectscore=0 phishscore=0 clxscore=1015 lowpriorityscore=0 malwarescore=0 bulkscore=0 impostorscore=0 spamscore=0 adultscore=0 priorityscore=1501 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2312210046 X-Spam-Status: No, score=-13.8 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, on 2023/12/21 09:37, 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. 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. > > Compared to last version, > https://gcc.gnu.org/pipermail/gcc-patches/2023-December/640833.html > the main change is to split optimization for size to a separate patch > and add a testcase for P7 BE. > > Bootstrapped and tested on x86 and powerpc64-linux BE and LE with no > regressions. Is this OK for trunk? OK, thanks! BR, Kewen > > Thanks > Gui Haochen > > ChangeLog > rs6000: Clean up the pre-checkings of expand_block_compare > > 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 is better than > library on P7 BE when the length is from 16 bytes to 64 bytes. > > gcc/ > * gcc/config/rs6000/rs6000-string.cc (expand_block_compare): Assert > only P7 above can enter this function. Remove P7 CPU test and let > P7 BE do the expand. > > gcc/testsuite/ > * gcc.target/powerpc/block-cmp-4.c: New. > > patch.diff > diff --git a/gcc/config/rs6000/rs6000-string.cc b/gcc/config/rs6000/rs6000-string.cc > index 5149273b80e..09db57255fa 100644 > --- a/gcc/config/rs6000/rs6000-string.cc > +++ b/gcc/config/rs6000/rs6000-string.cc > @@ -1947,15 +1947,12 @@ expand_block_compare_gpr(unsigned HOST_WIDE_INT bytes, unsigned int base_align, > bool > expand_block_compare (rtx operands[]) > { > + /* TARGET_POPCNTD is already guarded at expand cmpmemsi. */ > + gcc_assert (TARGET_POPCNTD); > + > if (optimize_insn_for_size_p ()) > return false; > > - rtx target = operands[0]; > - rtx orig_src1 = operands[1]; > - rtx orig_src2 = operands[2]; > - rtx bytes_rtx = operands[3]; > - rtx align_rtx = operands[4]; > - > /* 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. > @@ -1963,23 +1960,19 @@ expand_block_compare (rtx operands[]) > if (TARGET_32BIT && TARGET_POWERPC64) > 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)))) > - return false; > + rtx target = operands[0]; > + rtx orig_src1 = operands[1]; > + rtx orig_src2 = operands[2]; > + rtx bytes_rtx = operands[3]; > + rtx align_rtx = operands[4]; > > - /* 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) > + /* 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 > @@ -2027,14 +2020,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, base_align * BITS_PER_UNIT) > - && ((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-4.c b/gcc/testsuite/gcc.target/powerpc/block-cmp-4.c > new file mode 100644 > index 00000000000..c86febae68a > --- /dev/null > +++ b/gcc/testsuite/gcc.target/powerpc/block-cmp-4.c > @@ -0,0 +1,11 @@ > +/* { dg-do compile { target be } } */ > +/* { dg-options "-O2 -mdejagnu-cpu=power7" } */ > +/* { dg-final { scan-assembler-not {\mb[l]? memcmp\M} } } */ > + > +/* Test that it does expand for memcmpsi instead of calling library on > + P7 BE when length is less than 32 bytes. */ > + > +int foo (const char* s1, const char* s2) > +{ > + return __builtin_memcmp (s1, s2, 31); > +}