From patchwork Fri Apr 15 10:44:27 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kugan Vivekanandarajah X-Patchwork-Id: 65893 Delivered-To: patch@linaro.org Received: by 10.140.93.198 with SMTP id d64csp1103253qge; Fri, 15 Apr 2016 03:45:16 -0700 (PDT) X-Received: by 10.98.9.83 with SMTP id e80mr28466261pfd.34.1460717116110; Fri, 15 Apr 2016 03:45:16 -0700 (PDT) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id g14si3262546pfd.189.2016.04.15.03.45.15 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 15 Apr 2016 03:45:16 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-424870-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-424870-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-424870-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=SGaGIeixK6X0RkJSObuGZNV6nVCDC5S2d27kln2zswjSg8adpA c8hUjLZNkXIaw8RjI9J4hXidIBI1l1SRg9EjK64aSU/7N9qQun+0R0Wg4xskHVaI 0PLCTlO+vGoqyKkP/vP/jAwEScsZPcuS7gHe0q6uwNj7DF9Ucv6NWu1Yw= 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=csYAZ+ZNMkx7zIDtV51K/zJvye8=; b=EJ4R9lW3J8IgGWawMT3i sPXHFBJ2kXeF8ivGy4HSnFunrsh262N4ttfgz4n/t4KJmksP3OEjaiVubAjYNLC3 4xy3wJAMSU1BtAGtC2FE6P93ao4Lmea6e4VnGkCDmek2wuXPcp3fBpBQNKQipq/E agnHzl5GakrrTIkcDm+xnIg= Received: (qmail 47302 invoked by alias); 15 Apr 2016 10:45:03 -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 47256 invoked by uid 89); 15 Apr 2016 10:45:02 -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=H*r:10.1.1, HX-Received:10.98.24.71, wi X-HELO: mail-pf0-f176.google.com Received: from mail-pf0-f176.google.com (HELO mail-pf0-f176.google.com) (209.85.192.176) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Fri, 15 Apr 2016 10:44:49 +0000 Received: by mail-pf0-f176.google.com with SMTP id c20so55877901pfc.1 for ; Fri, 15 Apr 2016 03:44:49 -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=nBgPKyzi473bn/8A0CPP5iTg5AJU6IdtJHGPbX98S1s=; b=IUBenmVv4VTkyzNUuYqP6KDpN4nNmqiXMmXMYx0l7mgp2gLjtGLs/wZKUc8DT2wpZe LOyHnYz1n8Lpsu5ezl4WrltubIAjWtGvkakgAhekchrzcmUAnMf5I93cO+Ubd4bPr+2s TVu3FnmFgsgwMKPteTiBYOfAR+PHgaYWJL6EWM43RzhlsFaVtuMbh8lyXGRnMbn/S4in NO6zy/Jij65hsTzTZTUA5VACUUpAHFxIj2H/Cw9wWbYsTJXUxKAESYC2zuEYlTOfsCjA MOZ+qoSgd+39j8UNfTpeFt0XxFEMJpGdudApK/w3g+soG85IVoGTSfFMX5om5ic+Iurd HWbQ== X-Gm-Message-State: AOPr4FUv1adjJjceSaUCY9SAUqrCKlDIy2yyCLl9W6QSJzQb4gppp8egTKdT4xPsKg1M4+tG X-Received: by 10.98.24.71 with SMTP id 68mr7097640pfy.160.1460717087309; Fri, 15 Apr 2016 03:44:47 -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 d19sm63811703pfj.92.2016.04.15.03.44.44 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 15 Apr 2016 03:44:46 -0700 (PDT) To: "gcc-patches@gcc.gnu.org" , Richard Biener From: kugan Subject: [RFC][PR68217] Improve value range for signed & sign-bit-CST Message-ID: <5710C60B.2080308@linaro.org> Date: Fri, 15 Apr 2016 20:44:27 +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 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. 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..3a021f3 100644 --- a/gcc/tree-vrp.c +++ b/gcc/tree-vrp.c @@ -3115,6 +3115,22 @@ 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 (&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) {