From patchwork Tue Sep 16 06:25:13 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prathamesh Kulkarni X-Patchwork-Id: 389963 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 B5C0C140077 for ; Tue, 16 Sep 2014 16:25:26 +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 :mime-version:in-reply-to:references:date:message-id:subject :from:to:content-type; q=dns; s=default; b=N6KRNGo3w4eS35rAPWFlY zeQBG3/UgTHExB7HMTItpjfyeKcfCj4MXFDdlQYzq8K9KFl77b5+C7mkq+3plZxs gDraZz169lcYf5CHw54wna4eULE4w43+5LgSxNIpgBJHdL7srIIiKUNMwnjQXv7b SlijpK5CRUqS1hlXUycV9k= 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 :mime-version:in-reply-to:references:date:message-id:subject :from:to:content-type; s=default; bh=BG35G7KS5XjUGELYJxS5V9b493M =; b=bCWZ47EOxwlSrlaU+V/x1/mam+lWRiB7g8CCb3B7mvWCPMo2sAFWuDopRLn eOhu5ZUK1S6k9nCwYcygM116eIR95WNHKPGx8BuY1v5uN9+HKnDRyXxhOkPmXwUp x28w6LTXWkuHp9Uf3sWC5kV8Tbom2igEk/hryvTg2udwBi5M= Received: (qmail 32375 invoked by alias); 16 Sep 2014 06:25:18 -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 32365 invoked by uid 89); 16 Sep 2014 06:25:17 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.3 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-oa0-f45.google.com Received: from mail-oa0-f45.google.com (HELO mail-oa0-f45.google.com) (209.85.219.45) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Tue, 16 Sep 2014 06:25:15 +0000 Received: by mail-oa0-f45.google.com with SMTP id m1so3361000oag.18 for ; Mon, 15 Sep 2014 23:25:14 -0700 (PDT) MIME-Version: 1.0 X-Received: by 10.182.246.39 with SMTP id xt7mr8990443obc.63.1410848714000; Mon, 15 Sep 2014 23:25:14 -0700 (PDT) Received: by 10.182.187.71 with HTTP; Mon, 15 Sep 2014 23:25:13 -0700 (PDT) In-Reply-To: References: Date: Tue, 16 Sep 2014 11:55:13 +0530 Message-ID: Subject: Re: [match-and-simplify] CSE with expression captures From: Prathamesh Kulkarni To: marc.glisse@inria.fr, Richard Biener , "gcc-patches@gcc.gnu.org" X-IsSubscribed: yes On Tue, Sep 16, 2014 at 2:15 AM, Marc Glisse wrote: > On Tue, 16 Sep 2014, Prathamesh Kulkarni wrote: > >> --- gcc/match-builtin.pd (revision 215271) >> +++ gcc/match-builtin.pd (working copy) >> @@ -44,8 +44,8 @@ >> /* ??? There is no way to CSE here. We'd need to support >> expression captures here, like with >> (mult (realpart@1 @0) @1) */ >> - (mult (realpart @0) (realpart @0)) >> - (mult (imagpart @0) (imagpart @0))))))) >> + (mult (realpart@1 @0) @1) + (mult (imagpart@2 @0) @2)))))) > > > Maybe remove the comment above? > > You seem to have trailing spaces on most of your new lines. Thanks, fixed. * genmatch.c (operand::gen_transform): Add dt_operand ** default argument to operand heirarchy. (expr::gen_transform): Adjust. (capture::gen_transform): Likewise. (dt_simplify::gen): Likewise. * match-builtins.pd: Adjust pattern to use expression captures in transform. Regards, Prathamesh > > -- > Marc Glisse Index: gcc/genmatch.c =================================================================== --- gcc/genmatch.c (revision 215271) +++ gcc/genmatch.c (working copy) @@ -250,7 +250,7 @@ enum op_type { OP_PREDICATE, OP_EXPR, OP_CAPTURE, OP_C_EXPR }; operand (enum op_type type_) : type (type_) {} enum op_type type; - virtual void gen_transform (FILE *f, const char *, bool, int, const char *) = 0; + virtual void gen_transform (FILE *f, const char *, bool, int, const char *, dt_operand ** = 0) = 0; }; struct predicate : public operand @@ -257,7 +257,7 @@ { predicate (const char *ident_) : operand (OP_PREDICATE), ident (ident_) {} const char *ident; - virtual void gen_transform (FILE *, const char *, bool, int, const char *) + virtual void gen_transform (FILE *, const char *, bool, int, const char *, dt_operand ** = 0) { gcc_unreachable (); } }; @@ -277,7 +277,7 @@ e_operation *operation; vec ops; const char *expr_type; - virtual void gen_transform (FILE *f, const char *, bool, int, const char *); + virtual void gen_transform (FILE *f, const char *, bool, int, const char *, dt_operand ** = 0); }; struct c_expr : public operand @@ -300,7 +300,7 @@ char *fname; vec ids; - virtual void gen_transform (FILE *f, const char *, bool, int, const char *); + virtual void gen_transform (FILE *f, const char *, bool, int, const char *, dt_operand **); void output_code (FILE *f, bool); }; @@ -310,7 +310,7 @@ : operand (OP_CAPTURE), where (where_), what (what_) {} const char *where; operand *what; - virtual void gen_transform (FILE *f, const char *, bool, int, const char *); + virtual void gen_transform (FILE *f, const char *, bool, int, const char *, dt_operand ** = 0); }; template<> @@ -894,7 +894,7 @@ void expr::gen_transform (FILE *f, const char *dest, bool gimple, int depth, - const char *in_type) + const char *in_type, dt_operand **indexes) { bool conversion_p = is_conversion (operation->op); const char *type = expr_type; @@ -945,7 +945,7 @@ is not unless we somehow discover what operand we can generate first and do it in the appropriate order. */ - : (i == 0 ? in_type : type)); + : (i == 0 ? in_type : type), indexes); } if (gimple) @@ -1043,7 +1043,7 @@ void -c_expr::gen_transform (FILE *f, const char *dest, bool, int, const char *) +c_expr::gen_transform (FILE *f, const char *dest, bool, int, const char *, dt_operand **) { /* If this expression has an outlined function variant, call it. */ if (fname) @@ -1063,8 +1063,19 @@ } void -capture::gen_transform (FILE *f, const char *dest, bool, int, const char *) +capture::gen_transform (FILE *f, const char *dest, bool gimple, int depth, const char *in_type, dt_operand **indexes) { + if (what && is_a (what)) + { + int index = atoi (where); + if (indexes[index] == 0) + { + char buf[20]; + sprintf (buf, "captures[%s]", where); + what->gen_transform (f, buf, gimple, depth, in_type, 0); + } + } + fprintf (f, "%s = captures[%s];\n", dest, where); } @@ -1806,7 +1817,7 @@ snprintf (dest, 32, " res_ops[%d]", j); e->ops[j]->gen_transform (f, dest, true, 1, is_conversion (e->operation->op) - ? NULL : "type"); + ? NULL : "type", indexes); } /* Re-fold the toplevel result. It's basically an embedded gimple_build w/o actually building the stmt. */ @@ -1816,7 +1827,7 @@ else if (s->result->type == operand::OP_CAPTURE || s->result->type == operand::OP_C_EXPR) { - s->result->gen_transform (f, "res_ops[0]", true, 1, "type"); + s->result->gen_transform (f, "res_ops[0]", true, 1, "type", indexes); fprintf (f, "*res_code = TREE_CODE (res_ops[0]);\n"); } else @@ -1835,7 +1846,7 @@ snprintf (dest, 32, " res_op%d", j); e->ops[j]->gen_transform (f, dest, false, 1, is_conversion (e->operation->op) - ? NULL : "type"); + ? NULL : "type", indexes); } /* Re-fold the toplevel result. */ if (e->operation->op->kind == id_base::CODE) @@ -1852,7 +1863,7 @@ || s->result->type == operand::OP_C_EXPR) { fprintf (f, " tree res;\n"); - s->result->gen_transform (f, " res", false, 1, "type"); + s->result->gen_transform (f, " res", false, 1, "type", indexes); fprintf (f, " return res;\n"); } else Index: gcc/match-builtin.pd =================================================================== --- gcc/match-builtin.pd (revision 215271) +++ gcc/match-builtin.pd (working copy) @@ -41,11 +41,8 @@ (simplify (CABS @0) (SQRT (plus - /* ??? There is no way to CSE here. We'd need to support - expression captures here, like with - (mult (realpart@1 @0) @1) */ - (mult (realpart @0) (realpart @0)) - (mult (imagpart @0) (imagpart @0))))))) + (mult (realpart@1 @0) @1) + (mult (imagpart@2 @0) @2)))))) /* From fold_binary. */ /* Optimize x*pow(x,c) as pow(x,c+1). */