From patchwork Tue Oct 10 10:34:34 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 823790 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-463849-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="VJN72AIP"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yBD550PZWz9s7F for ; Tue, 10 Oct 2017 21:34:47 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=JOc3uem2mKDJGtfXTbcwwjYxhkqGliuntKn5MfviqZc3V6Mn+cr+8 x8E7S90XiEr9pibz5w92ol+ybYQg3IjHPwZ3mDAnCJak1P+OS5xYmIXFnGW8s9hU Rm/tHrX+LszeiesRlyf6UzmgMWm4a95rw1hnQ/T1gBs3wrwX9au9cY= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; s= default; bh=QofeMIQb/RQcxbkVom+ERYLs0Bk=; b=VJN72AIPibJlIiwHkyM9 s8uxmnRcMXoGMjlSPhOL9GW/cil/o8pT7FATJ+hQGeoiLzR0RhqS/OQ+KBUr9WoO su3O2JDr1MpM3LiW3Jr3W2AKUcqR/vNhb6tapeY2ZZhkHCduAUJKlBZmOdGQ9uLO NDjd5fC7Ko5ah9tvqJ3achU= Received: (qmail 87640 invoked by alias); 10 Oct 2017 10:34:39 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 87628 invoked by uid 89); 10 Oct 2017 10:34:39 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.1 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mx2.suse.de Received: from mx2.suse.de (HELO mx2.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 10 Oct 2017 10:34:37 +0000 Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 97279AB9D for ; Tue, 10 Oct 2017 10:34:34 +0000 (UTC) Date: Tue, 10 Oct 2017 12:34:34 +0200 (CEST) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] Simplify SCEV entry Message-ID: User-Agent: Alpine 2.20 (LSU 67 2015-01-07) MIME-Version: 1.0 This simplifies SCEV analyze_scalar_evolution_1 by removing what appeared to be dead code for the case of res != chrec_not_analyzed_yet. Adding a gcc_unrechable () turned up a rather serious bug though as in the loop pipeline we get a messed up SCEV cache if CFG cleanup renumbers blocks given SCEV uses BB indices in the cache. Fixing that makes bootstrapping with gcc_unreachable in the place of the removed code below work: Index: gcc/tree-scalar-evolution.c =================================================================== --- gcc/tree-scalar-evolution.c (revision 253545) +++ gcc/tree-scalar-evolution.c (working copy) @@ -2072,8 +2072,11 @@ analyze_scalar_evolution_1 (struct loop if (res != chrec_not_analyzed_yet) { if (loop != bb->loop_father) + { + gcc_unreachable (); res = compute_scalar_evolution_in_loop (find_common_loop (loop, bb->loop_father), bb->loop_father, res); + } goto set_and_end; } thus the following (which is really a bugfix plus code simplification). Bootstrap and regtest running on x86_64-unknown-linux-gnu. I should probably backport that CFG cleanup hunk... Richard. 2017-10-10 Richard Biener * tree-cfgcleanup.c (cleanup_tree_cfg_noloop): Avoid compacting blocks if SCEV is active. * tree-scalar-evolution.c (analyze_scalar_evolution_1): Remove dead code. (analyze_scalar_evolution): Handle cached evolutions the obvious way. (scev_initialize): Assert we are not yet initialized. Index: gcc/tree-cfgcleanup.c =================================================================== --- gcc/tree-cfgcleanup.c (revision 253580) +++ gcc/tree-cfgcleanup.c (working copy) @@ -892,7 +892,11 @@ cleanup_tree_cfg_noloop (void) changed |= cleanup_tree_cfg_1 (); gcc_assert (dom_info_available_p (CDI_DOMINATORS)); - compact_blocks (); + + /* Do not renumber blocks if the SCEV cache is active, it is indexed by + basic-block numbers. */ + if (! scev_initialized_p ()) + compact_blocks (); checking_verify_flow_info (); Index: gcc/tree-scalar-evolution.c =================================================================== --- gcc/tree-scalar-evolution.c (revision 253580) +++ gcc/tree-scalar-evolution.c (working copy) @@ -281,7 +281,7 @@ along with GCC; see the file COPYING3. #include "tree-ssa-propagate.h" #include "gimple-fold.h" -static tree analyze_scalar_evolution_1 (struct loop *, tree, tree); +static tree analyze_scalar_evolution_1 (struct loop *, tree); static tree analyze_scalar_evolution_for_address_of (struct loop *loop, tree var); @@ -2036,18 +2036,19 @@ compute_scalar_evolution_in_loop (struct if (no_evolution_in_loop_p (res, wrto_loop->num, &val) && val) return res; - return analyze_scalar_evolution_1 (wrto_loop, res, chrec_not_analyzed_yet); + return analyze_scalar_evolution_1 (wrto_loop, res); } /* Helper recursive function. */ static tree -analyze_scalar_evolution_1 (struct loop *loop, tree var, tree res) +analyze_scalar_evolution_1 (struct loop *loop, tree var) { tree type = TREE_TYPE (var); gimple *def; basic_block bb; struct loop *def_loop; + tree res; if (loop == NULL || TREE_CODE (type) == VECTOR_TYPE @@ -2069,18 +2070,9 @@ analyze_scalar_evolution_1 (struct loop goto set_and_end; } - if (res != chrec_not_analyzed_yet) - { - if (loop != bb->loop_father) - res = compute_scalar_evolution_in_loop - (find_common_loop (loop, bb->loop_father), bb->loop_father, res); - - goto set_and_end; - } - if (loop != def_loop) { - res = analyze_scalar_evolution_1 (def_loop, var, chrec_not_analyzed_yet); + res = analyze_scalar_evolution_1 (def_loop, var); res = compute_scalar_evolution_in_loop (loop, def_loop, res); goto set_and_end; @@ -2144,7 +2136,8 @@ analyze_scalar_evolution (struct loop *l } res = get_scalar_evolution (block_before_loop (loop), var); - res = analyze_scalar_evolution_1 (loop, var, res); + if (res == chrec_not_analyzed_yet) + res = analyze_scalar_evolution_1 (loop, var); if (dump_file && (dump_flags & TDF_SCEV)) fprintf (dump_file, ")\n"); @@ -3264,6 +3257,8 @@ scev_initialize (void) { struct loop *loop; + gcc_assert (! scev_initialized_p ()); + scalar_evolution_info = hash_table::create_ggc (100); initialize_scalar_evolutions_analyzer ();