From patchwork Mon Jul 1 12:02:24 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 256100 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "localhost", Issuer "www.qmailtoaster.com" (not verified)) by ozlabs.org (Postfix) with ESMTPS id 2C6A02C009F for ; Mon, 1 Jul 2013 22:02:44 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:cc:subject:references :in-reply-to:content-type; q=dns; s=default; b=QSE3ZNzWABR97tUph csosxWkK5gYcQxaIjny/atbKo54NvxTLbX9vgYosjc3Zy6eKn+j2eyKbJhY46QXJ jMhut3k4Rcq10kszpkVXST7jmLjPKWC6OgvIv1OXTqdpaj7B49k1U3NUe4QFvkLO tCoYNhfLQWYCi8SQTAoXmke8N4= 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 :message-id:date:from:mime-version:to:cc:subject:references :in-reply-to:content-type; s=default; bh=lGZYnpqs7Eo8XetMBRYqJsz zDCI=; b=dkNd4qndmDBOOu2+pBC4lc687ckU8sWGGWqxk+fzPTvFZWVjkePb46L E8M8+I3vuNYvuQDXwa/e7qck0vQNoUwH9b0wXDjWH7QpPaNRwMlYHQ4XUQMayqV7 +ZsVREagZk0hqT5gqJtVB5DAiSLYi4MR+RachJ6Q1+xqwewESu8Y= Received: (qmail 31188 invoked by alias); 1 Jul 2013 12:02:37 -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 31177 invoked by uid 89); 1 Jul 2013 12:02:37 -0000 X-Spam-SWARE-Status: No, score=-4.4 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, KHOP_THREADED, RCVD_IN_HOSTKARMA_W, RCVD_IN_HOSTKARMA_WL, TW_CF autolearn=ham version=3.3.1 Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Mon, 01 Jul 2013 12:02:36 +0000 Received: from svr-orw-fem-01.mgc.mentorg.com ([147.34.98.93]) by relay1.mentorg.com with esmtp id 1UtcoT-0003hq-TV from Tom_deVries@mentor.com ; Mon, 01 Jul 2013 05:02:33 -0700 Received: from SVR-IES-FEM-01.mgc.mentorg.com ([137.202.0.104]) by svr-orw-fem-01.mgc.mentorg.com over TLS secured channel with Microsoft SMTPSVC(6.0.3790.4675); Mon, 1 Jul 2013 05:02:33 -0700 Received: from [127.0.0.1] (137.202.0.76) by SVR-IES-FEM-01.mgc.mentorg.com (137.202.0.104) with Microsoft SMTP Server id 14.2.247.3; Mon, 1 Jul 2013 13:02:31 +0100 Message-ID: <51D16FD0.3010800@mentor.com> Date: Mon, 1 Jul 2013 14:02:24 +0200 From: Tom de Vries User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130623 Thunderbird/17.0.7 MIME-Version: 1.0 To: Richard Biener CC: Cesar Philippidis , "gcc-patches@gcc.gnu.org" , , Subject: Re: [PATCH] if-to-switch pass References: <51C4B99C.8030503@mentor.com> In-Reply-To: X-Virus-Found: No On 24/06/13 14:28, Richard Biener wrote: > On Fri, Jun 21, 2013 at 10:37 PM, Cesar Philippidis > wrote: >> Here is an updated version of Tom's if-to-switch conversion pass that >> was originally posted here: >> >> . >> >> I corrected a build problem with ARM by including "tm_p.h" and an ICE >> caused by NULL_TREE argument being passed to fold_binary () inside >> refine_range_plus (). Also, TODO_ggc_collect has been removed in the >> gimple_opt_pass struct. >> >> I bootstrapped and regression tested on x86_64-unknown-linux-gnu and >> arm-none-linux-gnueabi. OK for trunk? > > As we are doing switch-to-if conversion in the pass after this it looks like > as if we can save us intermediate code generation if the two passes were > unified? That is, have a analysis phase that populates an internal > representation > of the switch / cascaded if and peforms transforms based on a single analysis > of that representation. > Richard, I think that's doable, but it would be nice if we can get it committed in the current form already. > I also dislike the two passes being in early optimizations - that way they do > not see the effects of IPA inlining / LTO IPA-CP transforms. > I'd rather move > it way down towards RTL expansion (though eventually some may say that > switch-conversion may enable vectorization opportunities for example). > Right, you discussed that with Steven here earlier: http://gcc.gnu.org/ml/gcc-patches/2012-07/msg01156.html. Steven proposed to move pass_switch_conversion to before split_functions. Attached patch attempts to do that, I'm testing that now. That doesn't address your concern about seeing effects of IPA inlining / LTO IPA-CP transforms though. Is this patch ok (once tested), or do you really want pass_switch_conversion later, say the first in pass_all_optimizations, or f.i. after pass_pre to pick-up on tail-merge creating opportunities for if-to-switch conversion once we check that in before or merge with pass_switch_conversion? Thanks, - Tom 2013-07-01 Tom de Vries passes.c (init_optimization_passes): Move pass_convert_switch to before pass_{feedback_,}split_functions. tree-pass.h (pass_feedback_convert_switch): Declare new pass. tree-switch-conversion.c (switchconv_gate): Don't run when profiling. (feedback_switchconv_gate): New function. (pass_feedback_convert_switch): New pass. diff --git a/gcc/passes.c b/gcc/passes.c index 761f030..2d47239 100644 --- a/gcc/passes.c +++ b/gcc/passes.c @@ -1338,13 +1338,13 @@ init_optimization_passes (void) NEXT_PASS (pass_cd_dce); NEXT_PASS (pass_early_ipa_sra); NEXT_PASS (pass_tail_recursion); - NEXT_PASS (pass_convert_switch); NEXT_PASS (pass_cleanup_eh); NEXT_PASS (pass_profile); NEXT_PASS (pass_local_pure_const); /* Split functions creates parts that are not run through early optimizations again. It is thus good idea to do this late. */ + NEXT_PASS (pass_convert_switch); NEXT_PASS (pass_split_functions); } NEXT_PASS (pass_release_ssa_names); @@ -1355,6 +1355,7 @@ init_optimization_passes (void) NEXT_PASS (pass_ipa_tree_profile); { struct opt_pass **p = &pass_ipa_tree_profile.pass.sub; + NEXT_PASS (pass_feedback_convert_switch); NEXT_PASS (pass_feedback_split_functions); } NEXT_PASS (pass_ipa_increase_alignment); diff --git a/gcc/tree-pass.h b/gcc/tree-pass.h index b8c59a7..8c2e2df 100644 --- a/gcc/tree-pass.h +++ b/gcc/tree-pass.h @@ -489,6 +489,7 @@ extern struct gimple_opt_pass pass_early_inline; extern struct gimple_opt_pass pass_inline_parameters; extern struct gimple_opt_pass pass_update_address_taken; extern struct gimple_opt_pass pass_convert_switch; +extern struct gimple_opt_pass pass_feedback_convert_switch; /* The root of the compilation pass tree, once constructed. */ extern struct opt_pass *all_passes, *all_small_ipa_passes, *all_lowering_passes, diff --git a/gcc/tree-switch-conversion.c b/gcc/tree-switch-conversion.c index 9ad7daf..1793720 100644 --- a/gcc/tree-switch-conversion.c +++ b/gcc/tree-switch-conversion.c @@ -1460,7 +1460,9 @@ do_switchconv (void) static bool switchconv_gate (void) { - return flag_tree_switch_conversion != 0; + return (flag_tree_switch_conversion != 0 + && !profile_arc_flag + && !flag_branch_probabilities); } struct gimple_opt_pass pass_convert_switch = @@ -1485,3 +1487,35 @@ struct gimple_opt_pass pass_convert_switch = | TODO_verify_flow /* todo_flags_finish */ } }; + +/* The pass gate. */ + +static bool +feedback_switchconv_gate (void) +{ + return (flag_tree_switch_conversion != 0 + && flag_branch_probabilities); +} + +struct gimple_opt_pass pass_feedback_convert_switch = +{ + { + GIMPLE_PASS, + "switchconv", /* name */ + OPTGROUP_NONE, /* optinfo_flags */ + feedback_switchconv_gate, /* gate */ + do_switchconv, /* execute */ + NULL, /* sub */ + NULL, /* next */ + 0, /* static_pass_number */ + TV_TREE_SWITCH_CONVERSION, /* tv_id */ + PROP_cfg | PROP_ssa, /* properties_required */ + 0, /* properties_provided */ + 0, /* properties_destroyed */ + 0, /* todo_flags_start */ + TODO_update_ssa + | TODO_verify_ssa + | TODO_verify_stmts + | TODO_verify_flow /* todo_flags_finish */ + } +};