From patchwork Wed Jul 29 10:39:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 1338249 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.de Received: from 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 RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BGqms0z8fz9sSd for ; Wed, 29 Jul 2020 20:39:56 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 002403842421; Wed, 29 Jul 2020 10:39:54 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by sourceware.org (Postfix) with ESMTPS id 4D7553844045 for ; Wed, 29 Jul 2020 10:39:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 4D7553844045 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=rguenther@suse.de X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id B15C2ACF2 for ; Wed, 29 Jul 2020 10:40:02 +0000 (UTC) Date: Wed, 29 Jul 2020 12:39:51 +0200 (CEST) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] verify SCEV cache for stale entries Message-ID: User-Agent: Alpine 2.21 (LSU 202 2017-01-01) MIME-Version: 1.0 X-Spam-Status: No, score=-10.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: , Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" This adds verification for the SCEV cache to avoid stale entries that when picked up will lead to ICEs or other surprises. Bootstrapped / tested on x86_64-unknown-linux-gnu with the two previous fixes. Posted for reference and archival purposes, I'm not going to push this at this point. 2020-07-29 Richard Biener * passes.c (execute_function_todo): Call verify_scev_cache if it is initialized. * tree-scalar-evolution.h (verify_scev_cache): Declare. * tree-scalar-evolution.c (verify_scev_cache_r): New. (verify_scev_cache): Likewise. --- gcc/passes.c | 11 ++++++++--- gcc/tree-scalar-evolution.c | 29 +++++++++++++++++++++++++++++ gcc/tree-scalar-evolution.h | 1 + 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/gcc/passes.c b/gcc/passes.c index a5da9a46f4e..c3c3a086236 100644 --- a/gcc/passes.c +++ b/gcc/passes.c @@ -63,6 +63,7 @@ along with GCC; see the file COPYING3. If not see #include "diagnostic-core.h" /* for fnotice */ #include "stringpool.h" #include "attribs.h" +#include "tree-scalar-evolution.h" /* for verify_scev_cache. */ using namespace gcc; @@ -1994,9 +1995,13 @@ execute_function_todo (function *fn, void *data) verify_gimple_in_seq (gimple_body (cfun->decl)); } if (cfun->curr_properties & PROP_ssa) - /* IPA passes leave stmts to be fixed up, so make sure to - not verify SSA operands whose verifier will choke on that. */ - verify_ssa (true, !from_ipa_pass); + { + /* IPA passes leave stmts to be fixed up, so make sure to + not verify SSA operands whose verifier will choke on that. */ + verify_ssa (true, !from_ipa_pass); + if (scev_initialized_p ()) + verify_scev_cache (); + } /* IPA passes leave basic-blocks unsplit, so make sure to not trip on that. */ if ((cfun->curr_properties & PROP_cfg) diff --git a/gcc/tree-scalar-evolution.c b/gcc/tree-scalar-evolution.c index edab778277b..9645fed980c 100644 --- a/gcc/tree-scalar-evolution.c +++ b/gcc/tree-scalar-evolution.c @@ -284,6 +284,7 @@ along with GCC; see the file COPYING3. If not see #include "tree-into-ssa.h" #include "builtins.h" #include "case-cfn-macros.h" +#include "diagnostic.h" static tree analyze_scalar_evolution_1 (class loop *, tree); static tree analyze_scalar_evolution_for_address_of (class loop *loop, @@ -3025,6 +3026,34 @@ scev_reset (void) } } +/* CHREC walker for verify_scev_cache. */ + +static tree +verify_scev_cache_r (tree *tp, int *walk_subtrees, void *) +{ + if (TREE_CODE (*tp) == SSA_NAME + && SSA_NAME_IN_FREE_LIST (*tp)) + internal_error ("stale SCEV hash table entries"); + if (!EXPR_P (*tp)) + *walk_subtrees = 0; + return NULL_TREE; +} + +/* Verify the SCEV cache has no stale entries. */ + +void +verify_scev_cache () +{ + for (auto i = scalar_evolution_info->begin (); + i != scalar_evolution_info->end (); ++i) + { + if ((*i)->name_version >= num_ssa_names + || ! ssa_name ((*i)->name_version)) + internal_error ("stale SCEV hash table entries"); + walk_tree (&(*i)->chrec, verify_scev_cache_r, NULL, NULL); + } +} + /* Return true if the IV calculation in TYPE can overflow based on the knowledge of the upper bound on the number of iterations of LOOP, the BASE and STEP of IV. diff --git a/gcc/tree-scalar-evolution.h b/gcc/tree-scalar-evolution.h index e2fbfb55bd0..d0c578708ac 100644 --- a/gcc/tree-scalar-evolution.h +++ b/gcc/tree-scalar-evolution.h @@ -42,6 +42,7 @@ extern bool simple_iv (class loop *, class loop *, tree, struct affine_iv *, bool); extern bool iv_can_overflow_p (class loop *, tree, tree, tree); extern tree compute_overall_effect_of_inner_loop (class loop *, tree); +extern void verify_scev_cache (); /* Returns the basic block preceding LOOP, or the CFG entry block when the loop is function's body. */