From patchwork Tue Oct 10 13:40:37 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 823845 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-463861-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="wE7bMfLi"; 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 3yBJM46Ht0z9tYR for ; Wed, 11 Oct 2017 00:47:09 +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=fhKgF8Dxz/uHBZ+VHefL4ff9V0oeoAU5tZf2maRhQoaMNTpFGBQ4Y Ror71B7a0pCuEYRTm4RejEDmBDgwmPGDfasqzJyNpXFigIgSL5TfbuElqNq9VvZO JNih8HpXGrn7NWGOzgIbS9u1JqB93OoKOOL0Cb8HtKk+1z9fAq24h0= 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=vNmsgqYRsDqK0dKF51efITrZwes=; b=wE7bMfLiE/nMr7YyBjB1 IWWYASDQKWi5axbO6oDjpp/vGrVqpkCIQMaLAQkZ1fYD4RS2RywtYawbL5LPfARR GMKo5UqvmHk5zmxRyjt+pva0QXlB9K7gjW3Ihy8jOb+wz+pDfK4d0Xhn6RYr00xi 0cuYW4z97va4WMZHbyJ3FjE= Received: (qmail 105861 invoked by alias); 10 Oct 2017 13:40:42 -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 105143 invoked by uid 89); 10 Oct 2017 13:40:42 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.9 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 spammy=cuts, Interpret 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 13:40:39 +0000 Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 224EBAC0C for ; Tue, 10 Oct 2017 13:40:37 +0000 (UTC) Date: Tue, 10 Oct 2017 15:40:37 +0200 (CEST) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] More SCEV TLC Message-ID: User-Agent: Alpine 2.20 (LSU 67 2015-01-07) MIME-Version: 1.0 This cuts the recursion in analyze_scalar_evolution_1 somewhat more making the flow easier to understand. In particular no_evolution_in_loop_p is replaced with a positive test on chrec_contains_symbols_defined_in_loop guarding further analysis after skipping overall effects of loops. I've also included minor optimization / simplification regarding to default-defs and unhandled types so they do not pollute the cache. Bootstrapped and tested with asserts in place verifying everything, re-bootstrapping / testing with the actual patch below. In case you're curious I'm trying to make SCEV analysis region aware, replacing "loop" with "entry edge" in relevant APIs. Those cleanups are to make it easier to understand what contexts care about loops and which not. Richard. 2017-10-10 Richard Biener * tree-scalar-evolution.c (get_scalar_evolution): Handle default-defs and types we do not want to analyze. (interpret_loop_phi): Replace unreachable code with an assert. (compute_scalar_evolution_in_loop): Remove and inline ... (analyze_scalar_evolution_1): ... here, replacing condition with what makes the intent clearer. Remove handling of cases get_scalar_evolution now handles. Index: gcc/tree-scalar-evolution.c =================================================================== --- gcc/tree-scalar-evolution.c (revision 253585) +++ gcc/tree-scalar-evolution.c (working copy) @@ -564,22 +564,30 @@ get_scalar_evolution (basic_block instan nb_get_scev++; } - switch (TREE_CODE (scalar)) - { - case SSA_NAME: - res = *find_var_scev_info (instantiated_below, scalar); - break; + if (VECTOR_TYPE_P (TREE_TYPE (scalar)) + || TREE_CODE (TREE_TYPE (scalar)) == COMPLEX_TYPE) + /* For chrec_dont_know we keep the symbolic form. */ + res = scalar; + else + switch (TREE_CODE (scalar)) + { + case SSA_NAME: + if (SSA_NAME_IS_DEFAULT_DEF (scalar)) + res = scalar; + else + res = *find_var_scev_info (instantiated_below, scalar); + break; - case REAL_CST: - case FIXED_CST: - case INTEGER_CST: - res = scalar; - break; + case REAL_CST: + case FIXED_CST: + case INTEGER_CST: + res = scalar; + break; - default: - res = chrec_not_analyzed_yet; - break; - } + default: + res = chrec_not_analyzed_yet; + break; + } if (dump_file && (dump_flags & TDF_SCEV)) { @@ -1628,19 +1636,7 @@ interpret_loop_phi (struct loop *loop, g struct loop *phi_loop = loop_containing_stmt (loop_phi_node); tree init_cond; - if (phi_loop != loop) - { - struct loop *subloop; - tree evolution_fn = analyze_scalar_evolution - (phi_loop, PHI_RESULT (loop_phi_node)); - - /* Dive one level deeper. */ - subloop = superloop_at_depth (phi_loop, loop_depth (loop) + 1); - - /* Interpret the subloop. */ - res = compute_overall_effect_of_inner_loop (subloop, evolution_fn); - return res; - } + gcc_assert (phi_loop == loop); /* Otherwise really interpret the loop phi. */ init_cond = analyze_initial_condition (loop_phi_node); @@ -2016,29 +2012,6 @@ interpret_gimple_assign (struct loop *lo - instantiate_parameters. */ -/* Compute and return the evolution function in WRTO_LOOP, the nearest - common ancestor of DEF_LOOP and USE_LOOP. */ - -static tree -compute_scalar_evolution_in_loop (struct loop *wrto_loop, - struct loop *def_loop, - tree ev) -{ - bool val; - tree res; - - if (def_loop == wrto_loop) - return ev; - - def_loop = superloop_at_depth (def_loop, loop_depth (wrto_loop) + 1); - res = compute_overall_effect_of_inner_loop (def_loop, ev); - - if (no_evolution_in_loop_p (res, wrto_loop->num, &val) && val) - return res; - - return analyze_scalar_evolution_1 (wrto_loop, res); -} - /* Helper recursive function. */ static tree @@ -2050,20 +2023,14 @@ analyze_scalar_evolution_1 (struct loop struct loop *def_loop; tree res; - if (loop == NULL - || TREE_CODE (type) == VECTOR_TYPE - || TREE_CODE (type) == COMPLEX_TYPE) - return chrec_dont_know; - if (TREE_CODE (var) != SSA_NAME) return interpret_expr (loop, NULL, var); def = SSA_NAME_DEF_STMT (var); bb = gimple_bb (def); - def_loop = bb ? bb->loop_father : NULL; + def_loop = bb->loop_father; - if (bb == NULL - || !flow_bb_inside_loop_p (loop, bb)) + if (!flow_bb_inside_loop_p (loop, bb)) { /* Keep symbolic form, but look through obvious copies for constants. */ res = follow_copies_to_constant (var); @@ -2073,8 +2040,11 @@ analyze_scalar_evolution_1 (struct loop if (loop != def_loop) { res = analyze_scalar_evolution_1 (def_loop, var); - res = compute_scalar_evolution_in_loop (loop, def_loop, res); - + struct loop *loop_to_skip = superloop_at_depth (def_loop, + loop_depth (loop) + 1); + res = compute_overall_effect_of_inner_loop (loop_to_skip, res); + if (chrec_contains_symbols_defined_in_loop (res, loop->num)) + res = analyze_scalar_evolution_1 (loop, res); goto set_and_end; }