From patchwork Wed Oct 2 03:12:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 1991768 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=quicinc.com header.i=@quicinc.com header.a=rsa-sha256 header.s=qcppdkim1 header.b=gcqcboJG; 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 4XJKdD5yQzz1xsq for ; Wed, 2 Oct 2024 13:13:19 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A0677385F012 for ; Wed, 2 Oct 2024 03:13:09 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by sourceware.org (Postfix) with ESMTPS id 1F1B8385F012 for ; Wed, 2 Oct 2024 03:12:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1F1B8385F012 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=quicinc.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 1F1B8385F012 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.168.131 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1727838772; cv=none; b=hF8PcTCMgUUBMszm8kLjHhr0pTAqioD0r4JIqzubrLcv5EMoSVijrZ2dwLSj4PSpBfTRCU8ESsj0pfmYpJLBZcJWE5CgHdgi4Awgxu4W+3QlHT5dg44LCH9Y1Qh3WEraEbxb1hunpKOmX9OxKq+Ujkky+0tTF3EqN57/giKDo+U= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1727838772; c=relaxed/simple; bh=pOMt3GrnPnkyd07P8HNJ5RPljyaeiT5mgA0Gz4fIInY=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=n5FTNn05Mvm2mLOslHhFzdDuuY85QY5zN0fcqFZ5NlNPkxLEekky+abEZh1Gf03GzkClWF+ZZad7mPYi44xw7KFfjN7fByjWb1FXg8gn0+aDRPZ/nXvT1/O9VrJ3sUOgi3buI+Sq2uy6lcyHB4Oy7XPz30gMCbWV+LH9DnxXSf4= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0279864.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 491NVOs2021718 for ; Wed, 2 Oct 2024 03:12:50 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= cc:content-transfer-encoding:content-type:date:from:message-id :mime-version:subject:to; s=qcppdkim1; bh=ks/1U3gs+0TlGnBeI6I71U eQPXzrKvmJNUN7hfB/JrM=; b=gcqcboJGTPl7Q36N8rBbeGXYV5PIrv+icFt5cl OWNT5asiOYmDbsJJBZD44me0Vf/v9TiJ0MaTFIhvhXXFMiujdX14XVJA5wk5xq5q c7xAT4XRCNg1C3NZ4S00J1KvkY7tB+cmpKkOIlllIznNcdu48q8c9aLZw8o56RhG vxnBHhbE1Cy0m5S/18bHpiC0Y2DRxJqwYdQdMbDPut9FE0NgG1ZxKBPpoijbjCmm frGRzKuQ8AUBf8m/zChGvx/TOwhFDld1C1GOU/nz8ACLEsQLFc0I14CKq6eIVQQi jbftWgtRJetzcnDZT/XTefK6/kD0NSX86h69dkcfWxbPmKxg== Received: from nasanppmta04.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 41xaymjcnr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 02 Oct 2024 03:12:49 +0000 (GMT) Received: from nasanex01c.na.qualcomm.com (nasanex01c.na.qualcomm.com [10.45.79.139]) by NASANPPMTA04.qualcomm.com (8.18.1.2/8.18.1.2) with ESMTPS id 4923CnFk016897 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 2 Oct 2024 03:12:49 GMT Received: from hu-apinski-lv.qualcomm.com (10.49.16.6) by nasanex01c.na.qualcomm.com (10.45.79.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.9; Tue, 1 Oct 2024 20:12:48 -0700 From: Andrew Pinski To: CC: Andrew Pinski Subject: [PATCH] backprop: Fix deleting of a phi node [PR116922] Date: Tue, 1 Oct 2024 20:12:36 -0700 Message-ID: <20241002031236.1448655-1-quic_apinski@quicinc.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01a.na.qualcomm.com (10.47.209.196) To nasanex01c.na.qualcomm.com (10.45.79.139) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: K8y5M5tFAeQVSAh1442TH3yiqqKqqVfU X-Proofpoint-GUID: K8y5M5tFAeQVSAh1442TH3yiqqKqqVfU X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-06_09,2024-09-06_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 phishscore=0 mlxscore=0 adultscore=0 malwarescore=0 priorityscore=1501 impostorscore=0 clxscore=1015 bulkscore=0 lowpriorityscore=0 mlxlogscore=936 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2408220000 definitions=main-2410020022 X-Spam-Status: No, score=-13.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NONE, TXREP 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 The problem here is remove_unused_var is called on a name that is defined by a phi node but it deletes it like removing a normal statement. remove_phi_node should be called rather than gsi_remove for phinodes. Note there is a possibility of using simple_dce_from_worklist instead but that is for another day. Bootstrapped and tested on x86_64-linux-gnu. PR tree-optimization/116922 gcc/ChangeLog: * gimple-ssa-backprop.cc (remove_unused_var): Handle phi nodes correctly. gcc/testsuite/ChangeLog: * gcc.dg/torture/pr116922.c: New test. Signed-off-by: Andrew Pinski --- gcc/gimple-ssa-backprop.cc | 10 ++++++++-- gcc/testsuite/gcc.dg/torture/pr116922.c | 19 +++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/torture/pr116922.c diff --git a/gcc/gimple-ssa-backprop.cc b/gcc/gimple-ssa-backprop.cc index fe27ef51cdf..e3374b18138 100644 --- a/gcc/gimple-ssa-backprop.cc +++ b/gcc/gimple-ssa-backprop.cc @@ -663,8 +663,14 @@ remove_unused_var (tree var) print_gimple_stmt (dump_file, stmt, 0, TDF_SLIM); } gimple_stmt_iterator gsi = gsi_for_stmt (stmt); - gsi_remove (&gsi, true); - release_defs (stmt); + if (gimple_code (stmt) == GIMPLE_PHI) + remove_phi_node (&gsi, true); + else + { + unlink_stmt_vdef (stmt); + gsi_remove (&gsi, true); + release_defs (stmt); + } } /* Note that we're replacing OLD_RHS with NEW_RHS in STMT. */ diff --git a/gcc/testsuite/gcc.dg/torture/pr116922.c b/gcc/testsuite/gcc.dg/torture/pr116922.c new file mode 100644 index 00000000000..0fcf912930f --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr116922.c @@ -0,0 +1,19 @@ +/* { dg-do compile } */ +/* { dg-additional-options "-ffast-math" } */ +/* PR tree-optimization/116922 */ + + +static int g; + +void +foo (int c, double v, double *r) +{ +b: + do + v /= g - v; + while (c); + *r = v; + + double x; + foo (5, (double)0, &x); +}