From patchwork Thu Oct 6 22:00:39 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kugan Vivekanandarajah X-Patchwork-Id: 77317 Delivered-To: patch@linaro.org Received: by 10.140.97.247 with SMTP id m110csp127307qge; Thu, 6 Oct 2016 15:01:14 -0700 (PDT) X-Received: by 10.98.200.153 with SMTP id i25mr12314209pfk.156.1475791274291; Thu, 06 Oct 2016 15:01:14 -0700 (PDT) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id f7si14087543pas.141.2016.10.06.15.01.14 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 06 Oct 2016 15:01:14 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-437910-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-437910-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-437910-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:from :subject:to:message-id:date:mime-version:content-type; q=dns; s= default; b=skbKu4r51Q1cnVKqX4e19vUoQaxoTcaIL5jiCW5mI+JDOs7NQ5l5i QctTxS7AZtxmCDlZRZgisbL+S0oufrR2EWcEJ47HbGpj2054wRHj2d2KEBHelUfd /4pZT9LdhkyuuIBlkN+u8xX7DCMPFjZdNrCntuIWhkoq90VOWqGWDg= 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:from :subject:to:message-id:date:mime-version:content-type; s= default; bh=+i9zdSuv1EETrS5IW6k3YCmgLkc=; b=oGFbXrgRAnh+RMkVbEP0 X7QtR/TkrGfT9PEp08o7b7lKGIhpKUkxINPEBccLZWz8Q5IekhmvUWqzmL027B9O wDaWlPCOSsxgs2RXwpBbL7R7Mfv0lKIax4CWKkiGLxWOG7MjtATQC7BK09H+0VcR zctytIYadFPJ9Kc8d572mRY= Received: (qmail 84889 invoked by alias); 6 Oct 2016 22:01:01 -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 84800 invoked by uid 89); 6 Oct 2016 22:00:55 -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=2016-10-07, 20161007, Early, sk:value_r X-HELO: mail-pa0-f51.google.com Received: from mail-pa0-f51.google.com (HELO mail-pa0-f51.google.com) (209.85.220.51) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 06 Oct 2016 22:00:45 +0000 Received: by mail-pa0-f51.google.com with SMTP id rz1so14286850pab.1 for ; Thu, 06 Oct 2016 15:00:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:subject:to:message-id:date:user-agent :mime-version; bh=t1g0dGcWHIMY0VU2LzYybi8pgE5IG1+N5KNl5EZhGG4=; b=XNP4qwAgWIrPKjxaehzrEqizWWtLlMa5jTgGx6QVxKq3xbXnPQmqz0jbp114dxqfXd iScd3xLkBsDdzSozSNNupr7gQkXrgmjBzYUq/YY4VF59nNRPTGz/aeHfgDk1I/ei2TgJ Y7JIDMISZG/FCJr32vJfoPojrFFNcJB15mpckUV5a3IlrKnQrmvr96Sgi1cKHS1vhqTK /9xtPUpHE1nXqa/1ma3b1XDMOF8mkiPbsa1MnBWISXufp/amwq5kDm3qEYdtDlUcsHCU LqP7Z5CMpWohg4H9YlLKgcb1ndl0bJ2iwQWbe0jl7sYaDg8qTTvzZ57ucaQcY4KbyzW/ wkHA== X-Gm-Message-State: AA6/9Rnm0apsPAzMj0gY917zEbCN+4BYbYGEtB+ypVKF6XbuC/PBTK3uHZpqa8f+n141obN0 X-Received: by 10.66.13.34 with SMTP id e2mr25610298pac.103.1475791243560; Thu, 06 Oct 2016 15:00:43 -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 t5sm8180469pfi.78.2016.10.06.15.00.41 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 06 Oct 2016 15:00:42 -0700 (PDT) From: kugan Subject: [RFC][VRP] Improve intersect_ranges To: "gcc-patches@gcc.gnu.org" Message-ID: <76edd771-749d-f85f-2d0e-84e714abb78e@linaro.org> Date: Fri, 7 Oct 2016 09:00:39 +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, In vrp intersect_ranges, Richard recently changed it to create integer value ranges when it is integer singleton. Maybe we should do the same when the other range is a complex ranges with SSA_NAME (like [x+2, +INF])? Attached patch tries to do this. There are cases where it will be beneficial as the testcase in the patch. (For this testcase to work with Early VRP, we need the patch posted at https://gcc.gnu.org/ml/gcc-patches/2016-10/msg00413.html) Bootstrapped and regression tested on x86_64-linux-gnu with no new regressions. Thanks, Kugan gcc/testsuite/ChangeLog: 2016-10-07 Kugan Vivekanandarajah * gcc.dg/tree-ssa/evrp6.c: New test. gcc/ChangeLog: 2016-10-07 Kugan Vivekanandarajah * tree-vrp.c (intersect_ranges): If we failed to handle the intersection and the other range involves computation with symbolic values, choose integer range if available. diff --git a/gcc/testsuite/gcc.dg/tree-ssa/evrp6.c b/gcc/testsuite/gcc.dg/tree-ssa/evrp6.c index e69de29..3740da0 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/evrp6.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/evrp6.c @@ -0,0 +1,21 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-evrp" } */ + +extern void abort (void); + +int +foo (int k, int j) +{ + if (j >= 10) + { + if (j < k) + { + k++; + if (k < 10) + abort (); + } + } + + return j; +} +/* { dg-final { scan-tree-dump "\\\[12, \\+INF" "evrp" } } */ diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c index 7a08be7..2706854 100644 --- a/gcc/tree-vrp.c +++ b/gcc/tree-vrp.c @@ -8553,11 +8553,26 @@ intersect_ranges (enum value_range_type *vr0type, gcc_unreachable (); } + /* If one is a complex value range involving SSA_NAME + and other is INTEGER_CST, prefer INTEGER_CST. */ + else if (vr1type == VR_RANGE + && INTEGER_CST == TREE_CODE (vr1min) + && INTEGER_CST == TREE_CODE (vr1max) + && (((INTEGER_CST != TREE_CODE (*vr0min) + && SSA_NAME != TREE_CODE (*vr0min)) + || ((INTEGER_CST != TREE_CODE (*vr0max) + && SSA_NAME != TREE_CODE (*vr0max)))))) + { + *vr0type = vr1type; + *vr0min = vr1min; + *vr0max = vr1max; + } + /* As a fallback simply use { *VRTYPE, *VR0MIN, *VR0MAX } as result for the intersection. That's always a conservative correct estimate unless VR1 is a constant singleton range in which case we choose that. */ - if (vr1type == VR_RANGE + else if (vr1type == VR_RANGE && is_gimple_min_invariant (vr1min) && vrp_operand_equal_p (vr1min, vr1max)) {