From patchwork Thu Oct 6 20:55:52 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kugan Vivekanandarajah X-Patchwork-Id: 77315 Delivered-To: patch@linaro.org Received: by 10.140.97.247 with SMTP id m110csp115394qge; Thu, 6 Oct 2016 13:56:22 -0700 (PDT) X-Received: by 10.66.142.9 with SMTP id rs9mr24405552pab.87.1475787381967; Thu, 06 Oct 2016 13:56:21 -0700 (PDT) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id cm7si13849467pad.48.2016.10.06.13.56.21 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 06 Oct 2016 13:56:21 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-437894-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-437894-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-437894-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=DpSxIEQxsesSH8PXLYwfht4W7LoZih4HXLLVGun0iA58ZbD8WS BjH5sRdzj3rf5XP5FqskzxCsJGACiIRkRP8wT8Srw3hJXzoxuvutcBc19/0ScxZY mzB1L6bm8Jaip+y3UriaP0gCNNGlZDFrlF24rR61p3dNo8R+6bO30HEJc= 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=M5Rrr4pk2ORKEjOA1To6VbFSuME=; b=WIXKMqCon8cg7zhCC1J3 vBH7UG18ghUBjmLNyGVFJxjSu8apwJmqhF3i9cOYjAwJqYjYEqLcO8Cm+9a9Fsm8 Aglq06yNNxpQ09Y45BGYJYIBZezTUJs5evXvpuzrvLNU4ENQzV7x5Y6yWcLWzbAO HeV4jddSGM1JD4QOEkK1d1s= Received: (qmail 59815 invoked by alias); 6 Oct 2016 20:56:09 -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 59798 invoked by uid 89); 6 Oct 2016 20:56:08 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.5 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=no version=3.3.2 spammy=Discover, kugan.vivekanandarajah@linaro.org, sk:kugan.v, U*kugan.vivekanandarajah X-HELO: mail-pa0-f43.google.com Received: from mail-pa0-f43.google.com (HELO mail-pa0-f43.google.com) (209.85.220.43) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 06 Oct 2016 20:55:58 +0000 Received: by mail-pa0-f43.google.com with SMTP id ry6so13695213pac.3 for ; Thu, 06 Oct 2016 13:55:58 -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=sBMFHOhprNlFB4Hi1lx7/6Vo5lpPUR3SsLsMB9l5Zys=; b=Uap3Zn+/u0t2v8qfk7+I7XzbL7PZU9pA3P5L3ltlvAfzTVL7DbKETVm+vYKH0UCPq6 iahhn1C83VVJ0vhc36bXv0/I7+qj3DJcw+g6K0QD1yKoI43v8zSvvVnqGEgvJ/kxxYNl r+4r9Z+wwNHAV6aqYJiUHXYgkmxZLW38zZkBIIAIzWnDeR6HFI8T2Ap4fbQKfuqK90Da wWgmcLwHL90GtUVA7L/uDMtco2XddHyYZd1jX0iTvgo2x+xP1CnkflLmDFQl1vogA5Ck z4bbL6oukmMJ+zL28jz1CvYk/oPy8DrH0pDsrVNCOHJ7Pw9PuGD8Kg4iZOKD3mVaDuJD VjqA== X-Gm-Message-State: AA6/9RkVwSTOFWP92hry4rrgxyIpVSJ3D6dCD3Y1aZc/x7PqW5Zwm/BcJGvgCDbtSfYCSpSO X-Received: by 10.66.248.69 with SMTP id yk5mr25376344pac.9.1475787356717; Thu, 06 Oct 2016 13:55:56 -0700 (PDT) Received: from [10.1.1.7] (58-6-183-210.dyn.iinet.net.au. [58.6.183.210]) by smtp.gmail.com with ESMTPSA id s74sm8010548pfk.61.2016.10.06.13.55.55 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 06 Oct 2016 13:55:56 -0700 (PDT) To: "gcc-patches@gcc.gnu.org" From: kugan Subject: [EVRP] Register ranges for y in (x COND y) for Early VRP. Message-ID: <60bc27ef-2a36-3b50-1acf-71c5e12d839a@linaro.org> Date: Fri, 7 Oct 2016 07:55:52 +1100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.3.0 MIME-Version: 1.0 X-IsSubscribed: yes Hi, Attached patch Register ranges for y in (x COND y) for Early VRP. Bootstrapped and regression tested on x86_64-linux-gnu with no new regressions. Is this OK for trunk? Thanks, Kugan gcc/ChangeLog: 2016-10-06 Kugan Vivekanandarajah * tree-vrp.c (evrp_dom_walker::try_add_new_range): New. (evrp_dom_walker::before_dom_children): Infer and push new value ranges for x in y COND x. >From a90aac71afe66d47268dfb3d0cb7657c96e96b15 Mon Sep 17 00:00:00 2001 From: Kugan Vivekanandarajah Date: Mon, 3 Oct 2016 10:12:27 +1100 Subject: [PATCH 2/5] Register ranges for y in x < y 1 --- gcc/tree-vrp.c | 54 ++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 40 insertions(+), 14 deletions(-) diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c index 46bbd82..0892709 100644 --- a/gcc/tree-vrp.c +++ b/gcc/tree-vrp.c @@ -10640,6 +10640,7 @@ public: virtual void after_dom_children (basic_block); void push_value_range (const_tree var, value_range *vr); value_range *pop_value_range (const_tree var); + void try_add_new_range (tree op, tree_code code, tree limit); /* Cond_stack holds the old VR. */ auto_vec > stack; @@ -10647,20 +10648,42 @@ public: vec stmts_to_fixup; }; + +/* Add new range to OP such that (OP CODE LIMIT) is true. */ + +void +evrp_dom_walker::try_add_new_range (tree op, tree_code code, tree limit) +{ + value_range vr = VR_INITIALIZER; + value_range *old_vr = get_value_range (op); + + /* Discover VR when condition is true. */ + extract_range_for_var_from_comparison_expr (op, code, op, + limit, &vr); + if (old_vr->type == VR_RANGE || old_vr->type == VR_ANTI_RANGE) + vrp_intersect_ranges (&vr, old_vr); + /* If we found any usable VR, set the VR to ssa_name and create a + PUSH old value in the stack with the old VR. */ + if (vr.type == VR_RANGE || vr.type == VR_ANTI_RANGE) + { + value_range *new_vr = vrp_value_range_pool.allocate (); + *new_vr = vr; + push_value_range (op, new_vr); + } +} + /* See if there is any new scope is entered with new VR and set that VR to ssa_name before visiting the statements in the scope. */ edge evrp_dom_walker::before_dom_children (basic_block bb) { - value_range *new_vr = NULL; tree op0 = NULL_TREE; push_value_range (NULL_TREE, NULL); if (single_pred_p (bb)) { edge e = single_pred_edge (bb); - value_range vr = VR_INITIALIZER; gimple *stmt = last_stmt (e->src); if (stmt && gimple_code (stmt) == GIMPLE_COND @@ -10673,7 +10696,6 @@ evrp_dom_walker::before_dom_children (basic_block bb) here. */ tree op1 = gimple_cond_rhs (stmt); tree_code code = gimple_cond_code (stmt); - value_range *old_vr = get_value_range (op0); if (TREE_OVERFLOW_P (op1)) op1 = drop_tree_overflow (op1); @@ -10682,18 +10704,22 @@ evrp_dom_walker::before_dom_children (basic_block bb) if (e->flags & EDGE_FALSE_VALUE) code = invert_tree_comparison (gimple_cond_code (stmt), HONOR_NANS (op0)); - /* Discover VR when condition is true. */ - extract_range_for_var_from_comparison_expr (op0, code, op0, op1, &vr); - if (old_vr->type == VR_RANGE || old_vr->type == VR_ANTI_RANGE) - vrp_intersect_ranges (&vr, old_vr); - - /* If we found any usable VR, set the VR to ssa_name and create a - PUSH old value in the stack with the old VR. */ - if (vr.type == VR_RANGE || vr.type == VR_ANTI_RANGE) + /* Add VR when (OP0 CODE OP1) condition is true. */ + try_add_new_range (op0, code, op1); + + + /* Register ranges for y in x < y where + y might have ranges that are useful. */ + tree limit; + tree_code new_code; + if (TREE_CODE (op1) == SSA_NAME + && extract_code_and_val_from_cond_with_ops (op1, code, + op0, op1, + false, + &new_code, &limit)) { - new_vr = vrp_value_range_pool.allocate (); - *new_vr = vr; - push_value_range (op0, new_vr); + /* Add VR when (OP1 NEW_CODE LIMIT) condition is true. */ + try_add_new_range (op1, new_code, limit); } } } -- 2.7.4