From patchwork Mon Feb 26 03:30:12 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: 1904064 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=OJmJVOZr; 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 4TjmNR3q8Bz23qD for ; Mon, 26 Feb 2024 14:30:47 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 928003858C3A for ; Mon, 26 Feb 2024 03:30:45 +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 2688A3858D1E for ; Mon, 26 Feb 2024 03:30:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2688A3858D1E 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 2688A3858D1E 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=1708918230; cv=none; b=vKPEkHXnIR1KliM6MRX4Nd9ECw6HCajmNpeTGNWxG1N4fySbTJDQLmp3ZXUsJxFujCPEXj+CxJhRO8L49D78NqnDg37NHKMdCwg4XeNwCeSNzuKBQWnmr0sbqSM9uLamczLzMl2/eBUdzvd/xiBva+buoncgAiFAAsd1dfCjw6U= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708918230; c=relaxed/simple; bh=ZqazHKYbUvSofswJduHaiq/WIDr8LDbCf+4dWtOq9cY=; h=DKIM-Signature:Message-ID:Date:MIME-Version:To:From:Subject; b=Kgx3lgomnZ2gnOJ7l0bKtQflJztedbBp+xmvHsWaPUI/O9IsPeJHGUdYaq+WqQfnDkCR9jmpZirXJ5gfrYdeKAxznk1KZ/rO42xMx+BKth6T+kqmq0mjJCrkyxWlpeLZf93OEYmMMVtok4TmAnwsn19INe7RG1Fdls7bfvJe9ug= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0353728.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 41Q0Vqwf019827; Mon, 26 Feb 2024 03:30:23 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=message-id : date : mime-version : to : cc : from : subject : content-type : content-transfer-encoding; s=pp1; bh=nKK/zT0SkF7tOh/jVEGSSwMu08IAtNQkfqdgCgEknSU=; b=OJmJVOZrOHQE7eb53O6geZK/qvY4hog7686jkYARD1XPnvjlifMfEl3G3YowegSQwSpt 8mDAUvBJ0l6SLsDquoOHuY5Cv3BMgVZJAvZQN8YBQrZQGqsSr4Z9vGT1KHClkp5UgnKC I702Ef/Y5Qku/yx4YMlQYeAzt1D4y/fpYQzU0fQnpGIR7GHNnTFyGa/TOAD+yKJcPvyR JN0zrpUWSIqxxhVliGF1AtVdb4GjOmXtRloT2IYdMJj+MysbY9hqTD8jQwf7FhZAAhbQ wc4Y4gYXz6Mt+XEOY7x2C0u0oXdAmHWp/1MlotTAhPLvo7DlVcDHG5/sHWNktTzkF+sq Cg== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3wff352ghh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 26 Feb 2024 03:30:23 +0000 Received: from m0353728.ppops.net (m0353728.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 41Q3GxWP012985; Mon, 26 Feb 2024 03:30:22 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 3wff352ggv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 26 Feb 2024 03:30:22 +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 41Q35rQV024154; Mon, 26 Feb 2024 03:30:21 GMT Received: from smtprelay03.fra02v.mail.ibm.com ([9.218.2.224]) by ppma13.dal12v.mail.ibm.com (PPS) with ESMTPS id 3wfw0jx38n-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 26 Feb 2024 03:30:21 +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 41Q3UGL22359930 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 26 Feb 2024 03:30:18 GMT Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2383D2007C; Mon, 26 Feb 2024 03:30:16 +0000 (GMT) Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 051572004E; Mon, 26 Feb 2024 03:30:14 +0000 (GMT) Received: from [9.197.226.11] (unknown [9.197.226.11]) by smtpav05.fra02v.mail.ibm.com (Postfix) with ESMTP; Mon, 26 Feb 2024 03:30:13 +0000 (GMT) Message-ID: <22dddcdd-d739-4c6d-8da7-d59be94c435f@linux.ibm.com> Date: Mon, 26 Feb 2024 11:30:12 +0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US To: gcc-patches Cc: Segher Boessenkool , David , "Kewen.Lin" , Peter Bergner , Richard Sandiford From: HAO CHEN GUI Subject: [PATCH] fwprop: Avoid volatile defines to be propagated X-TM-AS-GCONF: 00 X-Proofpoint-GUID: vFgiAg1AL7pYMZ-zUlbDuo9M3CdFI--n X-Proofpoint-ORIG-GUID: jqce1Ae51ufSEteZRtHNT8rfNwyAioji 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-02-26_01,2024-02-23_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 bulkscore=0 adultscore=0 suspectscore=0 clxscore=1015 mlxscore=0 spamscore=0 impostorscore=0 phishscore=0 lowpriorityscore=0 mlxlogscore=737 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402260025 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 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. It has potential risk as the behavior is wrong. Currently set_src_cost comparison can reject such propagation. But the propagation might be taken after replacing set_src_cost with insn cost. Actually I found the problem in testing my patch which replacing et_src_cost with insn cost for fwprop. 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 asm operand will try to be propagated to a single set insn. The volatile asm operand is originally banned in profitable_p. This patch fixes the problem by skipping volatile set source in define set finding. gcc/ * fwprop.cc (forward_propagate_into): Return false for volatile set source. gcc/testsuite/ * gcc.target/powerpc/fwprop-1.c: New. patch.diff diff --git a/gcc/fwprop.cc b/gcc/fwprop.cc index 7872609b336..89dce88b43d 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_insn_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 try to be propagated. */ +long long foo () +{ + long long res; + __asm__ __volatile__( + "" + : "=r" (res) + : + : "memory"); + return res; +}