From patchwork Sat Jul 15 03:19:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 120734 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a6b2:0:b0:3e4:2afc:c1 with SMTP id c18csp2845067vqm; Fri, 14 Jul 2023 20:21:57 -0700 (PDT) X-Google-Smtp-Source: APBJJlFszzalE6l3T++S9ABgenM0J50jARwXd04CTeeFwFNgMsz79CKsY7H5ST8rKptAir+SmrSj X-Received: by 2002:a17:906:7f0b:b0:993:8d16:4c22 with SMTP id d11-20020a1709067f0b00b009938d164c22mr4752985ejr.75.1689391316886; Fri, 14 Jul 2023 20:21:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689391316; cv=none; d=google.com; s=arc-20160816; b=0KSMAjhpvvRZp4n1qTONeJrlU+rNqtDnbefamYPyI9ceOZIhDGxaf/zlOkt41rzZQS X3B45H6UKZbiFVMpc9ZaeseAcDB4TkiHkCtSziJtm7HPQe9cxNs7bKw2yVGo3ksTwxI+ US8zqircF0Prl1TKLVCvm8r48HPGJ3hZ2+jJlGGANtazNh8yWaPPsY4xdihLBxVJ6UX4 lC7qziguDnTakSw2SKn6tmrX85zP7l77kuop49NagbTtBYp7uK6SqyjP725Zq1xhi6ud svaMNsaohHnCrJ/468oNsMOstUGE0B2ejxFgpj4g4ieIjFAd50z1mCg14VjnFNknVJlO Pr/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=kheZed0zc7BDKCAlnhdFfuuvqeZq6nuTiQ2kExeDBqk=; fh=09okz+w4tVyhQmqNBttR063P0zKcIsLE1JRBioNPGC4=; b=LriQAiI1nNT7z/sAGrs4kQ0kc0EMtO984/ujGrNZ5sfNOtwIfrsQ7ahV4nIaJv3+/l /2/azJXMKlZHPj8X5K+Btg5ZrTxXDpJ/YPBLRtwjcMGR4US8pXl0sL9RoPoJVGHLZBSb FEB1yrTDr1Zkyif6zc6uGc0lJgMifbtjuQmO32R/ZezE/lZBydAJ2WmRjw9YDoWHjEk1 7svdEG7dCq2wBF2VGGEAwpdUDuK6IhbXIopVse8FYNV7o9+Ui6Ooiz1FTnWgzlsDrB5o UH3a/YHWNVi7J6qa1h/1en2VcxE9PDG9C6HN5ucv4ImcwCJHO+uf4yDpOVsuIlCQVdiK IRyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=ABBTOO1D; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id pv17-20020a170907209100b00988c64dd2e7si9415992ejb.850.2023.07.14.20.21.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Jul 2023 20:21:56 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=ABBTOO1D; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 65E433858296 for ; Sat, 15 Jul 2023 03:21:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 65E433858296 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1689391294; bh=kheZed0zc7BDKCAlnhdFfuuvqeZq6nuTiQ2kExeDBqk=; h=To:CC:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=ABBTOO1Du2aVphz2ZPYMJbhHL12GtmeLE/x2iPgrg32vmlyRzmZzgqNrsKApmP0gC vK70806D9ZiPpuAx+WSFpBCHGZpeToLF+CPFU7cNrHEz0So3ZBlqrav7vdQQpJfFBY A9qPIGn/eJIO5OpOm2/bbDuioYxX2ogup96/xpvM= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by sourceware.org (Postfix) with ESMTPS id 4C0C83858CD1 for ; Sat, 15 Jul 2023 03:20:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4C0C83858CD1 Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 36EN6lOL016067 for ; Fri, 14 Jul 2023 20:20:47 -0700 Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 3rtptxcgf1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Fri, 14 Jul 2023 20:20:47 -0700 Received: from DC5-EXCH02.marvell.com (10.69.176.39) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server (TLS) id 15.0.1497.48; Fri, 14 Jul 2023 20:20:45 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server id 15.0.1497.48 via Frontend Transport; Fri, 14 Jul 2023 20:20:45 -0700 Received: from vpnclient.wrightpinski.org.com (unknown [10.76.242.112]) by maili.marvell.com (Postfix) with ESMTP id 41F5F5B693B; Fri, 14 Jul 2023 20:20:44 -0700 (PDT) To: CC: Andrew Pinski Subject: [PATCH 1/2] Add flow_sensitive_info_storage and use it in gimple-fold. Date: Fri, 14 Jul 2023 20:19:56 -0700 Message-ID: <20230715031957.1147225-1-apinski@marvell.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Proofpoint-GUID: dpqmjNS7XplvXKpqMFw9XROpAfEgl7jW X-Proofpoint-ORIG-GUID: dpqmjNS7XplvXKpqMFw9XROpAfEgl7jW X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-07-14_12,2023-07-13_01,2023-05-22_02 X-Spam-Status: No, score=-14.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_LOW, 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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Andrew Pinski via Gcc-patches From: Andrew Pinski Reply-To: Andrew Pinski Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771455189320765615 X-GMAIL-MSGID: 1771455189320765615 This adds flow_sensitive_info_storage and uses it in maybe_fold_comparisons_from_match_pd as mentioned in https://gcc.gnu.org/pipermail/gcc-patches/2023-June/621817.html . Since using it in maybe_fold_comparisons_from_match_pd was easy and allowed me to test the storage earlier, I did it. This also hides better how the flow sensitive information is stored and only a single place needs to be updated if that ever changes (again). OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions. gcc/ChangeLog: * gimple-fold.cc (fosa_unwind): Replace `vrange_storage *` with flow_sensitive_info_storage. (follow_outer_ssa_edges): Update how to save off the flow sensitive info. (maybe_fold_comparisons_from_match_pd): Update restoring of flow sensitive info. * tree-ssanames.cc (flow_sensitive_info_storage::save): New method. (flow_sensitive_info_storage::restore): New method. (flow_sensitive_info_storage::save_and_clear): New method. (flow_sensitive_info_storage::clear_storage): New method. * tree-ssanames.h (class flow_sensitive_info_storage): New class. --- gcc/gimple-fold.cc | 17 +++++------ gcc/tree-ssanames.cc | 72 ++++++++++++++++++++++++++++++++++++++++++++ gcc/tree-ssanames.h | 21 +++++++++++++ 3 files changed, 100 insertions(+), 10 deletions(-) diff --git a/gcc/gimple-fold.cc b/gcc/gimple-fold.cc index 4027ff71e10..de94efbcff7 100644 --- a/gcc/gimple-fold.cc +++ b/gcc/gimple-fold.cc @@ -6947,7 +6947,7 @@ and_comparisons_1 (tree type, enum tree_code code1, tree op1a, tree op1b, } static basic_block fosa_bb; -static vec > *fosa_unwind; +static vec > *fosa_unwind; static tree follow_outer_ssa_edges (tree val) { @@ -6967,14 +6967,11 @@ follow_outer_ssa_edges (tree val) || POINTER_TYPE_P (TREE_TYPE (val))) && !TYPE_OVERFLOW_WRAPS (TREE_TYPE (val))) return NULL_TREE; + flow_sensitive_info_storage storage; + storage.save_and_clear (val); /* If the definition does not dominate fosa_bb temporarily reset flow-sensitive info. */ - if (val->ssa_name.info.range_info) - { - fosa_unwind->safe_push (std::make_pair - (val, val->ssa_name.info.range_info)); - val->ssa_name.info.range_info = NULL; - } + fosa_unwind->safe_push (std::make_pair (val, storage)); return val; } return val; @@ -7034,14 +7031,14 @@ maybe_fold_comparisons_from_match_pd (tree type, enum tree_code code, type, gimple_assign_lhs (stmt1), gimple_assign_lhs (stmt2)); fosa_bb = outer_cond_bb; - auto_vec, 8> unwind_stack; + auto_vec, 8> unwind_stack; fosa_unwind = &unwind_stack; if (op.resimplify (NULL, (!outer_cond_bb ? follow_all_ssa_edges : follow_outer_ssa_edges))) { fosa_unwind = NULL; for (auto p : unwind_stack) - p.first->ssa_name.info.range_info = p.second; + p.second.restore (p.first); if (gimple_simplified_result_is_gimple_val (&op)) { tree res = op.ops[0]; @@ -7065,7 +7062,7 @@ maybe_fold_comparisons_from_match_pd (tree type, enum tree_code code, } fosa_unwind = NULL; for (auto p : unwind_stack) - p.first->ssa_name.info.range_info = p.second; + p.second.restore (p.first); return NULL_TREE; } diff --git a/gcc/tree-ssanames.cc b/gcc/tree-ssanames.cc index 5fdb6a37e9f..f81332451fc 100644 --- a/gcc/tree-ssanames.cc +++ b/gcc/tree-ssanames.cc @@ -916,3 +916,75 @@ make_pass_release_ssa_names (gcc::context *ctxt) { return new pass_release_ssa_names (ctxt); } + +/* Save and restore of flow sensitive information. */ + +/* Save off the flow sensitive info from NAME. */ + +void +flow_sensitive_info_storage::save (tree name) +{ + gcc_assert (state == 0); + if (!POINTER_TYPE_P (TREE_TYPE (name))) + { + range_info = SSA_NAME_RANGE_INFO (name); + state = 1; + return; + } + state = -1; + auto ptr_info = SSA_NAME_PTR_INFO (name); + if (ptr_info) + { + align = ptr_info->align; + misalign = ptr_info->misalign; + null = SSA_NAME_PTR_INFO (name)->pt.null; + } + else + { + align = 0; + misalign = 0; + null = true; + } +} + +/* Restore the flow sensitive info from NAME. */ + +void +flow_sensitive_info_storage::restore (tree name) +{ + gcc_assert (state != 0); + if (!POINTER_TYPE_P (TREE_TYPE (name))) + { + gcc_assert (state == 1); + SSA_NAME_RANGE_INFO (name) = range_info; + return; + } + gcc_assert (state == -1); + auto ptr_info = SSA_NAME_PTR_INFO (name); + /* If there was no flow sensitive info on the pointer + just return, there is nothing to restore to. */ + if (!ptr_info) + return; + if (align != 0) + set_ptr_info_alignment (ptr_info, align, misalign); + else + mark_ptr_info_alignment_unknown (ptr_info); + SSA_NAME_PTR_INFO (name)->pt.null = null; +} + +/* Save off the flow sensitive info from NAME. + And reset the flow sensitive info of NAME. */ + +void +flow_sensitive_info_storage::save_and_clear (tree name) +{ + save (name); + reset_flow_sensitive_info (name); +} + +/* Clear the storage. */ +void +flow_sensitive_info_storage::clear_storage (void) +{ + state = 0; +} diff --git a/gcc/tree-ssanames.h b/gcc/tree-ssanames.h index f3fa609208a..98f4a835483 100644 --- a/gcc/tree-ssanames.h +++ b/gcc/tree-ssanames.h @@ -136,5 +136,26 @@ make_temp_ssa_name (tree type, gimple *stmt, const char *name) return ssa_name; } +/* A class which is used to save/restore the flow sensitive information. */ +class flow_sensitive_info_storage +{ +public: + void save (tree); + void save_and_clear (tree); + void restore (tree); + void clear_storage (); +private: + /* 0 means there is nothing saved. + 1 means non pointer is saved. + -1 means a pointer type is saved. + -2 means a pointer type is saved but no information was saved. */ + int state = 0; + /* The range info for non pointers */ + vrange_storage *range_info = nullptr; + /* Flow sensitive pointer information. */ + unsigned int align = 0; + unsigned int misalign = 0; + bool null = true; +}; #endif /* GCC_TREE_SSANAMES_H */ From patchwork Sat Jul 15 03:19:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 120735 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a6b2:0:b0:3e4:2afc:c1 with SMTP id c18csp2845074vqm; Fri, 14 Jul 2023 20:21:58 -0700 (PDT) X-Google-Smtp-Source: APBJJlH4D/PHcHfqYCOZzha1ErVUa8Y1/llyPA/o92PF0ZsRM6WBBDyNiNCB++mgReTdwLlH/AI2 X-Received: by 2002:aa7:d359:0:b0:51e:2d8b:454a with SMTP id m25-20020aa7d359000000b0051e2d8b454amr5269594edr.20.1689391318669; Fri, 14 Jul 2023 20:21:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689391318; cv=none; d=google.com; s=arc-20160816; b=oivG1txLOJ6kSh1sK84tpUiipKmXUq1hJPGpFtpjyXkLKn7I2QVRlP4v+gqqEKf5bp zdX6i2sUz7QKd1sM1dbZ92fg6i3G1Dpl3VAKwxCXbQHt34NP1qf1l55ZHRMtc91al3fX pHbWBkTV0LlIttYizfOY//MWLytBkNm0htOavFyToXfpEJpgS9+yQKvxsM4rTFoQaIcE m0aEz2W9jLqMM4SHCuBvIDLUjnvzGKw2EujFo0LPIu47fDjW/yRBBvRa3Iz+Wclzj8B5 iQBS6COI0YhlSDwgCSQ+cfx9WWPejfSJJsdiXLnCbBPidxhgGKoK2Wp/sB4CpjhOJrq9 ZH3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=4jROPOKTgcXBcPUpUM1w9T4pVyc6ZEcugagBzSASBL8=; fh=09okz+w4tVyhQmqNBttR063P0zKcIsLE1JRBioNPGC4=; b=TjSXQsw6aIaEb5nRKAmG3nbEunybRHbt12E5JUESkCBrxOuaAn8RL/pe18PivHew/e 4y79MOcKh8pS2ynOoUAnzDWEd3zM+qYOZgaeMH4rIHctHCwma8Mc8bSwQB4T5ayheWGO HYQQucMqAqv7ycNKNF5X/PodnvW7ywqlQiiDzHbhaF4AWsumK7M0mRhMNCKCv6i7jQHh 3P+YBkZmPHSdf+iG77n5ZJs+P61f03DM9mJ2d14zTaYs5a36K9i415+hPlDDqM7Ted27 SsX+y2WTxkZR0vYeNh3rGQHUC2eL1EoceMC09eVT1yBSPZJha7YRja3sDrkRkQvQWQFE m5SQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="r/veV6vZ"; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id p4-20020aa7d304000000b0051e0e38a950si11094730edq.637.2023.07.14.20.21.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Jul 2023 20:21:58 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="r/veV6vZ"; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id AE257385AF8F for ; Sat, 15 Jul 2023 03:21:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AE257385AF8F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1689391295; bh=4jROPOKTgcXBcPUpUM1w9T4pVyc6ZEcugagBzSASBL8=; h=To:CC:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=r/veV6vZ/LyHU4zof8oSlztSUvhkaFtAU4+iaGRdIAEoZvDr5OEi7OPAAoM4UumU2 88SlSF1hcsksvqsNLjAVEpyNoqckZJKp1XS3MuYAlXaiGb2KjyI8uzvTo4MxvRR8Ip 17kIT75N3eu6CR1oqjvl3ZRyLpvKL/I3Qjj69QCg= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by sourceware.org (Postfix) with ESMTPS id B58BC3858CDB for ; Sat, 15 Jul 2023 03:20:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B58BC3858CDB Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 36F2nxVY006766 for ; Fri, 14 Jul 2023 20:20:50 -0700 Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 3rtptxcgf2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Fri, 14 Jul 2023 20:20:49 -0700 Received: from DC5-EXCH02.marvell.com (10.69.176.39) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server (TLS) id 15.0.1497.48; Fri, 14 Jul 2023 20:20:47 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server id 15.0.1497.48 via Frontend Transport; Fri, 14 Jul 2023 20:20:47 -0700 Received: from vpnclient.wrightpinski.org.com (unknown [10.76.242.112]) by maili.marvell.com (Postfix) with ESMTP id CE6195B6939; Fri, 14 Jul 2023 20:20:45 -0700 (PDT) To: CC: Andrew Pinski Subject: [PATCH 2/2] [PATCH] Fix tree-opt/110252: wrong code due to phiopt using flow sensitive info during match Date: Fri, 14 Jul 2023 20:19:57 -0700 Message-ID: <20230715031957.1147225-2-apinski@marvell.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230715031957.1147225-1-apinski@marvell.com> References: <20230715031957.1147225-1-apinski@marvell.com> MIME-Version: 1.0 X-Proofpoint-GUID: 4INNeZWv1q2Xj7SUdMFiA7qhP27KkiU1 X-Proofpoint-ORIG-GUID: 4INNeZWv1q2Xj7SUdMFiA7qhP27KkiU1 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-07-14_12,2023-07-13_01,2023-05-22_02 X-Spam-Status: No, score=-14.6 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_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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Andrew Pinski via Gcc-patches From: Andrew Pinski Reply-To: Andrew Pinski Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771455191452860936 X-GMAIL-MSGID: 1771455191452860936 Match will query ranger via tree_nonzero_bits/get_nonzero_bits for 2 and 3rd operand of the COND_EXPR and phiopt tries to do create the COND_EXPR even if we moving one statement. That one statement could have some flow sensitive information on it based on the condition that is for the COND_EXPR but that might create wrong code if the statement was moved out. This is similar to the previous version of the patch except now we use flow_sensitive_info_storage instead of manually doing the save/restore and also handle all defs on a gimple statement rather than just for lhs of the gimple statement. Oh and a few more testcases were added that was failing before. OK? Bootsrapped and tested on x86_64-linux-gnu with no regressions. PR tree-optimization/110252 gcc/ChangeLog: * tree-ssa-phiopt.cc (class auto_flow_sensitive): New class. (auto_flow_sensitive::auto_flow_sensitive): New constructor. (auto_flow_sensitive::~auto_flow_sensitive): New deconstructor. (match_simplify_replacement): Temporarily remove the flow sensitive info on the two statements that might be moved. gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/phi-opt-25b.c: Updated as __builtin_parity loses the nonzerobits info. * gcc.c-torture/execute/pr110252-1.c: New test. * gcc.c-torture/execute/pr110252-2.c: New test. * gcc.c-torture/execute/pr110252-3.c: New test. * gcc.c-torture/execute/pr110252-4.c: New test. --- .../gcc.c-torture/execute/pr110252-1.c | 15 ++++++ .../gcc.c-torture/execute/pr110252-2.c | 10 ++++ .../gcc.c-torture/execute/pr110252-3.c | 13 +++++ .../gcc.c-torture/execute/pr110252-4.c | 8 +++ gcc/testsuite/gcc.dg/tree-ssa/phi-opt-25b.c | 6 +-- gcc/tree-ssa-phiopt.cc | 51 +++++++++++++++++-- 6 files changed, 96 insertions(+), 7 deletions(-) create mode 100644 gcc/testsuite/gcc.c-torture/execute/pr110252-1.c create mode 100644 gcc/testsuite/gcc.c-torture/execute/pr110252-2.c create mode 100644 gcc/testsuite/gcc.c-torture/execute/pr110252-3.c create mode 100644 gcc/testsuite/gcc.c-torture/execute/pr110252-4.c diff --git a/gcc/testsuite/gcc.c-torture/execute/pr110252-1.c b/gcc/testsuite/gcc.c-torture/execute/pr110252-1.c new file mode 100644 index 00000000000..4ae93ca0647 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/pr110252-1.c @@ -0,0 +1,15 @@ +/* This is reduced from sel-sched.cc which was noticed was being miscompiled too. */ +int g(int min_need_stall) __attribute__((__noipa__)); +int g(int min_need_stall) +{ + return min_need_stall < 0 ? 1 : ((min_need_stall) < (1) ? (min_need_stall) : (1)); +} +int main(void) +{ + for(int i = -100; i <= 100; i++) + { + int t = g(i); + if (t != (i!=0)) + __builtin_abort(); + } +} diff --git a/gcc/testsuite/gcc.c-torture/execute/pr110252-2.c b/gcc/testsuite/gcc.c-torture/execute/pr110252-2.c new file mode 100644 index 00000000000..7f1a7dbf134 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/pr110252-2.c @@ -0,0 +1,10 @@ +signed char f() __attribute__((__noipa__)); +signed char f() { return 0; } +int main() +{ + int g = f() - 1; + int e = g < 0 ? 1 : ((g >> (8-2))!=0); + asm("":"+r"(e)); + if (e != 1) + __builtin_abort(); +} diff --git a/gcc/testsuite/gcc.c-torture/execute/pr110252-3.c b/gcc/testsuite/gcc.c-torture/execute/pr110252-3.c new file mode 100644 index 00000000000..c24bf1ab1e4 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/pr110252-3.c @@ -0,0 +1,13 @@ + +unsigned int a = 1387579096U; +void sinkandcheck(unsigned b) __attribute__((noipa)); +void sinkandcheck(unsigned b) +{ + if (a != b) + __builtin_abort(); +} +int main() { + a = 1 < (~a) ? 1 : (~a); + sinkandcheck(1); + return 0; +} diff --git a/gcc/testsuite/gcc.c-torture/execute/pr110252-4.c b/gcc/testsuite/gcc.c-torture/execute/pr110252-4.c new file mode 100644 index 00000000000..f97edd3f069 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/pr110252-4.c @@ -0,0 +1,8 @@ + +int a, b = 2, c = 2; +int main() { + b = ~(1 % (a ^ (b - (1 && c) || c & b))); + if (b < -1) + __builtin_abort(); + return 0; +} diff --git a/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-25b.c b/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-25b.c index 7298da0c96e..0fd9b004a03 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-25b.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-25b.c @@ -65,8 +65,6 @@ int test_popcountll(unsigned long long x, unsigned long long y) return x ? __builtin_popcountll(y) : 0; } -/* 3 types of functions (not including parity), each with 3 types and there are 2 goto each */ -/* { dg-final { scan-tree-dump-times "goto " 18 "optimized" } } */ +/* 4 types of functions, each with 3 types and there are 2 goto each */ +/* { dg-final { scan-tree-dump-times "goto " 24 "optimized" } } */ /* { dg-final { scan-tree-dump-times "x_..D. != 0" 12 "optimized" } } */ -/* parity case will be optimized to x!=0 & parity(y) . */ -/* { dg-final { scan-tree-dump-times " & " 3 "optimized" } } */ diff --git a/gcc/tree-ssa-phiopt.cc b/gcc/tree-ssa-phiopt.cc index 467c9fd108a..9d542fd345f 100644 --- a/gcc/tree-ssa-phiopt.cc +++ b/gcc/tree-ssa-phiopt.cc @@ -708,6 +708,45 @@ move_stmt (gimple *stmt, gimple_stmt_iterator *gsi, auto_bitmap &inserted_exprs) reset_flow_sensitive_info (name); } +/* RAII style class to temporarily remove flow sensitive + from ssa names defined by a gimple statement. */ +class auto_flow_sensitive +{ +public: + auto_flow_sensitive (gimple *s); + ~auto_flow_sensitive (); +private: + auto_vec, 2> stack; +}; + +/* Constructor for auto_flow_sensitive. Saves + off the ssa names' flow sensitive information + that was defined by gimple statement S and + resets it to be non-flow based ones. */ + +auto_flow_sensitive::auto_flow_sensitive (gimple *s) +{ + if (!s) + return; + ssa_op_iter it; + tree def; + FOR_EACH_SSA_TREE_OPERAND (def, s, it, SSA_OP_DEF) + { + flow_sensitive_info_storage storage; + storage.save_and_clear (def); + stack.safe_push (std::make_pair (def, storage)); + } +} + +/* Deconstructor, restores the flow sensitive information + for the SSA names that had been saved off. */ + +auto_flow_sensitive::~auto_flow_sensitive () +{ + for (auto p : stack) + p.second.restore (p.first); +} + /* The function match_simplify_replacement does the main work of doing the replacement using match and simplify. Return true if the replacement is done. Otherwise return false. @@ -793,9 +832,15 @@ match_simplify_replacement (basic_block cond_bb, basic_block middle_bb, return false; tree type = TREE_TYPE (gimple_phi_result (phi)); - result = gimple_simplify_phiopt (early_p, type, stmt, - arg_true, arg_false, - &seq); + { + auto_flow_sensitive s1(stmt_to_move); + auto_flow_sensitive s_alt(stmt_to_move_alt); + + result = gimple_simplify_phiopt (early_p, type, stmt, + arg_true, arg_false, + &seq); + } + if (!result) return false;