From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 94403 invoked by alias); 30 Nov 2015 15:51:26 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 94393 invoked by uid 89); 30 Nov 2015 15:51:26 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.0 required=5.0 tests=AWL,BAYES_00,KAM_ASCII_DIVIDERS,RCVD_IN_DNSWL_LOW,SPF_PASS,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 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 (CAMELLIA256-SHA encrypted) ESMTPS; Mon, 30 Nov 2015 15:51:25 +0000 Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id D88E1AAB2; Mon, 30 Nov 2015 15:51:20 +0000 (UTC) Date: Mon, 30 Nov 2015 16:00:00 -0000 From: Richard Biener To: Marek Polacek cc: GCC Patches , Joseph Myers , Jakub Jelinek , ebotcazou@adacore.com Subject: Re: [PATCH] Add save_expr langhook (PR c/68513) In-Reply-To: <20151130154143.GF28072@redhat.com> Message-ID: References: <20151127185531.GA28072@redhat.com> <43651703-7ABE-491D-8D5B-863E921EA365@suse.de> <20151130154143.GF28072@redhat.com> User-Agent: Alpine 2.11 (LSU 23 2013-08-11) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-SW-Source: 2015-11/txt/msg03495.txt.bz2 On Mon, 30 Nov 2015, Marek Polacek wrote: > On Sat, Nov 28, 2015 at 08:50:12AM +0100, Richard Biener wrote: > > Different approach: after the FE folds (unexpectedly?), scan the result for > > SAVE_EXPRs and if found, drop the folding. > > Neither this fixes this problem completely, because we simply don't know where > those SAVE_EXPRs might be introduced: it might be convert(), but e.g. when I > changed the original testcase a tiny bit (added -), then those SAVE_EXPRs were > introduced in a different spot (via c_process_stmt_expr -> c_fully_fold). So the following "disables" save_expr generation from generic-match.c by failing to simplify if save_expr would end up not returning a non-save_expr. I expect this will make fixing PR68590 difficult (w/o re-introducing some fold-const.c code or changing genmatch to "special-case" things). The other option for this PR is to re-introduce the TREE_SIDE_EFFECTS check I removed earlier (to avoid un-CSEing large expressions at -O0 for example) and thus only FAIL if the save_expr were needed for correctness. Richard. Index: gcc/tree.c =================================================================== --- gcc/tree.c (revision 231065) +++ gcc/tree.c (working copy) @@ -3231,8 +3231,6 @@ decl_address_ip_invariant_p (const_tree not handle arithmetic; that's handled in skip_simple_arithmetic and tree_invariant_p). */ -static bool tree_invariant_p (tree t); - static bool tree_invariant_p_1 (tree t) { @@ -3282,7 +3280,7 @@ tree_invariant_p_1 (tree t) /* Return true if T is function-invariant. */ -static bool +bool tree_invariant_p (tree t) { tree inner = skip_simple_arithmetic (t); Index: gcc/tree.h =================================================================== --- gcc/tree.h (revision 231065) +++ gcc/tree.h (working copy) @@ -4320,6 +4320,10 @@ extern tree staticp (tree); extern tree save_expr (tree); +/* Return true if T is function-invariant. */ + +extern bool tree_invariant_p (tree); + /* Look inside EXPR into any simple arithmetic operations. Return the outermost non-arithmetic or non-invariant node. */ Index: gcc/genmatch.c =================================================================== --- gcc/genmatch.c (revision 231065) +++ gcc/genmatch.c (working copy) @@ -3106,7 +3106,9 @@ dt_simplify::gen_1 (FILE *f, int indent, else if (is_a (opr)) is_predicate = true; /* Search for captures used multiple times in the result expression - and dependent on TREE_SIDE_EFFECTS emit a SAVE_EXPR. */ + and check if we can safely evaluate it multiple times. Otherwise + fail, avoiding a SAVE_EXPR because that confuses the C FE + const expression folding. */ if (!is_predicate) for (int i = 0; i < s->capture_max + 1; ++i) { @@ -3114,8 +3116,8 @@ dt_simplify::gen_1 (FILE *f, int indent, continue; if (cinfo.info[i].result_use_count > 1) fprintf_indent (f, indent, - "captures[%d] = save_expr (captures[%d]);\n", - i, i); + "if (! tree_invariant_p (captures[%d])) " + "return NULL_TREE;\n", i); } for (unsigned j = 0; j < e->ops.length (); ++j) {