From patchwork Thu Oct 3 16:08: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: 1992424 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=VLcONNb7; 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 4XKGp72dgrz1xtk for ; Fri, 4 Oct 2024 02:09:16 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CBD843846423 for ; Thu, 3 Oct 2024 16:09:13 +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 09D90385DC3C for ; Thu, 3 Oct 2024 16:08:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 09D90385DC3C 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 09D90385DC3C 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=1727971732; cv=none; b=dq21OXapuK/aoKk1jNPmO0GKr0FNoCh0pZtvbdyNSxzMf6fJjKZdkX4vkI2LLBGj4YEUvvc89gzYrl+IkCB2qxhJYLjyKw/YStTd1Kzx1DySpn43Ny7e9vhi86lk/x9al8Ip8aFeFthT/NiJ+ZkyTgEHJqBzyJUa009t07JuwwU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1727971732; c=relaxed/simple; bh=hpXREUNr2Dc80qnLRKQHmw1alitCW5/BQbtY8KwLzmY=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=T/qIiHG6GELmvfixJe/wqgEfRoM/nktj3u7PeENQAF38GSQYW26GvXuJOkptYxlieQsPL3UWetI6hVZiIQ6AI5kKEt8IDm/PrOrLlaYvAzrIEerTmd2vupaFtPxWQ7ThwDqRXl9hfUI6IGM3d/hrPVPftavDz+NQWxwrBdaahK4= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0279865.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4939OjlC021918 for ; Thu, 3 Oct 2024 16:08: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=0CPBPHAAfmu9XojINlRSdm fiymhp6VpRdqvyzELJH8Y=; b=VLcONNb7MQyAiEWBVp5BfWGAR/KcsrAzr2moS/ RYA76ABK2mAuleq7TTM57s8Z4pbGR+i8mRx6dx/8xN1+Vuh8SgJTkdTKXxcPyMuG n12ito8AEAcJa+xn+x9yFD9r+PQKKJG5pIYutowiw87S7Sc6z2R+PmTt2nBmEIs5 NVJaKI2mr3/HHup49JP1lLgiJscxsoYZhtC/3OclQsuzxJBvSBKQPGWBCIT2lYZu b/JNsig8o796U3GMxbkA7IYgUGuz9DeP9H6LquAp3jJcd6b9USbiqiAtZEffYWKr uM428tcNWzYAqA7/4YePFRgFZc8UThOxa7XOxhgNxmdfBVgw== Received: from nasanppmta02.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 41yprau8yy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 03 Oct 2024 16:08:49 +0000 (GMT) Received: from nasanex01c.na.qualcomm.com (nasanex01c.na.qualcomm.com [10.45.79.139]) by NASANPPMTA02.qualcomm.com (8.18.1.2/8.18.1.2) with ESMTPS id 493G8mR6030138 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 3 Oct 2024 16:08: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; Thu, 3 Oct 2024 09:08:48 -0700 From: Andrew Pinski To: CC: Andrew Pinski Subject: [PATCH 1/3] cfgexpand: Expand comment on when non-var clobbers can show up Date: Thu, 3 Oct 2024 09:08:34 -0700 Message-ID: <20241003160836.2297144-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: tdqWuAFtzQL8yoVkZHTFXyXGx5N5nLhh X-Proofpoint-ORIG-GUID: tdqWuAFtzQL8yoVkZHTFXyXGx5N5nLhh 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 lowpriorityscore=0 malwarescore=0 spamscore=0 mlxscore=0 phishscore=0 impostorscore=0 clxscore=1015 adultscore=0 mlxlogscore=689 bulkscore=0 priorityscore=1501 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2408220000 definitions=main-2410030117 X-Spam-Status: No, score=-14.0 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 comment here is not wrong, just it would be better if mentioning the C++ front-end instead of just the nested function lowering. gcc/ChangeLog: * cfgexpand.cc (add_scope_conflicts_1): Expand comment on when non-var clobbers show up. Signed-off-by: Andrew Pinski --- gcc/cfgexpand.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/gcc/cfgexpand.cc b/gcc/cfgexpand.cc index f32cf1b20c9..6c1096363af 100644 --- a/gcc/cfgexpand.cc +++ b/gcc/cfgexpand.cc @@ -639,8 +639,9 @@ add_scope_conflicts_1 (basic_block bb, bitmap work, bool for_conflict) { tree lhs = gimple_assign_lhs (stmt); unsigned *v; - /* Nested function lowering might introduce LHSs - that are COMPONENT_REFs. */ + /* Handle only plain var clobbers. + Nested functions lowering and C++ front-end inserts clobbers + which are not just plain variables. */ if (!VAR_P (lhs)) continue; if (DECL_RTL_IF_SET (lhs) == pc_rtx From patchwork Thu Oct 3 16:08:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 1992425 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=JMFTWwtK; 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 4XKGp72NMLz1xsn for ; Fri, 4 Oct 2024 02:09:18 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 68D86384A46E for ; Thu, 3 Oct 2024 16:09:14 +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 53E55385DDD1 for ; Thu, 3 Oct 2024 16:08:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 53E55385DDD1 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 53E55385DDD1 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=1727971732; cv=none; b=pvlAui/7HC+67hUoD6L+DDEGjrXEgnhz2UkHS1+7LXdr2nKg2K7ZWXe6R7MCk+cr2Ju1uBCNocy0F3Wl7RTkIVPCHkLlZK3YnFXcjU9BqbrOYfRtKb6XWfs4EVCUpFH/aXNspKoVTmlaQiEPSV+B6x/vhGG12NbDoCytUUawI/c= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1727971732; c=relaxed/simple; bh=BzOkQ+/jnZCbEo5ZJ8CqzkcOXF/Mj84feciXQUKpj/g=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=Exe+4gaYd4vpAnulJ6gJYMWQsjE7wxjqFUEXW6l9FyM2PihLH6PmQQarU5WJPWY67KGDKvbe21pOuF3gJSUWIY/3Ux75gl31JjEZ9QfOypF0vGpvQoCEyX50Chkgg6vgJVhAebzgDTxR5FYCmnzg6J8CuRmThYVxzvchYIaE50M= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0279868.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4939Oquk001139 for ; Thu, 3 Oct 2024 16:08:50 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= OkG1XpC5L7Bjb15nA9z9A8IrWjEpravkimNWZpk0x8U=; b=JMFTWwtK7nm2o1F9 UZhPpGDYV3k+Gr0PybFd18haJYlHIi/nV3QVTJR61AEAPHWQoIE/Yq/6wOSlGAxP 2NxDftRQnTMKvgcFmGBfWmKuB4jjScO9tOxc0zdI7JVmxbKeVzxQ4Lt8D8CaMF28 Ln0yfeUVCJt9wI2l2VDmS8pmGSIVzTYhT327fBqgcrHs03VcKkz9wN2DjLF8pwuC jIC03AnknDA/+7/VrTmGH1OfY5ndVMiBFFjhlaOv3YGtc2gJAVH7POyBLT1pcNtM ZcEb7Uus8NXQu2l3rQ2R/Rmifs6ica1ggnfy5cdG8eCdhpjDzZCHWe1AQ7Qo6lDN 18F3JQ== Received: from nasanppmta02.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 41x94hpx7x-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 03 Oct 2024 16:08:50 +0000 (GMT) Received: from nasanex01c.na.qualcomm.com (nasanex01c.na.qualcomm.com [10.45.79.139]) by NASANPPMTA02.qualcomm.com (8.18.1.2/8.18.1.2) with ESMTPS id 493G8n5r030145 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 3 Oct 2024 16:08: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; Thu, 3 Oct 2024 09:08:48 -0700 From: Andrew Pinski To: CC: Andrew Pinski Subject: [PATCH 2/3] cfgexpand: Handle scope conflicts better [PR111422] Date: Thu, 3 Oct 2024 09:08:35 -0700 Message-ID: <20241003160836.2297144-2-quic_apinski@quicinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241003160836.2297144-1-quic_apinski@quicinc.com> References: <20241003160836.2297144-1-quic_apinski@quicinc.com> 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: KXqu5klIyEKBWZ0JQvKvhjNzEpsk87G1 X-Proofpoint-ORIG-GUID: KXqu5klIyEKBWZ0JQvKvhjNzEpsk87G1 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 clxscore=1015 phishscore=0 mlxscore=0 malwarescore=0 mlxlogscore=695 priorityscore=1501 impostorscore=0 lowpriorityscore=0 adultscore=0 bulkscore=0 suspectscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2408220000 definitions=main-2410030117 X-Spam-Status: No, score=-14.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, 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 After fixing loop-im to do the correct overflow rewriting for pointer types too. We end up with code like: ``` _9 = (unsigned long) &g; _84 = _9 + 18446744073709551615; _11 = _42 + _84; _44 = (signed char *) _11; ... *_44 = 10; g ={v} {CLOBBER(eos)}; ... n[0] = &f; *_44 = 8; g ={v} {CLOBBER(eos)}; ``` Which was not being recongized by the scope conflicts code. This was because it only handled one level walk backs rather than multiple ones. This fixes it by using a work_list to avoid huge recursion and a visited bitmape to avoid going into an infinite loops when dealing with loops. Bootstrapped and tested on x86_64-linux-gnu. PR tree-optimization/111422 gcc/ChangeLog: * cfgexpand.cc (add_scope_conflicts_2): Rewrite to be a full walk of all operands and their uses. Signed-off-by: Andrew Pinski --- gcc/cfgexpand.cc | 46 +++++++++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/gcc/cfgexpand.cc b/gcc/cfgexpand.cc index 6c1096363af..2e653d7207c 100644 --- a/gcc/cfgexpand.cc +++ b/gcc/cfgexpand.cc @@ -573,32 +573,40 @@ visit_conflict (gimple *, tree op, tree, void *data) /* Helper function for add_scope_conflicts_1. For USE on a stmt, if it is a SSA_NAME and in its SSA_NAME_DEF_STMT is known to be - based on some ADDR_EXPR, invoke VISIT on that ADDR_EXPR. */ + based on some ADDR_EXPR, invoke VISIT on that ADDR_EXPR. Also walk + the assignments backwards as they might be based on an ADDR_EXPR. */ -static inline void +static void add_scope_conflicts_2 (tree use, bitmap work, walk_stmt_load_store_addr_fn visit) { - if (TREE_CODE (use) == SSA_NAME - && (POINTER_TYPE_P (TREE_TYPE (use)) - || INTEGRAL_TYPE_P (TREE_TYPE (use)))) + auto_vec work_list; + auto_bitmap visited_ssa_names; + work_list.safe_push (use); + + while (!work_list.is_empty()) { - gimple *g = SSA_NAME_DEF_STMT (use); - if (gassign *a = dyn_cast (g)) + use = work_list.pop(); + if (!use) + continue; + if (TREE_CODE (use) == ADDR_EXPR) + visit (nullptr, TREE_OPERAND (use, 0), use, work); + else if (TREE_CODE (use) == SSA_NAME + && (POINTER_TYPE_P (TREE_TYPE (use)) + || INTEGRAL_TYPE_P (TREE_TYPE (use)))) { - if (tree op = gimple_assign_rhs1 (a)) - if (TREE_CODE (op) == ADDR_EXPR) - visit (a, TREE_OPERAND (op, 0), op, work); + gimple *g = SSA_NAME_DEF_STMT (use); + if (!bitmap_set_bit (visited_ssa_names, SSA_NAME_VERSION(use))) + continue; + if (gassign *a = dyn_cast (g)) + { + for (unsigned i = 1; i < gimple_num_ops (g); i++) + work_list.safe_push (gimple_op (a, i)); + } + else if (gphi *p = dyn_cast (g)) + for (unsigned i = 0; i < gimple_phi_num_args (p); ++i) + work_list.safe_push (gimple_phi_arg_def (p, i)); } - else if (gphi *p = dyn_cast (g)) - for (unsigned i = 0; i < gimple_phi_num_args (p); ++i) - if (TREE_CODE (use = gimple_phi_arg_def (p, i)) == SSA_NAME) - if (gassign *a = dyn_cast (SSA_NAME_DEF_STMT (use))) - { - if (tree op = gimple_assign_rhs1 (a)) - if (TREE_CODE (op) == ADDR_EXPR) - visit (a, TREE_OPERAND (op, 0), op, work); - } } } From patchwork Thu Oct 3 16:08: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: 1992426 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=VRKaqVYr; 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 4XKGpB26gkz1xsn for ; Fri, 4 Oct 2024 02:09:22 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 247E8384642B for ; Thu, 3 Oct 2024 16:09:20 +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 7C0EF385DDDE for ; Thu, 3 Oct 2024 16:08:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7C0EF385DDDE 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 7C0EF385DDDE 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=1727971734; cv=none; b=GnP1qCaxOdOsn88S6EsoBcAqiPpuE5SDyrDyUtXVfgRDu/WAMyd6yXlBAv2sOJzpnNoFJZa6oDoTjUjBYn+NBtrOu+POcFoKjUMi5gWpniUAZqMvjdOOfKQev/fqJxHLgj6VpQiFZ2AClkmYi+7lc9IMgfe6oDKYtgQMSZEBtck= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1727971734; c=relaxed/simple; bh=gs+JCI0peJJe7MoffAu5ZR+kkrn/GoBloQck/kvvoCg=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=lEVIyVt1qIytdvydqq+hACN97PpvOfj4U/kSkNspL5Z/Ca8V8kuEi4SgAKuFscus2EC+bf/Q4lwiOMQmcXMm83acXC6chq/yhx4+UpFiuH4+0M11c7N57/qle1pu4vFx4/5hZuVd95QDier2Ofszu1RHg5wQZszfPuZFC56fvnQ= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0279870.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4939OioU025680 for ; Thu, 3 Oct 2024 16:08:51 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= z40cdrV1pyMZoApjMymkiREHP7sDcYTrLmCqGFjCzdg=; b=VRKaqVYrFXRfQU58 Co16JoDmhoq+iEQGHe33yio/JvXGdY/cEcByRskz9ctDIbxcp3xhkfRRF+MpUplA lgfLhK9rmXEafEDM4eKcRtkDIDfv7ClA5nYLcpt9nLuWgiHecGP7j+WgTNA76WeQ 1rk4PyET852PzHJParC/R5Pb5ghExP5miCr4GshA2619VPP/QgNC/rWGaM4lMl15 1uU/TUNc9mTbCIgFquswxPYGe5miaEjvyQqC3GY5d68KYUBClFKbKgFszE4SYJf8 79y+U8rOEd9SQAcboeZXccTDgyNMAQMKLuF4KVqL6KwCcG5gd+bOGI3KCfMBldUz qsiuzg== Received: from nasanppmta02.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 41x9vuexk2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 03 Oct 2024 16:08:50 +0000 (GMT) Received: from nasanex01c.na.qualcomm.com (nasanex01c.na.qualcomm.com [10.45.79.139]) by NASANPPMTA02.qualcomm.com (8.18.1.2/8.18.1.2) with ESMTPS id 493G8nwA030149 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 3 Oct 2024 16:08: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; Thu, 3 Oct 2024 09:08:49 -0700 From: Andrew Pinski To: CC: Andrew Pinski Subject: [PATCH 3/3] gimple: Add gimple_with_undefined_signed_overflow and use it [PR111276] Date: Thu, 3 Oct 2024 09:08:36 -0700 Message-ID: <20241003160836.2297144-3-quic_apinski@quicinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241003160836.2297144-1-quic_apinski@quicinc.com> References: <20241003160836.2297144-1-quic_apinski@quicinc.com> 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: REE68CiDQatzir6MI9yfVRe-7iZvZnj0 X-Proofpoint-ORIG-GUID: REE68CiDQatzir6MI9yfVRe-7iZvZnj0 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 bulkscore=0 mlxlogscore=999 lowpriorityscore=0 clxscore=1015 spamscore=0 suspectscore=0 phishscore=0 priorityscore=1501 malwarescore=0 adultscore=0 mlxscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2408220000 definitions=main-2410030117 X-Spam-Status: No, score=-14.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, 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 While looking into the ifcombine, I noticed that rewrite_to_defined_overflow was rewriting already defined code. In the previous attempt at fixing this, the review mentioned we should not be calling rewrite_to_defined_overflow in those cases. The places which called rewrite_to_defined_overflow didn't always check the lhs of the assignment. This fixes the problem by introducing a helper function which is to be used before calling rewrite_to_defined_overflow. Bootstrapped and tested on x86_64-linux-gnu. gcc/ChangeLog: PR tree-optimization/111276 * gimple-fold.cc (arith_code_with_undefined_signed_overflow): Make static. (gimple_with_undefined_signed_overflow): New function. * gimple-fold.h (arith_code_with_undefined_signed_overflow): Remove. (gimple_with_undefined_signed_overflow): Add declaration. * tree-if-conv.cc (if_convertible_gimple_assign_stmt_p): Use gimple_with_undefined_signed_overflow instead of manually checking lhs and the code of the stmt. (predicate_statements): Likewise. * tree-ssa-ifcombine.cc (pass_tree_ifcombine::execute): Likewise. * tree-ssa-loop-im.cc (move_computations_worker): Likewise. * tree-ssa-reassoc.cc (update_range_test): Likewise. Reformat. * tree-scalar-evolution.cc (final_value_replacement_loop): Use gimple_with_undefined_signed_overflow instead of arith_code_with_undefined_signed_overflow. * tree-ssa-loop-split.cc (split_loop): Likewise. Signed-off-by: Andrew Pinski --- gcc/gimple-fold.cc | 26 ++++++++++++++++++++++- gcc/gimple-fold.h | 2 +- gcc/tree-if-conv.cc | 16 +++------------ gcc/tree-scalar-evolution.cc | 5 +---- gcc/tree-ssa-ifcombine.cc | 10 ++------- gcc/tree-ssa-loop-im.cc | 6 +----- gcc/tree-ssa-loop-split.cc | 5 +---- gcc/tree-ssa-reassoc.cc | 40 +++++++++++++++--------------------- 8 files changed, 50 insertions(+), 60 deletions(-) diff --git a/gcc/gimple-fold.cc b/gcc/gimple-fold.cc index 942de7720fd..0b49d6754e2 100644 --- a/gcc/gimple-fold.cc +++ b/gcc/gimple-fold.cc @@ -8991,7 +8991,7 @@ gimple_fold_indirect_ref (tree t) integer types involves undefined behavior on overflow and the operation can be expressed with unsigned arithmetic. */ -bool +static bool arith_code_with_undefined_signed_overflow (tree_code code) { switch (code) @@ -9008,6 +9008,30 @@ arith_code_with_undefined_signed_overflow (tree_code code) } } +/* Return true if STMT has an operation that operates on a signed + integer types involves undefined behavior on overflow and the + operation can be expressed with unsigned arithmetic. */ + +bool +gimple_with_undefined_signed_overflow (gimple *stmt) +{ + if (!is_gimple_assign (stmt)) + return false; + tree lhs = gimple_assign_lhs (stmt); + if (!lhs) + return false; + tree lhs_type = TREE_TYPE (lhs); + if (!INTEGRAL_TYPE_P (lhs_type) + && !POINTER_TYPE_P (lhs_type)) + return false; + if (!TYPE_OVERFLOW_UNDEFINED (lhs_type)) + return false; + if (!arith_code_with_undefined_signed_overflow + (gimple_assign_rhs_code (stmt))) + return false; + return true; +} + /* Rewrite STMT, an assignment with a signed integer or pointer arithmetic operation that can be transformed to unsigned arithmetic by converting its operand, carrying out the operation in the corresponding unsigned diff --git a/gcc/gimple-fold.h b/gcc/gimple-fold.h index dc709d515a9..165325392c9 100644 --- a/gcc/gimple-fold.h +++ b/gcc/gimple-fold.h @@ -59,7 +59,7 @@ extern tree gimple_get_virt_method_for_vtable (HOST_WIDE_INT, tree, extern tree gimple_fold_indirect_ref (tree); extern bool gimple_fold_builtin_sprintf (gimple_stmt_iterator *); extern bool gimple_fold_builtin_snprintf (gimple_stmt_iterator *); -extern bool arith_code_with_undefined_signed_overflow (tree_code); +extern bool gimple_with_undefined_signed_overflow (gimple *); extern void rewrite_to_defined_overflow (gimple_stmt_iterator *); extern gimple_seq rewrite_to_defined_overflow (gimple *); extern void replace_call_with_value (gimple_stmt_iterator *, tree); diff --git a/gcc/tree-if-conv.cc b/gcc/tree-if-conv.cc index 3b04d1e8d34..f5aa6c04fc9 100644 --- a/gcc/tree-if-conv.cc +++ b/gcc/tree-if-conv.cc @@ -1067,11 +1067,7 @@ if_convertible_gimple_assign_stmt_p (gimple *stmt, fprintf (dump_file, "tree could trap...\n"); return false; } - else if ((INTEGRAL_TYPE_P (TREE_TYPE (lhs)) - || POINTER_TYPE_P (TREE_TYPE (lhs))) - && TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (lhs)) - && arith_code_with_undefined_signed_overflow - (gimple_assign_rhs_code (stmt))) + else if (gimple_with_undefined_signed_overflow (stmt)) /* We have to rewrite stmts with undefined overflow. */ need_to_rewrite_undefined = true; @@ -2820,7 +2816,6 @@ predicate_statements (loop_p loop) for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi);) { gassign *stmt = dyn_cast (gsi_stmt (gsi)); - tree lhs; if (!stmt) ; else if (is_false_predicate (cond) @@ -2876,12 +2871,7 @@ predicate_statements (loop_p loop) gsi_replace (&gsi, new_stmt, true); } - else if (((lhs = gimple_assign_lhs (stmt)), true) - && (INTEGRAL_TYPE_P (TREE_TYPE (lhs)) - || POINTER_TYPE_P (TREE_TYPE (lhs))) - && TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (lhs)) - && arith_code_with_undefined_signed_overflow - (gimple_assign_rhs_code (stmt))) + else if (gimple_with_undefined_signed_overflow (stmt)) rewrite_to_defined_overflow (&gsi); else if (gimple_vdef (stmt)) { @@ -2936,7 +2926,7 @@ predicate_statements (loop_p loop) gsi_replace (&gsi, new_call, true); } - lhs = gimple_get_lhs (gsi_stmt (gsi)); + tree lhs = gimple_get_lhs (gsi_stmt (gsi)); if (lhs && TREE_CODE (lhs) == SSA_NAME) ssa_names.add (lhs); gsi_next (&gsi); diff --git a/gcc/tree-scalar-evolution.cc b/gcc/tree-scalar-evolution.cc index abb2bad7773..34dc9810a31 100644 --- a/gcc/tree-scalar-evolution.cc +++ b/gcc/tree-scalar-evolution.cc @@ -3931,10 +3931,7 @@ final_value_replacement_loop (class loop *loop) gsi2 = gsi_start (stmts); while (!gsi_end_p (gsi2)) { - gimple *stmt = gsi_stmt (gsi2); - if (is_gimple_assign (stmt) - && arith_code_with_undefined_signed_overflow - (gimple_assign_rhs_code (stmt))) + if (gimple_with_undefined_signed_overflow (gsi_stmt (gsi2))) rewrite_to_defined_overflow (&gsi2); gsi_next (&gsi2); } diff --git a/gcc/tree-ssa-ifcombine.cc b/gcc/tree-ssa-ifcombine.cc index 6a3bc99190d..541a7be86ed 100644 --- a/gcc/tree-ssa-ifcombine.cc +++ b/gcc/tree-ssa-ifcombine.cc @@ -874,15 +874,9 @@ pass_tree_ifcombine::execute (function *fun) for (gimple_stmt_iterator gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi)) { - gassign *ass = dyn_cast (gsi_stmt (gsi)); - if (!ass) + if (!gimple_with_undefined_signed_overflow (gsi_stmt (gsi))) continue; - tree lhs = gimple_assign_lhs (ass); - if ((INTEGRAL_TYPE_P (TREE_TYPE (lhs)) - || POINTER_TYPE_P (TREE_TYPE (lhs))) - && arith_code_with_undefined_signed_overflow - (gimple_assign_rhs_code (ass))) - rewrite_to_defined_overflow (&gsi); + rewrite_to_defined_overflow (&gsi); } cfg_changed |= true; } diff --git a/gcc/tree-ssa-loop-im.cc b/gcc/tree-ssa-loop-im.cc index ccc56dc42f6..07a4739711c 100644 --- a/gcc/tree-ssa-loop-im.cc +++ b/gcc/tree-ssa-loop-im.cc @@ -1390,11 +1390,7 @@ move_computations_worker (basic_block bb) when the target loop header is executed and the stmt may invoke undefined integer or pointer overflow rewrite it to unsigned arithmetic. */ - if (is_gimple_assign (stmt) - && INTEGRAL_TYPE_P (TREE_TYPE (gimple_assign_lhs (stmt))) - && TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (gimple_assign_lhs (stmt))) - && arith_code_with_undefined_signed_overflow - (gimple_assign_rhs_code (stmt)) + if (gimple_with_undefined_signed_overflow (stmt) && (!ALWAYS_EXECUTED_IN (bb) || !(ALWAYS_EXECUTED_IN (bb) == level || flow_loop_nested_p (ALWAYS_EXECUTED_IN (bb), level)))) diff --git a/gcc/tree-ssa-loop-split.cc b/gcc/tree-ssa-loop-split.cc index 68435485b79..c69403c8613 100644 --- a/gcc/tree-ssa-loop-split.cc +++ b/gcc/tree-ssa-loop-split.cc @@ -662,10 +662,7 @@ split_loop (class loop *loop1) gsi = gsi_start (stmts2); while (!gsi_end_p (gsi)) { - gimple *stmt = gsi_stmt (gsi); - if (is_gimple_assign (stmt) - && arith_code_with_undefined_signed_overflow - (gimple_assign_rhs_code (stmt))) + if (gimple_with_undefined_signed_overflow (gsi_stmt (gsi))) rewrite_to_defined_overflow (&gsi); gsi_next (&gsi); } diff --git a/gcc/tree-ssa-reassoc.cc b/gcc/tree-ssa-reassoc.cc index 347350fc98d..dc1b2410f2f 100644 --- a/gcc/tree-ssa-reassoc.cc +++ b/gcc/tree-ssa-reassoc.cc @@ -2924,30 +2924,22 @@ update_range_test (struct range_entry *range, struct range_entry *otherrange, !gsi_end_p (gsi); gsi_next (&gsi)) { gimple *stmt = gsi_stmt (gsi); - if (is_gimple_assign (stmt)) - if (tree lhs = gimple_assign_lhs (stmt)) - if ((INTEGRAL_TYPE_P (TREE_TYPE (lhs)) - || POINTER_TYPE_P (TREE_TYPE (lhs))) - && TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (lhs))) - { - enum tree_code code = gimple_assign_rhs_code (stmt); - if (arith_code_with_undefined_signed_overflow (code)) - { - gimple_stmt_iterator gsip = gsi; - gimple_stmt_iterator gsin = gsi; - gsi_prev (&gsip); - gsi_next (&gsin); - rewrite_to_defined_overflow (&gsi); - unsigned uid = gimple_uid (stmt); - if (gsi_end_p (gsip)) - gsip = gsi_after_labels (bb); - else - gsi_next (&gsip); - for (; gsi_stmt (gsip) != gsi_stmt (gsin); - gsi_next (&gsip)) - gimple_set_uid (gsi_stmt (gsip), uid); - } - } + if (gimple_with_undefined_signed_overflow (stmt)) + { + gimple_stmt_iterator gsip = gsi; + gimple_stmt_iterator gsin = gsi; + gsi_prev (&gsip); + gsi_next (&gsin); + rewrite_to_defined_overflow (&gsi); + unsigned uid = gimple_uid (stmt); + if (gsi_end_p (gsip)) + gsip = gsi_after_labels (bb); + else + gsi_next (&gsip); + for (; gsi_stmt (gsip) != gsi_stmt (gsin); + gsi_next (&gsip)) + gimple_set_uid (gsi_stmt (gsip), uid); + } } if (opcode == BIT_IOR_EXPR