From patchwork Thu Jun 23 02:46:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xionghu Luo X-Patchwork-Id: 55316 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 92E373895FE9 for ; Thu, 23 Jun 2022 02:47:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 92E373895FE9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1655952453; bh=B4XC9RJG/322F0n6JpgNJlstj24ZhD1+YLJcH74yZHY=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=O/0SRqBjirxj7RDYCrdXUfbKkqe8l3OoseydXjqCh0SpoO6UI2NXVeUzYHuKF3YlS 0mS25up7IDoX3WtrV/MYQUxzrc4bu/PGzRj0IXEEo7w/xvAa1uM82pajpSmT9mMWEj S5Rv5SOKT0IodNMLuU8L2DD4S+dpyvIw0kClfcig= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pf1-x433.google.com (mail-pf1-x433.google.com [IPv6:2607:f8b0:4864:20::433]) by sourceware.org (Postfix) with ESMTPS id 5395438207F7 for ; Thu, 23 Jun 2022 02:47:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 5395438207F7 Received: by mail-pf1-x433.google.com with SMTP id d17so8819796pfq.9 for ; Wed, 22 Jun 2022 19:47:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=B4XC9RJG/322F0n6JpgNJlstj24ZhD1+YLJcH74yZHY=; b=YF5ROeysw2uj0Wcz6DFGwsSVl8MsxsuNZsofOnF4pvfQxaZupNcNHjIEjJn+IJBxM0 m7mzd9b2Rhh5p6LPdd99h+Rm3AULH379z2ir6vlcmVNDYj4hQiq71qRL0dHn2dj3bkmm EGmWCRvg41aNEyGYPv1nSKtAQR0v5PSMRSUCqTJEyy91V4sBhcrRBR+//7w0GzT+P9UW 1edPjITZTc6OzURb8nro8TyJH4jCQw6y4ugFXKs+YloyiOarLQW4AruikHjcbtq2Hdlg dLueynRNc3HFM82dU7+ijGl5eUY+lg64fJ91BXCgw4xa+yYrV1rOFBsKvuDKuRVibS6Y Vfug== X-Gm-Message-State: AJIora8Cn+0UY6fndgbmLCDns5P64XMxwFMH9dvKpYXIi0Z4qBCzFaDg C1nLm+fLLzuHreATpy6sK2gBQNN3svb5mpcf X-Google-Smtp-Source: AGRyM1uTF4Dr5mIXu4TTXbkvOe5i02eEEj3MwvTHs7jOGRBNTguLbtMAXx4cQMd7A0MoHhFIspUf7w== X-Received: by 2002:a63:b742:0:b0:40c:8913:341f with SMTP id w2-20020a63b742000000b0040c8913341fmr5451213pgt.607.1655952423058; Wed, 22 Jun 2022 19:47:03 -0700 (PDT) Received: from localhost ([43.132.141.4]) by smtp.gmail.com with ESMTPSA id j5-20020aa783c5000000b0050dc7628183sm14682199pfn.93.2022.06.22.19.47.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Jun 2022 19:47:02 -0700 (PDT) X-Google-Original-From: Xionghu Luo To: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix ICE when multiple speculative targets are expanded in different ltrans unit [PR93318] Date: Thu, 23 Jun 2022 10:46:39 +0800 Message-Id: <20220623024639.3599442-1-xionghuluo@tencent.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, 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: Xionghu Luo via Gcc-patches From: Xionghu Luo Reply-To: Xionghu Luo Cc: hubicka@ucw.cz Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" There is a corner case for speculative multiple targets, that if speculative edges are streamed to different ltrans units, and then edges are expanded in one ltrans unit but the speculative property is not cleared by resolve_speculation in other ltrans unit finally cause ICE. This patch fixes this by adding checking to guard speculative edge without no indirect edge binded to it. No case is provided since this is from large program with 128 LTO ltrans units not easy to reduce originated from protobuf. Bootstrap and regression tested pass on x86_64-linux-gnu, OK for master? Signed-off-by: Xionghu Luo gcc/ChangeLog: PR ipa/93318 * cgraph.cc (cgraph_edge::resolve_speculation): Remove speculative info if no indirect edge found. * cgraph.h: Return NULL if the edges are resloved in other ltrans units. * tree-inline.cc (copy_bb): Only clone current edge if the speculative call is processed in other ltrans units. Signed-off-by: Xionghu Luo --- gcc/cgraph.cc | 7 +++++++ gcc/cgraph.h | 3 ++- gcc/tree-inline.cc | 11 +++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/gcc/cgraph.cc b/gcc/cgraph.cc index 7eeda53ca84..120c0ac7650 100644 --- a/gcc/cgraph.cc +++ b/gcc/cgraph.cc @@ -1217,6 +1217,13 @@ cgraph_edge::resolve_speculation (cgraph_edge *edge, tree callee_decl) e2 = edge; ref = e2->speculative_call_target_ref (); edge = edge->speculative_call_indirect_edge (); + if (!edge) + { + e2->speculative = false; + ref->remove_reference (); + return e2; + } + if (!callee_decl || !ref->referred->semantically_equivalent_p (symtab_node::get (callee_decl))) diff --git a/gcc/cgraph.h b/gcc/cgraph.h index 4be67e3cea9..5404f023e31 100644 --- a/gcc/cgraph.h +++ b/gcc/cgraph.h @@ -1773,11 +1773,12 @@ public: if (!callee) return this; for (cgraph_edge *e2 = caller->indirect_calls; - true; e2 = e2->next_callee) + e2; e2 = e2->next_callee) if (e2->speculative && call_stmt == e2->call_stmt && lto_stmt_uid == e2->lto_stmt_uid) return e2; + return NULL; } /* When called on any edge in speculative call and when given any target diff --git a/gcc/tree-inline.cc b/gcc/tree-inline.cc index 043e1d5987a..777d9efdd70 100644 --- a/gcc/tree-inline.cc +++ b/gcc/tree-inline.cc @@ -2262,6 +2262,17 @@ copy_bb (copy_body_data *id, basic_block bb, cgraph_edge *indirect = old_edge->speculative_call_indirect_edge (); + if (indirect == NULL + && old_edge->num_speculative_call_targets_p () + == 0) + { + cgraph_edge::resolve_speculation (old_edge); + edge = old_edge->clone (id->dst_node, call_stmt, + gimple_uid (stmt), num, + den, true); + edge->count = copy_basic_block->count; + break; + } profile_count indir_cnt = indirect->count; /* Next iterate all direct edges, clone it and its