From patchwork Wed Apr 27 01:17:20 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kugan Vivekanandarajah X-Patchwork-Id: 66754 Delivered-To: patch@linaro.org Received: by 10.140.93.198 with SMTP id d64csp1917513qge; Tue, 26 Apr 2016 18:17:57 -0700 (PDT) X-Received: by 10.98.9.83 with SMTP id e80mr8022688pfd.34.1461719877707; Tue, 26 Apr 2016 18:17:57 -0700 (PDT) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id j186si841598pfb.136.2016.04.26.18.17.57 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Apr 2016 18:17:57 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-425727-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-425727-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-425727-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 :subject:to:references:cc:from:message-id:date:mime-version :in-reply-to:content-type; q=dns; s=default; b=eweD72wRk0HUQa72E 0nI6GFGP2V7/mT5HpgRKbxNsuhadGCGsI672E/u+JytIhfCV7rTaeJZuTCEbYH4B wIt8V+rSWBkHH0DU+GRRbjKW5jPwugwkvCjvzAHS5W2Fe8gxEHJkaP1db57/ZTR4 1ngF9SlXxQFigU9A1cOjbUbCGk= 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 :subject:to:references:cc:from:message-id:date:mime-version :in-reply-to:content-type; s=default; bh=A4+KPgC10OZ9o1+dWcB4D8H ROtE=; b=kkFq3EKJmYc+He0Jnv0JJo5gteaEh/NCC5iTbWNMzJdn2L+iblP2EOg YRltNTI4KhNJNZB8EUHLM2hYRo3hGk6TcU19XhfeVexo9Si1/ejFhPn88fwYN5i/ vVkVZrxSkK8ZW/9jsLra68zzmqaKsw4adb83n/np99O5njA/qoN8= Received: (qmail 30608 invoked by alias); 27 Apr 2016 01:17:40 -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 30599 invoked by uid 89); 27 Apr 2016 01:17:40 -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=sk:wide_in, kuganv@linaro.org, kugan.vivekanandarajah@linaro.org, kuganvlinaroorg X-HELO: mail-pf0-f173.google.com Received: from mail-pf0-f173.google.com (HELO mail-pf0-f173.google.com) (209.85.192.173) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Wed, 27 Apr 2016 01:17:30 +0000 Received: by mail-pf0-f173.google.com with SMTP id 206so13693564pfu.0 for ; Tue, 26 Apr 2016 18:17:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:subject:to:references:cc:from:message-id:date :user-agent:mime-version:in-reply-to; bh=KDMOlSl/DglCWTsePq1xqdWTUjqaw48yBCDsW/MtEwk=; b=LW/rnQzC/vMs5kCsCEDuAOkwseCHKg7soA7STolQKrY7M9HGss4ok+ReFfZ76Py+US IFLYgxIwc7AW6v6bJcSYyh8d4ev+Uz+J80hF3Ac398WwJefbfX56scqNEbULQIs7gQ8u DdCjtPAbkMFIzhTaZ1fngrBymuY+z8yXflMiORTnUbWPo6I9gmOZn9kV01Q+eRXM6TRU QnGp9V3+3FlMltu6pkdP22zmEVZUGqgcd+h7zDaXSyfj4L1rkTqh7iL+det7wA0yt5FU QYORJKH982iA38jVm5xpxuim4q7Hb9zkPlo+1CnsSk6Gt/oL0i+C/FhlMplv7V8yrB79 gohg== X-Gm-Message-State: AOPr4FW/IIONocRZCKbFz8UMH3aeAis2m+tOZcXPbPrUI2OCkgb9IddKh3Od9pEpHCPSBLFs X-Received: by 10.98.36.12 with SMTP id r12mr8006829pfj.86.1461719848070; Tue, 26 Apr 2016 18:17:28 -0700 (PDT) Received: from [10.1.1.8] (58-6-183-210.dyn.iinet.net.au. [58.6.183.210]) by smtp.googlemail.com with ESMTPSA id y2sm1320078pfi.39.2016.04.26.18.17.25 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 26 Apr 2016 18:17:27 -0700 (PDT) Subject: Re: [RFC][PR68217] Improve value range for signed & sign-bit-CST To: Richard Biener References: <5710C60B.2080308@linaro.org> Cc: "gcc-patches@gcc.gnu.org" From: kugan Message-ID: <57201320.4060106@linaro.org> Date: Wed, 27 Apr 2016 11:17:20 +1000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.5.1 MIME-Version: 1.0 In-Reply-To: X-IsSubscribed: yes On 27/04/16 00:14, Richard Biener wrote: > On Fri, Apr 15, 2016 at 12:44 PM, kugan > wrote: >> As pointed out by Richard, for signed & sign-bit-CST value range should be >> [-INF, 0] range, not a [-INF, INF] range as happens now. >> >> This patch fixes this. I bootstrapped and regression tested for >> x86-64-linux-gnu with no new regression. Is this OK for statege-1. > > I think you need to check vr0 for singleton-constant == sign_bit as well, > there is nothing that canonicalizes this during propagation. Thanks for the review. Here is the updated patch. I will bootstrap again and commit if this is OK. Thanks, Kugan > > Otherwise ok. > > Thanks, > Richard. > >> Thanks, >> Kugan >> >> >> gcc/ChangeLog: >> >> 2016-04-14 Kugan Vivekanandarajah >> >> PR middle-end/68217 >> * tree-vrp.c (extract_range_from_binary_expr_1): In case of signed & >> sign-bit-CST, >> generate [-INF, 0] instead of [-INF, INF]. >> >> >> gcc/testsuite/ChangeLog: >> >> 2016-04-14 Kugan Vivekanandarajah >> >> PR middle-end/68217 >> * gcc.dg/pr68217.c: New test. diff --git a/gcc/testsuite/gcc.dg/pr68217.c b/gcc/testsuite/gcc.dg/pr68217.c index e69de29..8197363 100644 --- a/gcc/testsuite/gcc.dg/pr68217.c +++ b/gcc/testsuite/gcc.dg/pr68217.c @@ -0,0 +1,14 @@ + +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-vrp1" } */ + +int foo (void) +{ + volatile int a = -1; + long long b = -9223372036854775807LL - 1; // LLONG_MIN + long long x = (a & b); // x == 0x8000000000000000 + if (x < 1LL) { ; } else { __builtin_abort(); } + return 0; +} + +/* { dg-final { scan-tree-dump "x_*: \\[-INF, 0\\]" "vrp1" } } */ diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c index bbdf9ce..a86d6dd 100644 --- a/gcc/tree-vrp.c +++ b/gcc/tree-vrp.c @@ -3115,6 +3115,24 @@ extract_range_from_binary_expr_1 (value_range *vr, if (int_cst_range1 && tree_int_cst_sgn (vr1.min) >= 0) wmax = wi::min (wmax, vr1.max, TYPE_SIGN (expr_type)); max = wide_int_to_tree (expr_type, wmax); + cmp = compare_values (min, max); + /* PR68217: In case of signed & sign-bit-CST should + result in [-INF, 0] instead of [-INF, INF]. */ + if (cmp == -2 || cmp == 1) + { + wide_int sign_bit + = wi::set_bit_in_zero (TYPE_PRECISION (expr_type) - 1, + TYPE_PRECISION (expr_type)); + if (!TYPE_UNSIGNED (expr_type) + && ((value_range_constant_singleton (&vr0) + && !wi::cmps (vr0.min, sign_bit)) + || (value_range_constant_singleton (&vr1) + && !wi::cmps (vr1.min, sign_bit)))) + { + min = TYPE_MIN_VALUE (expr_type); + max = build_int_cst (expr_type, 0); + } + } } else if (code == BIT_IOR_EXPR) {