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); - } } }