From patchwork Wed Aug 27 12:04:47 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 383436 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 3CA04140085 for ; Wed, 27 Aug 2014 22:08:33 +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:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=I79l6FT9x3uoNJFpOeAXRQFR+5MZNYI5203tLi1hCG9X+wfNYeJ4m TiY+TPXcqG6pgB16PV7mZSZW7nckVVPK9Yn4gZmSfkFKWTo2nHt+mFm1jOqjY/TB Fqw7fcdvr7ZEB/QFg7k0fdBL+SHNl8NICovcjXDJ6Qrw99Hv5Ns5eo= 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=lMqTAi3titkoloVQ0/KF6NZieJM=; b=qYq+XPR32zPbbC039tyD a05NfFpwYHLmMhSKyb+uHM2YqVhz8ATVUOQC4WtPddvCvqbZ4C754THjpVfjBUjL PPfC11taNmjSuNYCx80O7mO7XLfk7JUtz8yMttHykA6qXHLHlpq5Bu02njWu3Zhg B1lCCUHaFtmePcGmWiO8x6U= Received: (qmail 20449 invoked by alias); 27 Aug 2014 12:08: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 20435 invoked by uid 89); 27 Aug 2014 12:08:12 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.3 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mx2.suse.de Received: from cantor2.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; Wed, 27 Aug 2014 12:08:11 +0000 Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 55A17AC15 for ; Wed, 27 Aug 2014 12:08:08 +0000 (UTC) Date: Wed, 27 Aug 2014 14:04:47 +0200 (CEST) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH][match-and-simplify] Fix type guessing for conversions Message-ID: User-Agent: Alpine 2.11 (LSU 23 2013-08-11) MIME-Version: 1.0 The following fixes type guessing by handling VIEW_CONVERT_EXPR and by properly passing down "unknown" for outermost conversions. Btw, a case where we need some explicit type specification support is Convert (T1)(X * Y) into (T1)X * (T1)Y which needs to eventually use an unsigned type for the multiplication. Suggested syntax could be /* Convert (T1)(X * Y) into (T1)X * (T1)Y if T1 is narrower than the type of X and Y (integer types only). */ (simplify (convert (mult @0 @1)) (if (INTEGRAL_TYPE_P (type) && INTEGRAL_TYPE_P (TREE_TYPE (@0)) && TYPE_PRECISION (type) < TYPE_PRECISION (TREE_TYPE (@0))) (if (TYPE_OVERFLOW_WRAPS (type)) (mult (convert @0) (convert @1))) /* 1) We can't handle the two-conversions-in-a-row below. 2) We can't properly specify the type for the inner conversion (unsigned_type_for). Suggested syntax below. */ (with { tree utype = unsigned_type_for (TREE_TYPE (@0)); } (convert (mult (convert:utype @0) (convert:utype @1)))))) Committed. Richard. 2014-08-27 Richard Biener * genmatch.c (is_conversion): New helper, add VIEW_CONVERT_EXPR to the list of conversions. (expr::gen_transform): Use it. (dt_simplify::gen): Properly pass down NULL as the operand type for outermost conversions. Index: gcc/genmatch.c =================================================================== --- gcc/genmatch.c (revision 214568) +++ gcc/genmatch.c (working copy) @@ -866,22 +866,27 @@ check_no_user_id (simplify *s) check_no_user_id (s->result); } +bool +is_conversion (id_base *op) +{ + return (*op == CONVERT_EXPR + || *op == NOP_EXPR + || *op == FLOAT_EXPR + || *op == FIX_TRUNC_EXPR + || *op == VIEW_CONVERT_EXPR); +} + /* Code gen off the AST. */ void expr::gen_transform (FILE *f, const char *dest, bool gimple, int depth, const char *in_type) { - bool is_conversion = false; - if (*operation->op == CONVERT_EXPR - || *operation->op == NOP_EXPR - || *operation->op == FLOAT_EXPR - || *operation->op == FIX_TRUNC_EXPR) - is_conversion = true; + bool conversion_p = is_conversion (operation->op); const char *type; char optype[20]; - if (is_conversion) + if (conversion_p) /* For conversions we need to build the expression using the outer type passed in. */ type = in_type; @@ -901,7 +906,7 @@ expr::gen_transform (FILE *f, const char char dest[32]; snprintf (dest, 32, " ops%d[%u]", depth, i); ops[i]->gen_transform (f, dest, gimple, depth + 1, - is_conversion + conversion_p /* If this op is a conversion its single operand has to know its type itself. */ ? NULL @@ -1769,7 +1774,9 @@ dt_simplify::gen (FILE *f, bool gimple) { char dest[32]; snprintf (dest, 32, " res_ops[%d]", j); - e->ops[j]->gen_transform (f, dest, true, 1, "type"); + e->ops[j]->gen_transform (f, dest, true, 1, + is_conversion (e->operation->op) + ? NULL : "type"); } /* Re-fold the toplevel result. It's basically an embedded gimple_build w/o actually building the stmt. */ @@ -1796,7 +1803,9 @@ dt_simplify::gen (FILE *f, bool gimple) fprintf (f, " tree res_op%d;\n", j); char dest[32]; snprintf (dest, 32, " res_op%d", j); - e->ops[j]->gen_transform (f, dest, false, 1, "type"); + e->ops[j]->gen_transform (f, dest, false, 1, + is_conversion (e->operation->op) + ? NULL : "type"); } /* Re-fold the toplevel result. */ if (e->operation->op->kind == id_base::CODE)