From patchwork Thu Aug 1 20:39:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 95119 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 36FD63858430 for ; Thu, 1 Aug 2024 20:40:19 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by sourceware.org (Postfix) with ESMTPS id AB2DC3858D20 for ; Thu, 1 Aug 2024 20:39:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AB2DC3858D20 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 AB2DC3858D20 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.180.131 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722544790; cv=none; b=mXDs2gFs22sMPkRYV0b6QMVro1VzHnNLTBXNGxeTnI4SUPbAYgk1yMKt9Rn4LfvRRoMdMnlllieVV8soEnSKzBNJH5AOszDq9EpT5ErOh6CItG6Hanz2lDW0p082O0ej2CIxysTf+deI9LvcJg0GBb7PB3jTI5ZfJcsEadfFA1o= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722544790; c=relaxed/simple; bh=pJ5Kg4xEbZMqu/dnLNdt0zLORHf8mNrVihM36NxxItk=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=FTur0OHKKqFjZPRbn5PeIFfd+VE9KOoVCrTmjc+nMfJyscPJvjl+V0Z+kEhyNMPl1mBqjhiSFmewUS/qs0j/juguv6umBS5lxNB3LUPvaR4AqdinNPPFLyyyNuroaqD/SEc6cYR9G/SMIvgpHGPX5MzBGa5220+C64eYPWxoTLM= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0279871.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 471DaaBo004880 for ; Thu, 1 Aug 2024 20:39:46 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=tMBlfQvlXIs7wNhAGaXsYz EWOLVVI1Ey/rJIZS6EjQI=; b=eA0XCMfg38w5/ePQb9CY5s1dyMqxOr8cXS4SCi CTIHbEDuvE1otezG9K+2q0NBbYByndW9epX2BVcZex7IsjrQWTgyD1Qcnai0dWP4 Y8qDWSV9QrdY+XyQ/Seq8V3uJ//1KR5U5M4RULZVYx216KRjvISYv7KVYAXwSu5l F6U7F+ClQr2u26S/6Z1f3+WIZx9T6Ak18Iyf9J4WqONajUAKDMdGgiT9hOgaUDKl ULJv9p/NGCWYk/h4iW9lRF4s79VmZJ76sOj8jJM20f3C/vxjMselDR7xMSRnTF+3 n5ieS0+99Polafjge1vB+KeqPPI+SyhD+pCO2IH+AzdSp14Q== Received: from nasanppmta03.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 40pw459m19-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 01 Aug 2024 20:39:46 +0000 (GMT) Received: from nasanex01c.na.qualcomm.com (nasanex01c.na.qualcomm.com [10.45.79.139]) by NASANPPMTA03.qualcomm.com (8.17.1.19/8.17.1.19) with ESMTPS id 471Kdjes010544 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 1 Aug 2024 20:39:45 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; Thu, 1 Aug 2024 13:39:44 -0700 From: Andrew Pinski To: CC: Andrew Pinski Subject: [PATCH] forwprop: Don't add uses to dce list if debug statement [PR116156] Date: Thu, 1 Aug 2024 13:39:34 -0700 Message-ID: <20240801203934.1576508-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: nalasex01c.na.qualcomm.com (10.47.97.35) 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-GUID: hfyI_eao7g8cbAqOGI5pkPhmi5nGfC-o X-Proofpoint-ORIG-GUID: hfyI_eao7g8cbAqOGI5pkPhmi5nGfC-o 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-01_18,2024-08-01_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 priorityscore=1501 suspectscore=0 adultscore=0 clxscore=1015 impostorscore=0 malwarescore=0 lowpriorityscore=0 mlxlogscore=999 phishscore=0 bulkscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2407110000 definitions=main-2408010136 X-Spam-Status: No, score=-13.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, 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~patchwork=sourceware.org@gcc.gnu.org The problem here is that when forwprop does a copy prop, into a statement, we mark the uses of that statement as possibly need to be removed. But it just happened that statement was a debug statement, there will be a difference when compiling with debuging info turned on vs off; this is not expected. So the fix is not to add the old use to dce list to process if it was a debug statement. Bootstrapped and tested on x86_64-linux-gnu with no regressions. PR tree-optimization/116156 gcc/ChangeLog: * tree-ssa-forwprop.cc (pass_forwprop::execute): Don't add uses if the statement was a debug statement. gcc/testsuite/ChangeLog: * c-c++-common/torture/pr116156-1.c: New test. Signed-off-by: Andrew Pinski --- .../c-c++-common/torture/pr116156-1.c | 30 +++++++++++++++++++ gcc/tree-ssa-forwprop.cc | 16 +++++----- 2 files changed, 39 insertions(+), 7 deletions(-) create mode 100644 gcc/testsuite/c-c++-common/torture/pr116156-1.c diff --git a/gcc/testsuite/c-c++-common/torture/pr116156-1.c b/gcc/testsuite/c-c++-common/torture/pr116156-1.c new file mode 100644 index 00000000000..10f938ef4e5 --- /dev/null +++ b/gcc/testsuite/c-c++-common/torture/pr116156-1.c @@ -0,0 +1,30 @@ +/* { dg-additional-options "-fcompare-debug" } */ +/* PR tree-optimization/116156 */ + +/* Forwprop used to delete an unused statement + but only with debug statements around. */ + +struct jpeg_compress_struct { + int X_density; +}; +void gg(); +int h(const char*,const char*) __attribute((pure)); +int h1(const char*) __attribute((pure)); +int f1() __attribute__((returns_twice)); +void real_save_jpeg(char **keys, char *values) { + struct jpeg_compress_struct cinfo; + int x_density = 0; + while (*keys) + { + if (h1(*keys) == 0) + gg(); + if (h1(*keys) == 0) { + if (!*values) + x_density = -1; + if (x_density <= 0) + gg(); + } + } + if (f1()) + cinfo.X_density = x_density; +} diff --git a/gcc/tree-ssa-forwprop.cc b/gcc/tree-ssa-forwprop.cc index 44a6b5d39aa..2e37642359c 100644 --- a/gcc/tree-ssa-forwprop.cc +++ b/gcc/tree-ssa-forwprop.cc @@ -3923,7 +3923,8 @@ pass_forwprop::execute (function *fun) tree val = fwprop_ssa_val (use); if (val && val != use) { - bitmap_set_bit (simple_dce_worklist, SSA_NAME_VERSION (use)); + if (!is_gimple_debug (stmt)) + bitmap_set_bit (simple_dce_worklist, SSA_NAME_VERSION (use)); if (may_propagate_copy (use, val)) { propagate_value (usep, val); @@ -3963,12 +3964,13 @@ pass_forwprop::execute (function *fun) if (gimple_cond_true_p (cond) || gimple_cond_false_p (cond)) cfg_changed = true; - /* Queue old uses for simple DCE. */ - for (tree use : uses) - if (TREE_CODE (use) == SSA_NAME - && !SSA_NAME_IS_DEFAULT_DEF (use)) - bitmap_set_bit (simple_dce_worklist, - SSA_NAME_VERSION (use)); + /* Queue old uses for simple DCE if not debug statement. */ + if (!is_gimple_debug (stmt)) + for (tree use : uses) + if (TREE_CODE (use) == SSA_NAME + && !SSA_NAME_IS_DEFAULT_DEF (use)) + bitmap_set_bit (simple_dce_worklist, + SSA_NAME_VERSION (use)); } if (changed || substituted_p)