From patchwork Mon Aug 19 02:20:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: HAO CHEN GUI X-Patchwork-Id: 1973635 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=afdlXt0l; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WnGYX2qZDz1yXZ for ; Mon, 19 Aug 2024 12:21:20 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 901623850203 for ; Mon, 19 Aug 2024 02:21:18 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by sourceware.org (Postfix) with ESMTPS id 8B392386183A for ; Mon, 19 Aug 2024 02:20:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8B392386183A 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 8B392386183A 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=1724034051; cv=none; b=CauLxt4w9iepDuBtFXs8cd3xn6jo+0gM/lcm1rtrGEC6EbDhRFweKFObC6ahMbi5eqLF0Iwh6ZPMRtGdC43PYxEfZs1nPH8e6btg+FgS2WnsuYim0rcAjOS3wuI9m3pWpspbdNGjWt7SJ/VeIJxYfYqw3nwb7NlyPECdCu/56vI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1724034051; c=relaxed/simple; bh=fanaVsfsz0440/8R/B+KXsVGxqfAb524DDiMiPsGx1I=; h=DKIM-Signature:Message-ID:Date:To:From:Subject:MIME-Version; b=YtBcU0ibGCHr3btk66v/qesNcBXX2nrwcnV4wBg2pOSAY63HbGEUgWXNO36DxqNpxEgO3xVqRkQQ2OjJVso3In/iJnD1WVdNbLtaB87atxpLRLjTV+jKfzfepm7YSpMQUvYml2uRLpwPC6WRQnxa4a5mqvbrzWzFNiIoiJsDB0k= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0360083.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 47J08luI007282; Mon, 19 Aug 2024 02:20:45 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h= message-id:date:to:cc:from:subject:content-type :content-transfer-encoding:mime-version; s=pp1; bh=CYzDMYsPFBvmn rZjHveyJBPJVNeqxbW20+UN2oVMoxs=; b=afdlXt0l5g1Y1HNydSFq2LgGcelH0 gSbhCT2jH+ctcxhySmDyHwPXgK6DU42TNXG2zAYqG6mn2BaXzQGf/xsS6gIQVYAV LGlO4Zn0L+IAKtACmWuRp5rHrD7GBM8qaWGB8V60A3YfxCLe/6U8h3Wc4i/ZePKY 33VGAtL16/F+nlMJjPKV9PVD9NBvL8/zlgvI4AmEpU1rTM3mXLxv1LLMhANwD4k0 TKooNSTRt0lv5oMEe9mDwQM0qEdOiWK+GY06eGccVJOY9wCNPiHlO4r62yWP7mVy yzldwxRqbeChqFXVwcIFBF6BxpWEbyIhavyQhnpfxgWwGnPr7H36t08Rg== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 412mb5eknc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 19 Aug 2024 02:20:45 +0000 (GMT) Received: from m0360083.ppops.net (m0360083.ppops.net [127.0.0.1]) by pps.reinject (8.18.0.8/8.18.0.8) with ESMTP id 47J2Ki4P009402; Mon, 19 Aug 2024 02:20:44 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 412mb5ekn9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 19 Aug 2024 02:20:44 +0000 (GMT) Received: from pps.filterd (ppma13.dal12v.mail.ibm.com [127.0.0.1]) by ppma13.dal12v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 47INq1uX029710; Mon, 19 Aug 2024 02:20:43 GMT Received: from smtprelay05.fra02v.mail.ibm.com ([9.218.2.225]) by ppma13.dal12v.mail.ibm.com (PPS) with ESMTPS id 4138dm3xhd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 19 Aug 2024 02:20:43 +0000 Received: from smtpav04.fra02v.mail.ibm.com (smtpav04.fra02v.mail.ibm.com [10.20.54.103]) by smtprelay05.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 47J2KcIL47513994 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 19 Aug 2024 02:20:40 GMT Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5236020040; Mon, 19 Aug 2024 02:20:38 +0000 (GMT) Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2620420043; Mon, 19 Aug 2024 02:20:35 +0000 (GMT) Received: from [9.200.48.134] (unknown [9.200.48.134]) by smtpav04.fra02v.mail.ibm.com (Postfix) with ESMTP; Mon, 19 Aug 2024 02:20:34 +0000 (GMT) Message-ID: Date: Mon, 19 Aug 2024 10:20:33 +0800 User-Agent: Mozilla Thunderbird Content-Language: en-US To: gcc-patches Cc: Segher Boessenkool , David , "Kewen.Lin" , Peter Bergner , Jeff Law , Richard Sandiford From: HAO CHEN GUI Subject: [PATCHv4, expand] Add const0 move checking for CLEAR_BY_PIECES optabs X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: 1WKfxWJBekW94NBcSy5fSlic3Eyh4eqo X-Proofpoint-GUID: 3dOM6Rt_p27QpDEceJYio2sCMwvRfSWC X-Proofpoint-UnRewURL: 0 URL was un-rewritten MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-08-18_24,2024-08-16_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 spamscore=0 priorityscore=1501 adultscore=0 bulkscore=0 impostorscore=0 malwarescore=0 mlxlogscore=999 phishscore=0 mlxscore=0 lowpriorityscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2407110000 definitions=main-2408190014 X-Spam-Status: No, score=-12.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_MSPIKE_H3, 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org Hi, This patch adds const0 move checking for CLEAR_BY_PIECES. The original vec_duplicate handles duplicates of non-constant inputs. But 0 is a constant. So even a platform doesn't support vec_duplicate, it could still do clear by pieces if it supports const0 move by that mode. Compared to the previous version, the main change is to set up a new function to generate const0 for certain modes and use the function as by_pieces_constfn for CLEAR_BY_PIECES. https://gcc.gnu.org/pipermail/gcc-patches/2024-August/660344.html Bootstrapped and tested on powerpc64-linux BE and LE with no regressions. On i386, it got several regressions. One issue is the predicate of V16QI move expand doesn't include const0. Thus V16QI mode can't be used for clear by pieces with the patch. The second issue is the const0 is passed directly to the move expand with the patch. Originally it is forced to a pseudo and i386 can leverage the previous data to do optimization. The patch also raises several regressions on aarch64. The V2x8QImode replaces TImode to do 16-byte clear by pieces as V2x8QImode move expand supports const0 and vector mode is preferable. I drafted a patch to address the issue. It will be sent for review in a separate email. Another problem is V8QImode replaces DImode to do 8-byte clear by pieces. It seems cause different sequences of instructions but the actually instructions are the same. Thanks Gui Haochen ChangeLog expand: Add const0 move checking for CLEAR_BY_PIECES optabs vec_duplicate handles duplicates of non-constant inputs. The 0 is a constant. So even a platform doesn't support vec_duplicate, it could still do clear by pieces if it supports const0 move. This patch adds the checking. gcc/ * expr.cc (by_pieces_mode_supported_p): Add const0 move checking for CLEAR_BY_PIECES. (set_zero): New. (clear_by_pieces): Pass set_zero as by_pieces_constfn. patch.diff diff --git a/gcc/expr.cc b/gcc/expr.cc index ffbac513692..7199e0956f8 100644 --- a/gcc/expr.cc +++ b/gcc/expr.cc @@ -1014,14 +1014,20 @@ can_use_qi_vectors (by_pieces_operation op) static bool by_pieces_mode_supported_p (fixed_size_mode mode, by_pieces_operation op) { - if (optab_handler (mov_optab, mode) == CODE_FOR_nothing) + enum insn_code icode = optab_handler (mov_optab, mode); + if (icode == CODE_FOR_nothing) return false; - if ((op == SET_BY_PIECES || op == CLEAR_BY_PIECES) + if (op == SET_BY_PIECES && VECTOR_MODE_P (mode) && optab_handler (vec_duplicate_optab, mode) == CODE_FOR_nothing) return false; + if (op == CLEAR_BY_PIECES + && VECTOR_MODE_P (mode) + && !insn_operand_matches (icode, 1, CONST0_RTX (mode))) + return false; + if (op == COMPARE_BY_PIECES && !can_compare_p (EQ, mode, ccp_jump)) return false; @@ -1840,16 +1846,20 @@ store_by_pieces (rtx to, unsigned HOST_WIDE_INT len, return to; } +static rtx +set_zero (void *, void *, HOST_WIDE_INT, fixed_size_mode mode) +{ + return CONST0_RTX (mode); +} + void clear_by_pieces (rtx to, unsigned HOST_WIDE_INT len, unsigned int align) { if (len == 0) return; - /* Use builtin_memset_read_str to support vector mode broadcast. */ - char c = 0; - store_by_pieces_d data (to, builtin_memset_read_str, &c, len, align, - CLEAR_BY_PIECES); + /* Use set_zero to generate const0 of centain mode. */ + store_by_pieces_d data (to, set_zero, NULL, len, align, CLEAR_BY_PIECES); data.run (); }