From patchwork Sat Apr 16 23:14:01 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kugan Vivekanandarajah X-Patchwork-Id: 65987 Delivered-To: patch@linaro.org Received: by 10.140.93.198 with SMTP id d64csp608485qge; Sat, 16 Apr 2016 16:14:52 -0700 (PDT) X-Received: by 10.66.122.67 with SMTP id lq3mr39034533pab.54.1460848492394; Sat, 16 Apr 2016 16:14:52 -0700 (PDT) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id y65si6029321pfa.146.2016.04.16.16.14.52 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 16 Apr 2016 16:14:52 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-424940-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org; spf=pass (google.com: domain of gcc-patches-return-424940-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-424940-patch=linaro.org@gcc.gnu.org; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=ia1LfQrU6xVkC6Y+HxixECyGPr85m9UeafBr5LZRy09UCdtX5D WG/+o1pxFZyJBQDucDHsJkaKnSSRYmpI53s0Kc7QGOEexdT3jNQKBTi+kMq8nxmF 0JfXSgSL3MG05kd+ZIPoWepBQVqTfmYIQS3J+XyoVjE9SoO4L9AXP6rzQ= 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:to :from:subject:message-id:date:mime-version:content-type; s= default; bh=0uqT6uQsjrDPGGnYwA0KWbUd1v8=; b=O0zX95z1TPQET0MosLqw hTa+VrGI0Ov8UlRQL+pklrzH1KPaOOaVRGjAzjh1O4BlzTj9ARJ/KL4jQkxVMnl/ 9aoUC7NWmk8CiDvSu2gDC0WW/nqX4DMrWWW1XjeFkwkaT/QEQi6iL2rUCQs0/adu 1dtQXFvG40/kjthc1Ryu1bs= Received: (qmail 45900 invoked by alias); 16 Apr 2016 23:14:38 -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 45884 invoked by uid 89); 16 Apr 2016 23:14:37 -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, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 spammy=2016-04-17, 20160417, gsi X-HELO: mail-pa0-f42.google.com Received: from mail-pa0-f42.google.com (HELO mail-pa0-f42.google.com) (209.85.220.42) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Sat, 16 Apr 2016 23:14:27 +0000 Received: by mail-pa0-f42.google.com with SMTP id r5so11713635pag.1 for ; Sat, 16 Apr 2016 16:14:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:to:from:subject:message-id:date:user-agent :mime-version; bh=CS/RuQm3gxB1AIH3ImMXqr5bp0Tc6FCUH87ERDQOKlw=; b=GgwSQ08qaDThIMItgBKa+18JssPQeo8AcNAGGxZsxsZ/mBD4+dmaADlhoHvHcHPRNH sGUPBvvs+wjOrkX3gVQW2yy4JPzQxiR5VyECftCN+AYCadiPHlPNtG5iqV+o0s3aRgbD /mHi3XX4MDmmamoiC3PM3P0RYRGQT6j4qMsjF67KkVTsbCmHaZnd2Ro7h1cASnnDYhyt Fseq8vaUvCglkp/mudCVooYjN8oDA9U6vYfeu80yKkwVh11XiPtz1PS1+FQXyb5/zFyT /VH3L5L3vInHCO1VaduqLxlZupugvnVhWdq8SuOpDk+WcgoFwwLfLI+aWJcZeiKvSS5Z U3ug== X-Gm-Message-State: AOPr4FX9C0xPNHgv+0QAf8DNric3i5HtH7iZesaJIxbw+8I0z8i0xgpFuUEFmm+udsvecTVF X-Received: by 10.67.3.129 with SMTP id bw1mr2924279pad.16.1460848465685; Sat, 16 Apr 2016 16:14:25 -0700 (PDT) Received: from [10.1.1.9] (58-6-183-210.dyn.iinet.net.au. [58.6.183.210]) by smtp.googlemail.com with ESMTPSA id yj1sm73888752pac.16.2016.04.16.16.14.23 (version=TLSv1/SSLv3 cipher=OTHER); Sat, 16 Apr 2016 16:14:25 -0700 (PDT) To: "gcc-patches@gcc.gnu.org" , Richard Biener From: kugan Subject: [RFC][PR61839]Convert CST BINOP COND_EXPR to COND_EXPR ? (CST BINOP 1) : (CST BINOP 0) Message-ID: <5712C739.4080101@linaro.org> Date: Sun, 17 Apr 2016 09:14:01 +1000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.5.1 MIME-Version: 1.0 X-IsSubscribed: yes As explained in PR61839, Following difference results in extra instructions: - c = b != 0 ? 486097858 : 972195717; + c = a + 972195718 >> (b != 0); As suggested in PR, attached patch converts CST BINOP COND_EXPR to COND_EXPR ? (CST BINOP 1) : (CST BINOP 0). Bootstrapped and regression tested for x86-64-linux-gnu with no new regression. Is this OK for statege-1. Thanks, Kugan gcc/ChangeLog: 2016-04-17 Kugan Vivekanandarajah * tree-vrp.c (simplify_stmt_using_ranges): Convert CST BINOP COND_EXPR to COND_EXPR ? (CST BINOP 1) : (CST BINOP 0) when possible. diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c index bbdf9ce..caf7a2a 100644 --- a/gcc/tree-vrp.c +++ b/gcc/tree-vrp.c @@ -9902,6 +9902,49 @@ simplify_stmt_using_ranges (gimple_stmt_iterator *gsi) { enum tree_code rhs_code = gimple_assign_rhs_code (stmt); tree rhs1 = gimple_assign_rhs1 (stmt); + tree rhs2 = gimple_assign_rhs2 (stmt); + tree var; + + /* Convert: + COND_RES = X COMPARE Y + TMP = (CAST) COND_RES + LHS = CST BINOP TMP + + To: + LHS = COND_RES ? (CST BINOP 1) : (CST BINOP 0) */ + + if (TREE_CODE_CLASS (rhs_code) == tcc_binary + && TREE_CODE (rhs1) == INTEGER_CST + && TREE_CODE (rhs2) == SSA_NAME + && is_gimple_assign (SSA_NAME_DEF_STMT (rhs2)) + && gimple_assign_rhs_code (SSA_NAME_DEF_STMT (rhs2)) == NOP_EXPR + && (var = gimple_assign_rhs1 (SSA_NAME_DEF_STMT (rhs2))) + && TREE_CODE (var) == SSA_NAME + && is_gimple_assign (SSA_NAME_DEF_STMT (var)) + && TREE_CODE_CLASS (gimple_assign_rhs_code (SSA_NAME_DEF_STMT (var))) + == tcc_comparison) + + { + value_range *vr = get_value_range (var); + if (range_int_cst_p (vr) + && integer_zerop (vr->min) + && integer_onep (vr->max)) + { + + tree new_rhs1 = int_const_binop (rhs_code, rhs1, vr->max); + tree new_rhs2 = int_const_binop (rhs_code, rhs1, vr->min); + + if (new_rhs1 && new_rhs2) + { + gimple_assign_set_rhs_with_ops (gsi, + COND_EXPR, var, + new_rhs1, + new_rhs2); + update_stmt (gsi_stmt (*gsi)); + return true; + } + } + } switch (rhs_code) {