From patchwork Mon Sep 7 02:58:31 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kugan Vivekanandarajah X-Patchwork-Id: 53204 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f197.google.com (mail-wi0-f197.google.com [209.85.212.197]) by patches.linaro.org (Postfix) with ESMTPS id 4D45822B05 for ; Mon, 7 Sep 2015 02:59:05 +0000 (UTC) Received: by wicmn1 with SMTP id mn1sf21751128wic.1 for ; Sun, 06 Sep 2015 19:59:04 -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=5gjFn0bc2OrX3O2Lbd+S+4COdmvsFOMDDA2ZaRC2VKI=; b=MbJT6BLv98Cd6sUk1Oy/kG064Sofz2FEW+J4b1LdBBdmrAlYd/8IBD/X9qACPk00St UJZSeD7ym0RMIaezCSCjKpEqYIhVSt+Mqv8brE/bTxjH2cPzmxPHhx9U7568M+lc/jlo l+a9GqLOhuCWbyjzWhPnEkR5BewSadQ5F9C2vfFNVBO0Ra+RLPEdqoao9y6e5xFYhS6U JcuhuKCmk4l7oc8Q54oxn/5n4TRD9VCaTWAkqZgqOAzmOcRuXORedRM/mRHK2J0OYZXW hAuS2LzrLwYAIT//X7mWORu2x4+u5sQ8bUvoAoxEzoMaw/+yTYnQ0pfaP0LPIBT/+yj/ txWw== X-Gm-Message-State: ALoCoQkwWReGnFd3Nn15FXcM+10BvWYYRZXVhdSshIQuSEsZg4raQXlrLYKwBnoEXIz8eIMEJbU3 X-Received: by 10.112.16.200 with SMTP id i8mr4318526lbd.20.1441594744243; Sun, 06 Sep 2015 19:59:04 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.204.135 with SMTP id ky7ls572815lac.20.gmail; Sun, 06 Sep 2015 19:59:04 -0700 (PDT) X-Received: by 10.112.148.130 with SMTP id ts2mr15058852lbb.17.1441594744095; Sun, 06 Sep 2015 19:59:04 -0700 (PDT) Received: from mail-la0-x231.google.com (mail-la0-x231.google.com. [2a00:1450:4010:c03::231]) by mx.google.com with ESMTPS id tt2si9260888lbb.13.2015.09.06.19.59.04 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 06 Sep 2015 19:59:04 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2a00:1450:4010:c03::231 as permitted sender) client-ip=2a00:1450:4010:c03::231; Received: by laeb10 with SMTP id b10so44225131lae.1 for ; Sun, 06 Sep 2015 19:59:04 -0700 (PDT) X-Received: by 10.112.209.106 with SMTP id ml10mr14951949lbc.112.1441594743965; Sun, 06 Sep 2015 19:59:03 -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 w3csp119449lbq; Sun, 6 Sep 2015 19:59:02 -0700 (PDT) X-Received: by 10.66.62.163 with SMTP id z3mr40073178par.12.1441594742711; Sun, 06 Sep 2015 19:59:02 -0700 (PDT) Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id cr2si17605814pdb.134.2015.09.06.19.59.01 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 06 Sep 2015 19:59:02 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-406778-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Received: (qmail 78608 invoked by alias); 7 Sep 2015 02:58:48 -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 75231 invoked by uid 89); 7 Sep 2015 02:58:41 -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-f53.google.com Received: from mail-pa0-f53.google.com (HELO mail-pa0-f53.google.com) (209.85.220.53) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Mon, 07 Sep 2015 02:58:40 +0000 Received: by padhy16 with SMTP id hy16so79674181pad.1 for ; Sun, 06 Sep 2015 19:58:38 -0700 (PDT) X-Received: by 10.68.138.200 with SMTP id qs8mr40618424pbb.19.1441594718230; Sun, 06 Sep 2015 19:58:38 -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 gx11sm9978632pbd.82.2015.09.06.19.58.36 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 06 Sep 2015 19:58:37 -0700 (PDT) Subject: [3/7] Optimize ZEXT_EXPR with tree-vrp To: "gcc-patches@gcc.gnu.org" References: <55ECFC2A.7050908@linaro.org> Cc: Richard Biener From: Kugan Message-ID: <55ECFD57.5060507@linaro.org> Date: Mon, 7 Sep 2015 12:58:31 +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::231 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 tree-vrp handling and optimization for ZEXT_EXPR. gcc/ChangeLog: 2015-09-07 Kugan Vivekanandarajah * tree-vrp.c (extract_range_from_binary_expr_1): Handle SEXT_EXPR. (simplify_bit_ops_using_ranges): Likewise. (simplify_stmt_using_ranges): Likewise. >From 7143e0575f309f70d838edf436b555fb93a6c4bb Mon Sep 17 00:00:00 2001 From: Kugan Vivekanandarajah Date: Mon, 17 Aug 2015 13:45:52 +1000 Subject: [PATCH 3/8] Optimize ZEXT_EXPR with tree-vrp --- gcc/tree-vrp.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c index 21fbed0..d579b49 100644 --- a/gcc/tree-vrp.c +++ b/gcc/tree-vrp.c @@ -2327,6 +2327,7 @@ extract_range_from_binary_expr_1 (value_range_t *vr, && code != LSHIFT_EXPR && code != MIN_EXPR && code != MAX_EXPR + && code != SEXT_EXPR && code != BIT_AND_EXPR && code != BIT_IOR_EXPR && code != BIT_XOR_EXPR) @@ -2887,6 +2888,55 @@ extract_range_from_binary_expr_1 (value_range_t *vr, extract_range_from_multiplicative_op_1 (vr, code, &vr0, &vr1); return; } + else if (code == SEXT_EXPR) + { + gcc_assert (range_int_cst_p (&vr1)); + unsigned int prec = tree_to_uhwi (vr1.min); + type = vr0.type; + wide_int tmin, tmax; + wide_int type_min, type_max; + wide_int may_be_nonzero, must_be_nonzero; + + gcc_assert (!TYPE_UNSIGNED (expr_type)); + type_min = wi::shwi (1 << (prec - 1), + TYPE_PRECISION (TREE_TYPE (vr0.min))); + type_max = wi::shwi (((1 << (prec - 1)) - 1), + TYPE_PRECISION (TREE_TYPE (vr0.max))); + if (zero_nonzero_bits_from_vr (expr_type, &vr0, + &may_be_nonzero, + &must_be_nonzero)) + { + HOST_WIDE_INT int_may_be_nonzero = may_be_nonzero.to_uhwi (); + HOST_WIDE_INT int_must_be_nonzero = must_be_nonzero.to_uhwi (); + + if (int_must_be_nonzero & (1 << (prec - 1))) + { + /* If to-be-extended sign bit is one. */ + tmin = type_min; + tmax = may_be_nonzero; + } + else if ((int_may_be_nonzero & (1 << (prec - 1))) == 0) + { + /* If to-be-extended sign bit is zero. */ + tmin = must_be_nonzero; + tmax = may_be_nonzero; + } + else + { + tmin = type_min; + tmax = type_max; + } + } + else + { + tmin = type_min; + tmax = type_max; + } + tmin = wi::sext (tmin, prec - 1); + tmax = wi::sext (tmax, prec - 1); + min = wide_int_to_tree (expr_type, tmin); + max = wide_int_to_tree (expr_type, tmax); + } else if (code == RSHIFT_EXPR || code == LSHIFT_EXPR) { @@ -9254,6 +9304,30 @@ simplify_bit_ops_using_ranges (gimple_stmt_iterator *gsi, gimple stmt) break; } break; + case SEXT_EXPR: + { + gcc_assert (is_gimple_min_invariant (op1)); + unsigned int prec = tree_to_uhwi (op1); + wide_int mask; + HOST_WIDE_INT may_be_nonzero = may_be_nonzero0.to_uhwi (); + HOST_WIDE_INT must_be_nonzero = must_be_nonzero0.to_uhwi (); + mask = wi::shwi (((1 << (prec - 1)) - 1), + TYPE_PRECISION (TREE_TYPE (vr0.max))); + mask = wi::bit_not (mask); + if (must_be_nonzero & (1 << (prec - 1))) + { + /* If to-be-extended sign bit is one. */ + if (wi::bit_and (must_be_nonzero0, mask) == mask) + op = op0; + } + else if ((may_be_nonzero & (1 << (prec - 1))) == 0) + { + /* If to-be-extended sign bit is zero. */ + if (wi::bit_and (may_be_nonzero0, mask) == 0) + op = op0; + } + } + break; default: gcc_unreachable (); } @@ -9955,6 +10029,7 @@ simplify_stmt_using_ranges (gimple_stmt_iterator *gsi) case BIT_AND_EXPR: case BIT_IOR_EXPR: + case SEXT_EXPR: /* Optimize away BIT_AND_EXPR and BIT_IOR_EXPR if all the bits being cleared are already cleared or all the bits being set are already set. */ -- 1.9.1