From patchwork Tue Mar 5 07:12:13 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: 1908039 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=jcznY2XJ; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; 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 [IPv6:2620:52:3:1:0:246e:9693:128c]) (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 4Tpmwy3Nkjz23qm for ; Tue, 5 Mar 2024 18:12:50 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 62B943858403 for ; Tue, 5 Mar 2024 07:12:48 +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 5D1DF3858CD1 for ; Tue, 5 Mar 2024 07:12:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5D1DF3858CD1 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 5D1DF3858CD1 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=1709622749; cv=none; b=xImgl5fE+idbQ8ZxS02Y74CmOTtFYzycGyELjrP/Yeux4zQgC0/nxmAeKRO7ywjhsFalb94hPLVKhAEV94MM9/+U8asqYWixNi2BJsa6LctNwQFjNmo28lSAWxCDJgLzMl6AZabCFP2O6QcfU01n9o/vTip62VuFnpxHK+hFMSE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709622749; c=relaxed/simple; bh=Kmz10RLadQgyguJV0N7bkMbDpXiRWohLE/LcgFEV9uY=; h=DKIM-Signature:Message-ID:Date:To:From:Subject:MIME-Version; b=wn8Xvu5Lhgz4UUgVORCdzV2YF+VE1F3/Q/6CpuZP155oF+O4uoHaqtiZNX4RbyKbsPVnmtAG9qToWPoPirak/u3PtWcfmdjJwKIzGGEoIvw9f0bL1F9/ckRJkZvPQwQdfFL68JYGKNRHdy8DzGsNv3vY+ILfpQWptOXTcociRBA= 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.17.1.19/8.17.1.19) with ESMTP id 4257CAaB015183; Tue, 5 Mar 2024 07:12:24 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=15vpmafBN+ClfbVGCXLz7/L2/N7bd8sqjKsd9sp0ztE=; b=jcznY2XJTT8CFWMlzxA8JlQXXjdQ14MyN6PxjYP9XQg93fuVVg+Eb+rzMDE586Ji/YXu IiU2GyeG3MMFCdc8qnOc9IpYPPazi1Vqf5BqNGqS44zjtS9lQevoqquS54Ywo8GrGW1/ jfrJXB/fgQk1y2z3EYqV/N7bg3Zc5Arj+zdG/uglav0BKc8Es7sbjilBRZr1AuoGqvU5 57B+Fd2ZjBCg5SN+Moo2gpBeMZkL6/n46BsIDY7eFfwLWNXLH+TGlTf1nJ3IusC1wBp7 1E4W6QwCiR+dEPXC59b/AddkqDEojJM2uAOq4KMB91RNvYBc1nJb9hkGywfAfg/PK0UJ sw== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3wnxsug03u-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 05 Mar 2024 07:12:23 +0000 Received: from m0360083.ppops.net (m0360083.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 4257CNjY015418; Tue, 5 Mar 2024 07:12:23 GMT Received: from ppma11.dal12v.mail.ibm.com (db.9e.1632.ip4.static.sl-reverse.com [50.22.158.219]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3wnxsug03b-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 05 Mar 2024 07:12:23 +0000 Received: from pps.filterd (ppma11.dal12v.mail.ibm.com [127.0.0.1]) by ppma11.dal12v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 4256JqYr010881; Tue, 5 Mar 2024 07:12:22 GMT Received: from smtprelay03.fra02v.mail.ibm.com ([9.218.2.224]) by ppma11.dal12v.mail.ibm.com (PPS) with ESMTPS id 3wmh525e76-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 05 Mar 2024 07:12:22 +0000 Received: from smtpav05.fra02v.mail.ibm.com (smtpav05.fra02v.mail.ibm.com [10.20.54.104]) by smtprelay03.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 4257CGEH35324392 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 5 Mar 2024 07:12:18 GMT Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 71A8C20040; Tue, 5 Mar 2024 07:12:16 +0000 (GMT) Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 7275720065; Tue, 5 Mar 2024 07:12:14 +0000 (GMT) Received: from [9.200.103.244] (unknown [9.200.103.244]) by smtpav05.fra02v.mail.ibm.com (Postfix) with ESMTP; Tue, 5 Mar 2024 07:12:14 +0000 (GMT) Message-ID: Date: Tue, 5 Mar 2024 15:12:13 +0800 User-Agent: Mozilla Thunderbird Content-Language: en-US To: gcc-patches Cc: Segher Boessenkool , David , "Kewen.Lin" , Peter Bergner , Richard Sandiford , Jeff Law From: HAO CHEN GUI Subject: [PATCHv2] fwprop: Avoid volatile defines to be propagated X-TM-AS-GCONF: 00 X-Proofpoint-GUID: NDCRj4X1iISQr9frGfi9gEoQRKnDBLfY X-Proofpoint-ORIG-GUID: RPrDeS4ueZfWW4VTbVSBg6k5hmICmn4- 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.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-03-05_04,2024-03-04_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1011 adultscore=0 priorityscore=1501 malwarescore=0 mlxlogscore=916 spamscore=0 bulkscore=0 lowpriorityscore=0 impostorscore=0 phishscore=0 suspectscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2403050055 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, 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 tries to fix a potential problem which is raised by the patch for PR111267. The volatile asm operand tries to be propagated to a single set insn with the patch for PR111267. The volatile asm operand might be executed for multiple times if the define insn isn't eliminated after propagation. Now set_src_cost comparison might reject such propagation. But it has the chance to be taken after replacing set_src_cost with insn cost. Actually I found the problem in testing my patch which replacing set_src_cost with insn_cost in fwprop pass. Compared to the last version, the check volatile_insn_p is replaced with volatile_refs_p in order to check volatile memory reference also. https://gcc.gnu.org/pipermail/gcc-patches/2024-February/646482.html Bootstrapped and tested on x86 and powerpc64-linux BE and LE with no regressions. Is it OK for the trunk? Thanks Gui Haochen ChangeLog fwprop: Avoid volatile defines to be propagated The patch for PR111267 (commit id 86de9b66480b710202a2898cf513db105d8c432f) which introduces an exception for propagation on single set insn. The propagation which might not be profitable (checked by profitable_p) is still allowed to be propagated to single set insn. It has a potential problem that a volatile operand might be propagated to a single set insn. If the define insn is not eliminated after propagation, the volatile operand will be executed for multiple times. This patch fixes the problem by skipping volatile set source rtx in propagation. gcc/ * fwprop.cc (forward_propagate_into): Return false for volatile set source rtx. gcc/testsuite/ * gcc.target/powerpc/fwprop-1.c: New. patch.diff diff --git a/gcc/fwprop.cc b/gcc/fwprop.cc index 7872609b336..cb6fd6700ca 100644 --- a/gcc/fwprop.cc +++ b/gcc/fwprop.cc @@ -854,6 +854,8 @@ forward_propagate_into (use_info *use, bool reg_prop_only = false) rtx dest = SET_DEST (def_set); rtx src = SET_SRC (def_set); + if (volatile_refs_p (src)) + return false; /* Allow propagations into a loop only for reg-to-reg copies, since replacing one register by another shouldn't increase the cost. diff --git a/gcc/testsuite/gcc.target/powerpc/fwprop-1.c b/gcc/testsuite/gcc.target/powerpc/fwprop-1.c new file mode 100644 index 00000000000..07b207f980c --- /dev/null +++ b/gcc/testsuite/gcc.target/powerpc/fwprop-1.c @@ -0,0 +1,15 @@ +/* { dg-do compile } */ +/* { dg-options "-O1 -fdump-rtl-fwprop1-details" } */ +/* { dg-final { scan-rtl-dump-not "propagating insn" "fwprop1" } } */ + +/* Verify that volatile asm operands doesn't be propagated. */ +long long foo () +{ + long long res; + __asm__ __volatile__( + "" + : "=r" (res) + : + : "memory"); + return res; +}