From patchwork Wed Aug 22 11:55:48 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marc Glisse X-Patchwork-Id: 179303 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id A0D702C0086 for ; Wed, 22 Aug 2012 21:56:35 +1000 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1346241395; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Date:From:To:Subject:Message-ID:User-Agent:MIME-Version: Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:Sender:Delivered-To; bh=O0a3Qf6 fWjl8yY1rPTjPiRAr23Y=; b=KkmewZWv9jg3FnPmms65LAIEsecPpw6T5aST+oF rCbFnWIWpWMxHT2Ykd4fm9P0yy9SmI0eUzxN6Y9Y601xlaO+PDE+x8WnL6E2CBVk t8Y2yAn+0ooH/GpmFF8mkaOOBr3C+93akTl6rZHs+S4XImXH7kYTDq1h7vXHs4pS irW8= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Date:From:To:Subject:Message-ID:User-Agent:MIME-Version:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=EhdO0lsVBZTExNfkmC2jJgms/2WUuOdl6uuUuM+FC5h8PlPLjC8mkteeDyXfpN +oBpRicOJoUNzuKBbYli1Ltwj/doW1V/XkjL58nD6Bh1JbdNjUSvNRzy4Gx0Plsz CBwPk5xPsN/p1meMTYfvYIflWhKCI9uaqAvnazkSsghEg=; Received: (qmail 29288 invoked by alias); 22 Aug 2012 11:56:24 -0000 Received: (qmail 29279 invoked by uid 22791); 22 Aug 2012 11:56:23 -0000 X-SWARE-Spam-Status: No, hits=-6.8 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, TW_OV X-Spam-Check-By: sourceware.org Received: from mail1-relais-roc.national.inria.fr (HELO mail1-relais-roc.national.inria.fr) (192.134.164.82) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 22 Aug 2012 11:55:51 +0000 Received: from stedding.saclay.inria.fr ([193.55.250.194]) by mail1-relais-roc.national.inria.fr with ESMTP/TLS/DHE-RSA-AES128-SHA; 22 Aug 2012 13:55:49 +0200 Received: from glisse (helo=localhost) by stedding.saclay.inria.fr with local-esmtp (Exim 4.80) (envelope-from ) id 1T49XI-0005i2-Se for gcc-patches@gcc.gnu.org; Wed, 22 Aug 2012 13:55:48 +0200 Date: Wed, 22 Aug 2012 13:55:48 +0200 (CEST) From: Marc Glisse To: gcc-patches@gcc.gnu.org Subject: Fix double_int overflow in VRP PLUS_EXPR Message-ID: User-Agent: Alpine 2.02 (DEB 1266 2009-07-14) MIME-Version: 1.0 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 Hello, when I adapted VRP PLUS_EXPR handling for __int128, I missed one place where double_int can overflow. Note that I have no idea if that helps for bug 54317, but that's where I noticed the issue. 2012-08-21 Marc Glisse PR tree-optimization/54317 gcc/ * tree-vrp.c (extract_range_from_binary_expr_1): Test for double_int overflow. Remove dead tests. gcc/testsuite/ * gcc.dg/tree-ssa/vrp79.c: New testcase. Index: testsuite/gcc.dg/tree-ssa/vrp79.c =================================================================== --- testsuite/gcc.dg/tree-ssa/vrp79.c (revision 0) +++ testsuite/gcc.dg/tree-ssa/vrp79.c (revision 0) @@ -0,0 +1,23 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-optimized" } */ + +#ifdef __SIZEOF_INT128__ +typedef unsigned __int128 NT; +#else +typedef unsigned long long NT; +#endif + +extern void do_not_go_away (); + +void f (NT x, NT y) +{ + NT n = 1; + n <<= (8 * sizeof (NT) - 1); + if (x > n) return; + if (y > n) return; + NT z = x + y; + if (z == 42) do_not_go_away (); +} + +/* { dg-final { scan-tree-dump "do_not_go_away" "optimized" } } */ +/* { dg-final { cleanup-tree-dump "optimized" } } */ Property changes on: testsuite/gcc.dg/tree-ssa/vrp79.c ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision URL Added: svn:eol-style + native Index: tree-vrp.c =================================================================== --- tree-vrp.c (revision 190590) +++ tree-vrp.c (working copy) @@ -2467,32 +2467,35 @@ extract_range_from_binary_expr_1 (value_ && max_ovf == 1) { /* Underflow and overflow, drop to VR_VARYING. */ set_value_range_to_varying (vr); return; } else { /* Min underflow or max overflow. The range kind changes to VR_ANTI_RANGE. */ + bool covers = false; double_int tem = tmin; gcc_assert ((min_ovf == -1 && max_ovf == 0) || (max_ovf == 1 && min_ovf == 0)); type = VR_ANTI_RANGE; tmin = double_int_add (tmax, double_int_one); + if (double_int_cmp (tmin, tmax, uns) < 0) + covers = true; tmax = double_int_add (tem, double_int_minus_one); + if (double_int_cmp (tmax, tem, uns) > 0) + covers = true; /* If the anti-range would cover nothing, drop to varying. Likewise if the anti-range bounds are outside of the types values. */ - if (double_int_cmp (tmin, tmax, uns) > 0 - || double_int_cmp (tmin, type_min, uns) < 0 - || double_int_cmp (tmax, type_max, uns) > 0) + if (covers || double_int_cmp (tmin, tmax, uns) > 0) { set_value_range_to_varying (vr); return; } min = double_int_to_tree (expr_type, tmin); max = double_int_to_tree (expr_type, tmax); } } else {