From patchwork Tue Dec 1 14:19:08 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 550910 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.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4E1081401DE for ; Wed, 2 Dec 2015 01:19:20 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=wNMxujSI; dkim-atps=neutral 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=ceOtq26ouzOd5ycErABPZ3Vm8z3pYSWFlhDzkPNgarnTm9Ws1DQCO 5mZtZ9UfQUIEbeU1K/LCVNWdtXovsz0PHiKsZR89kibkPxzQF0dR6wBzJTW3Fj7m koYSmRkJ91lyNmBseJM0JLYyAArThm+ge3hh7r1jpI6bfwyGXIWtJE= 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=jF5s49lJ21wKAXEBaEV2LUShF0U=; b=wNMxujSIGI9coTz8uEPv L/GbJnX+IJn1enSToMFqrlOBQbZQd4KrH197lmGf/csztUq6nc8YBnVz2Ue2ei8n BGyua8F9O2g9ihXoliawzaB2FPMDebxX0oQ4pLNjCWDtYSOjLMFw7KGA0W4xJy6e EXVbYuT9DjbJxZm/Iuw1akk= Received: (qmail 69252 invoked by alias); 1 Dec 2015 14:19:13 -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 69242 invoked by uid 89); 1 Dec 2015 14:19:12 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.4 required=5.0 tests=AWL, BAYES_00, 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; Tue, 01 Dec 2015 14:19:11 +0000 Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 92875AD01 for ; Tue, 1 Dec 2015 14:19:08 +0000 (UTC) Date: Tue, 1 Dec 2015 15:19:08 +0100 (CET) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix PR68590 Message-ID: User-Agent: Alpine 2.11 (LSU 23 2013-08-11) MIME-Version: 1.0 This fixes the PR in another way as well, allowing as many capture uses in the replacement expression as in the original one, avoiding some spurious save_exprs that way (and not perform "CSE" within the match-and-simplify framework). Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to trunk. Richard. 2015-12-01 Richard Biener PR middle-end/68590 * genmatch.c (struct capture_info): Add match_use_count. (capture_info::walk_match): Increment match_use_count. (dt_simplify::gen_1): For GENERIC, only wrap multi-use replacements in a save_expr if they occur more often than in the original expression. Index: gcc/genmatch.c =================================================================== --- gcc/genmatch.c (revision 231101) +++ gcc/genmatch.c (working copy) @@ -1851,7 +1850,8 @@ struct capture_info bool force_single_use; bool cond_expr_cond_p; unsigned long toplevel_msk; - int result_use_count; + unsigned match_use_count; + unsigned result_use_count; unsigned same_as; capture *c; }; @@ -1901,6 +1901,7 @@ capture_info::walk_match (operand *o, un if (capture *c = dyn_cast (o)) { unsigned where = c->where; + info[where].match_use_count++; info[where].toplevel_msk |= 1 << toplevel_arg; info[where].force_no_side_effects_p |= conditional_p; info[where].cond_expr_cond_p |= cond_expr_cond_p; @@ -3106,13 +3107,16 @@ 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 wrap them in a SAVE_EXPR. Allow as many uses as in the + original expression. */ if (!is_predicate) for (int i = 0; i < s->capture_max + 1; ++i) { - if (cinfo.info[i].same_as != (unsigned)i) + if (cinfo.info[i].same_as != (unsigned)i + || cinfo.info[i].cse_p) continue; - if (cinfo.info[i].result_use_count > 1) + if (cinfo.info[i].result_use_count + > cinfo.info[i].match_use_count) fprintf_indent (f, indent, "captures[%d] = save_expr (captures[%d]);\n", i, i);