From patchwork Mon Sep 7 02:55:24 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kugan Vivekanandarajah X-Patchwork-Id: 53202 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f197.google.com (mail-lb0-f197.google.com [209.85.217.197]) by patches.linaro.org (Postfix) with ESMTPS id 93A5F22B05 for ; Mon, 7 Sep 2015 02:55:56 +0000 (UTC) Received: by lbcao8 with SMTP id ao8sf21295928lbc.1 for ; Sun, 06 Sep 2015 19:55:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:mailing-list:precedence:list-id :list-unsubscribe:list-archive:list-post:list-help:sender :delivered-to:subject:to:references:cc:from:message-id:date :user-agent:mime-version:in-reply-to:content-type:x-original-sender :x-original-authentication-results; bh=C26MZt5VQ5cS/m3a7kIHH9ebE39B8sLPi1jYS++QKbo=; b=R1q8XK4J0zMULwbDktpzbKe4qwYtzbHMadbhUVijHeNVOx6PdKlV/Rl5CO/HHuccXA 4SxSUlao0d1Xfhhd+mxQoHEVH20Jv+oV82k0ruIA1vLPdflF4vBe0aFE2Md4WBKU7hzN r4IbK3xRBoOuCrTbEtQm+50w9r7yUlz74iz+Ka/NPwzfqgcYHKs6u/brZu6oY2TkKz9+ Tyr10cBUTFV9zEiD9kqYAjK1CZIhKxn6sXpPorsosvpZlCtUR/wjKo81YoQIGGmD3nIG IEaVx8t1HRtMRk21fBGVNcKNU+bB9sn8MhYSiHWvm1ghR/WeEFVBtfv2NwFOJTqIfKwJ 9e5g== X-Gm-Message-State: ALoCoQnvOWhxH5X0+gZ95W84Mcbvx7k8GStLcPu1V8OuTJYZAA/9GYNu9tnBMjI2oVHrlC9ZALxo X-Received: by 10.152.5.164 with SMTP id t4mr4320491lat.0.1441594555551; Sun, 06 Sep 2015 19:55:55 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.239.161 with SMTP id vt1ls462636lac.41.gmail; Sun, 06 Sep 2015 19:55:55 -0700 (PDT) X-Received: by 10.112.64.228 with SMTP id r4mr13639928lbs.80.1441594555403; Sun, 06 Sep 2015 19:55:55 -0700 (PDT) Received: from mail-la0-x22e.google.com (mail-la0-x22e.google.com. [2a00:1450:4010:c03::22e]) by mx.google.com with ESMTPS id h11si202317lbo.151.2015.09.06.19.55.55 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 06 Sep 2015 19:55:55 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2a00:1450:4010:c03::22e as permitted sender) client-ip=2a00:1450:4010:c03::22e; Received: by lamp12 with SMTP id p12so42910582lam.0 for ; Sun, 06 Sep 2015 19:55:55 -0700 (PDT) X-Received: by 10.112.51.142 with SMTP id k14mr4819441lbo.76.1441594555321; Sun, 06 Sep 2015 19:55:55 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.59.35 with SMTP id w3csp118585lbq; Sun, 6 Sep 2015 19:55:53 -0700 (PDT) X-Received: by 10.68.98.5 with SMTP id ee5mr40160539pbb.95.1441594553854; Sun, 06 Sep 2015 19:55:53 -0700 (PDT) Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id a10si17632010pat.46.2015.09.06.19.55.52 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 06 Sep 2015 19:55:53 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-406776-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Received: (qmail 63550 invoked by alias); 7 Sep 2015 02:55:35 -0000 Mailing-List: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org Precedence: list 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 63539 invoked by uid 89); 7 Sep 2015 02:55:35 -0000 X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.4 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-pa0-f44.google.com Received: from mail-pa0-f44.google.com (HELO mail-pa0-f44.google.com) (209.85.220.44) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Mon, 07 Sep 2015 02:55:33 +0000 Received: by pacex6 with SMTP id ex6so81870423pac.0 for ; Sun, 06 Sep 2015 19:55:32 -0700 (PDT) X-Received: by 10.66.246.228 with SMTP id xz4mr41094059pac.46.1441594531945; Sun, 06 Sep 2015 19:55:31 -0700 (PDT) Received: from [10.1.1.7] (58-6-183-210.dyn.iinet.net.au. [58.6.183.210]) by smtp.googlemail.com with ESMTPSA id qh5sm9978261pbb.71.2015.09.06.19.55.29 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 06 Sep 2015 19:55:30 -0700 (PDT) Subject: [1/7] Add new tree code SEXT_EXPR To: "gcc-patches@gcc.gnu.org" References: <55ECFC2A.7050908@linaro.org> Cc: Richard Biener From: Kugan Message-ID: <55ECFC9C.8050204@linaro.org> Date: Mon, 7 Sep 2015 12:55:24 +1000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.2.0 MIME-Version: 1.0 In-Reply-To: <55ECFC2A.7050908@linaro.org> X-IsSubscribed: yes X-Original-Sender: kugan.vivekanandarajah@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2a00:1450:4010:c03::22e as permitted sender) smtp.mailfrom=patch+caf_=patchwork-forward=linaro.org@linaro.org; dkim=pass header.i=@gcc.gnu.org X-Google-Group-Id: 836684582541 This patch adds support for new tree code SEXT_EXPR. gcc/ChangeLog: 2015-09-07 Kugan Vivekanandarajah * cfgexpand.c (expand_debug_expr): Handle SEXT_EXPR. * expr.c (expand_expr_real_2): Likewise. * fold-const.c (int_const_binop_1): Likewise. * tree-cfg.c (verify_gimple_assign_binary): Likewise. * tree-inline.c (estimate_operator_cost): Likewise. * tree-pretty-print.c (dump_generic_node): Likewise. (op_symbol_code): Likewise. * tree.def: Define new tree code SEXT_EXPR. >From 9e9fd271b84580ae40ce21eb39f9be8072e6dd12 Mon Sep 17 00:00:00 2001 From: Kugan Vivekanandarajah Date: Mon, 17 Aug 2015 13:37:15 +1000 Subject: [PATCH 1/8] Add new SEXT_EXPR tree code --- gcc/cfgexpand.c | 4 ++++ gcc/expr.c | 16 ++++++++++++++++ gcc/fold-const.c | 4 ++++ gcc/tree-cfg.c | 12 ++++++++++++ gcc/tree-inline.c | 1 + gcc/tree-pretty-print.c | 11 +++++++++++ gcc/tree.def | 4 ++++ 7 files changed, 52 insertions(+) diff --git a/gcc/cfgexpand.c b/gcc/cfgexpand.c index d567a87..bbc3c10 100644 --- a/gcc/cfgexpand.c +++ b/gcc/cfgexpand.c @@ -5071,6 +5071,10 @@ expand_debug_expr (tree exp) case FMA_EXPR: return simplify_gen_ternary (FMA, mode, inner_mode, op0, op1, op2); + case SEXT_EXPR: + return op0; + + default: flag_unsupported: #ifdef ENABLE_CHECKING diff --git a/gcc/expr.c b/gcc/expr.c index 1e820b4..bcd87c0 100644 --- a/gcc/expr.c +++ b/gcc/expr.c @@ -9273,6 +9273,22 @@ expand_expr_real_2 (sepops ops, rtx target, machine_mode tmode, target = expand_vec_cond_expr (type, treeop0, treeop1, treeop2, target); return target; + case SEXT_EXPR: + { + rtx op0 = expand_normal (treeop0); + rtx temp; + if (!target) + target = gen_reg_rtx (TYPE_MODE (TREE_TYPE (treeop0))); + + machine_mode inner_mode + = smallest_mode_for_size (tree_to_shwi (treeop1), + MODE_INT); + temp = convert_modes (inner_mode, + TYPE_MODE (TREE_TYPE (treeop0)), op0, 0); + convert_move (target, temp, 0); + return target; + } + default: gcc_unreachable (); } diff --git a/gcc/fold-const.c b/gcc/fold-const.c index c826e67..473f930 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -984,6 +984,10 @@ int_const_binop_1 (enum tree_code code, const_tree arg1, const_tree parg2, res = wi::bit_and (arg1, arg2); break; + case SEXT_EXPR: + res = wi::sext (arg1, arg2.to_uhwi ()); + break; + case RSHIFT_EXPR: case LSHIFT_EXPR: if (wi::neg_p (arg2)) diff --git a/gcc/tree-cfg.c b/gcc/tree-cfg.c index 5ac73b3..c9ad28d 100644 --- a/gcc/tree-cfg.c +++ b/gcc/tree-cfg.c @@ -3756,6 +3756,18 @@ verify_gimple_assign_binary (gassign *stmt) return false; } + case SEXT_EXPR: + { + if (!INTEGRAL_TYPE_P (lhs_type) + || !INTEGRAL_TYPE_P (rhs1_type) + || TREE_CODE (rhs2) != INTEGER_CST) + { + error ("invalid operands in sext expr"); + return true; + } + return false; + } + case VEC_WIDEN_LSHIFT_HI_EXPR: case VEC_WIDEN_LSHIFT_LO_EXPR: { diff --git a/gcc/tree-inline.c b/gcc/tree-inline.c index e1ceea4..272c409 100644 --- a/gcc/tree-inline.c +++ b/gcc/tree-inline.c @@ -3884,6 +3884,7 @@ estimate_operator_cost (enum tree_code code, eni_weights *weights, case BIT_XOR_EXPR: case BIT_AND_EXPR: case BIT_NOT_EXPR: + case SEXT_EXPR: case TRUTH_ANDIF_EXPR: case TRUTH_ORIF_EXPR: diff --git a/gcc/tree-pretty-print.c b/gcc/tree-pretty-print.c index 7cd1fe7..04f6777 100644 --- a/gcc/tree-pretty-print.c +++ b/gcc/tree-pretty-print.c @@ -1794,6 +1794,14 @@ dump_generic_node (pretty_printer *pp, tree node, int spc, int flags, } break; + case SEXT_EXPR: + pp_string (pp, "SEXT_EXPR <"); + dump_generic_node (pp, TREE_OPERAND (node, 0), spc, flags, false); + pp_string (pp, ", "); + dump_generic_node (pp, TREE_OPERAND (node, 1), spc, flags, false); + pp_greater (pp); + break; + case MODIFY_EXPR: case INIT_EXPR: dump_generic_node (pp, TREE_OPERAND (node, 0), spc, flags, @@ -3414,6 +3422,9 @@ op_symbol_code (enum tree_code code) case MIN_EXPR: return "min"; + case SEXT_EXPR: + return "sext from bit"; + default: return "<<< ??? >>>"; } diff --git a/gcc/tree.def b/gcc/tree.def index 56580af..d614544 100644 --- a/gcc/tree.def +++ b/gcc/tree.def @@ -752,6 +752,10 @@ DEFTREECODE (BIT_XOR_EXPR, "bit_xor_expr", tcc_binary, 2) DEFTREECODE (BIT_AND_EXPR, "bit_and_expr", tcc_binary, 2) DEFTREECODE (BIT_NOT_EXPR, "bit_not_expr", tcc_unary, 1) +/* Sign-extend operation. It will sign extend first operand from + the sign bit specified by the second operand. */ +DEFTREECODE (SEXT_EXPR, "sext_expr", tcc_binary, 2) + /* ANDIF and ORIF allow the second operand not to be computed if the value of the expression is determined from the first operand. AND, OR, and XOR always compute the second operand whether its value is -- 1.9.1