From patchwork Thu Feb 2 09:48:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 51829 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2388:b0:96:219d:e725 with SMTP id i8csp195865dyf; Thu, 2 Feb 2023 01:49:27 -0800 (PST) X-Google-Smtp-Source: AK7set9WVpNYDPCFUI6XdVXuyAviTcIXlvL25fF3HmoOtSHmY5EpPxMaT/YJvm6IWRA8OTf06JO2 X-Received: by 2002:a17:906:31cf:b0:878:4dd1:5161 with SMTP id f15-20020a17090631cf00b008784dd15161mr5853724ejf.11.1675331367473; Thu, 02 Feb 2023 01:49:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675331367; cv=none; d=google.com; s=arc-20160816; b=05vic+R6x1DxaRYsMWj3AfDXA8biSaUnJDNPF5xpYv+Em7aVvLjpWlm8rHc+yPolkb 70o0WVRV6ZRym2lEOhxdLiLmWFcfc1IdmU1ZhiRauQKsedCza8nvlspXu9BBFkRzHzcx KyEWTEFk6qxXp/oQLcfAQqLfetzzQ8roW8TJ6p7bUOZgAoWhdNPYW3jP3hf458lgrjKr TPKlL1Lt0Vwfgl6Ywn2GuIVSS4yTAmzDQ4Ui7rwzu3OcP/1QYzMLB7NgCrzwT0mo9+kL PkQxX5zHDXK4svFlyxCn+DZJuAaU/G5Nnb7ZugOXK7OqzQSqxuGj3yFiyAGLIVJMplXD i1PQ== 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:mime-version :user-agent:message-id:date:subject:mail-followup-to:to:dmarc-filter :delivered-to:dkim-signature:dkim-filter; bh=Yow394SkLNaHdzz3sIj+R2F2m+GYTtzK6Y9/oVUxV/A=; b=dgsFoTymwJ5J51bwJFkVpMKzbmiPU9NuV7rnbO/7WfI1qA+umrgXLh0LHSyLRQhT5Q JeH/CyPTVZOIt+8luGsbl8RNdA6PsJTunfyJiNFT90jJ/5FaGFsTc0s9fawFF2i4OTPb SxKhqng6vVT9mexoSyCOCuSVtX8e677g925vK2S95lTlGdZSk8I2PVn3G0OLXRD3x1id DoJHhOy30wbhDyPJdZ9LNX5Tf6NeVEnbdDF3+qDeuWKCTQXN4hhe3beGX06yqrhag8pH uTQtqHBpZV1yunACbutwoOi46a7dvNPru1j83S9yKSS6to/Zk7/FS15mBExKsuEpFvRd vvPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=urujz1CA; 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 sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id 21-20020a170906009500b0088b3b09e143si10112466ejc.593.2023.02.02.01.49.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Feb 2023 01:49:27 -0800 (PST) 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=urujz1CA; 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 6716A3857B8E for ; Thu, 2 Feb 2023 09:49:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6716A3857B8E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1675331366; bh=Yow394SkLNaHdzz3sIj+R2F2m+GYTtzK6Y9/oVUxV/A=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=urujz1CA2/Xr73/RE5igwPDqsGS+xDFUMn75exmj3shdAJ5a3RkFVYH51Lud5ZJRN bLYzFqTnf/L4qX57M/W9coiiQ2HRJlhcsgsmCq1CY2wbSyT0ScrywoYr8NRbzTuUPB BK8u0QUEeHH/NxQF6THz4Gwej+uulofCFa+11kIc= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by sourceware.org (Postfix) with ESMTP id C1E7F3858C2D for ; Thu, 2 Feb 2023 09:48:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C1E7F3858C2D Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 8DD511042 for ; Thu, 2 Feb 2023 01:48:55 -0800 (PST) Received: from localhost (e121540-lin.manchester.arm.com [10.32.99.50]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 12AB23F64C for ; Thu, 2 Feb 2023 01:48:12 -0800 (PST) To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@arm.com Subject: [PATCH] rtl-ssa: Fix splitting of clobber groups [PR108508] Date: Thu, 02 Feb 2023 09:48:11 +0000 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) MIME-Version: 1.0 X-Spam-Status: No, score=-36.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, KAM_SHORT, 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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Richard Sandiford via Gcc-patches From: Richard Sandiford Reply-To: Richard Sandiford Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756712264336467589?= X-GMAIL-MSGID: =?utf-8?q?1756712264336467589?= Since rtl-ssa isn't a real/native SSA representation, it has to honour the constraints of the underlying rtl representation. Part of this involves maintaining an rpo list of definitions for each rtl register, backed by a splay tree where necessary for quick lookup/insertion. However, clobbers of a register don't act as barriers to other clobbers of a register. E.g. it's possible to move one flag-clobbering instruction across an arbitrary number of other flag-clobbering instructions. In order to allow passes to do that without quadratic complexity, the splay tree groups all consecutive clobbers into groups, with only the group being entered into the splay tree. These groups in turn have an internal splay tree of clobbers where necessary. This means that, if we insert a new definition and use into the middle of a sea of clobbers, we need to split the clobber group into two groups. This was quite a difficult condition to trigger during development, and the PR shows that the code to handle it had (at least) two bugs. First, the process involves searching the clobber tree for the split point. This search can give either the previous clobber (which will belong to the first of the split groups) or the next clobber (which will belong to the second of the split groups). The code for the former case handled the split correctly but the code for the latter case didn't. Second, I'd forgotten to add the second clobber group to the main splay tree. :-( Tested on aarch64-linux-gnu & x86_64-linux-gnu. OK for trunk & GCC 12? Although the testcase is "only" a regression from GCC 12, I think the rtl-ssa patch should be backported to GCC 11 too. Richard gcc/ PR rtl-optimization/108508 * rtl-ssa/accesses.cc (function_info::split_clobber_group): When the splay tree search gives the first clobber in the second group, make sure that the root of the first clobber group is updated correctly. Enter the new clobber group into the definition splay tree. gcc/testsuite/ PR rtl-optimization/108508 * gcc.target/aarch64/pr108508.c: New test. --- gcc/rtl-ssa/accesses.cc | 14 ++++++++--- gcc/testsuite/gcc.target/aarch64/pr108508.c | 28 +++++++++++++++++++++ 2 files changed, 38 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/gcc.target/aarch64/pr108508.c diff --git a/gcc/rtl-ssa/accesses.cc b/gcc/rtl-ssa/accesses.cc index 03b9a475d3b..f12b5f4dd77 100644 --- a/gcc/rtl-ssa/accesses.cc +++ b/gcc/rtl-ssa/accesses.cc @@ -794,23 +794,26 @@ function_info::merge_clobber_groups (clobber_info *clobber1, // GROUP spans INSN, and INSN now sets the resource that GROUP clobbers. // Split GROUP around INSN and return the clobber that comes immediately // before INSN. +// +// The resource that GROUP clobbers is known to have an associated +// splay tree. clobber_info * function_info::split_clobber_group (clobber_group *group, insn_info *insn) { // Search for either the previous or next clobber in the group. // The result is less than zero if CLOBBER should come before NEIGHBOR // or greater than zero if CLOBBER should come after NEIGHBOR. - int comparison = lookup_clobber (group->m_clobber_tree, insn); + clobber_tree &tree1 = group->m_clobber_tree; + int comparison = lookup_clobber (tree1, insn); gcc_checking_assert (comparison != 0); - clobber_info *neighbor = group->m_clobber_tree.root (); + clobber_info *neighbor = tree1.root (); - clobber_tree tree1, tree2; + clobber_tree tree2; clobber_info *prev; clobber_info *next; if (comparison > 0) { // NEIGHBOR is the last clobber in what will become the first group. - tree1 = neighbor; tree2 = tree1.split_after_root (); prev = neighbor; next = as_a (prev->next_def ()); @@ -843,6 +846,9 @@ function_info::split_clobber_group (clobber_group *group, insn_info *insn) tree2->set_group (group2); last_clobber->set_group (group2); + // Insert GROUP2 into the splay tree as an immediate successor of GROUP1. + def_splay_tree::insert_child (group1, 1, group2); + return prev; } diff --git a/gcc/testsuite/gcc.target/aarch64/pr108508.c b/gcc/testsuite/gcc.target/aarch64/pr108508.c new file mode 100644 index 00000000000..e97896b6a1b --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/pr108508.c @@ -0,0 +1,28 @@ +/* { dg-options "-O3 -fharden-conditional-branches -fno-dce -fno-guess-branch-probability" } */ + +#include + +int +test_vld3q_lane_f64 (void) +{ + float64x2x3_t vectors; + float64_t temp[2]; + int i, j; + + for (i = 0; i < 3; i++) + { + vst1q_f64 (temp, vectors.val[i]); + for (j = 0; j < 2; j++) + if (temp[j]) + return 1; + } + + return 0; +} + +void +foo (void) +{ + if (test_vld3q_lane_f64 () || test_vld3q_lane_f64 ()) + __builtin_abort (); +}