From patchwork Wed Nov 21 20:38:28 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 200855 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 B2FA92C008D for ; Thu, 22 Nov 2012 07:38:43 +1100 (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=1354135125; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Received:Date:From:To:Subject:Message-ID:Reply-To: MIME-Version:Content-Type:Content-Disposition:User-Agent: Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:Sender:Delivered-To; bh=W1ONJJDUWYDU6f/J2cQn DqYxUmc=; b=JE1mHGrQs2YOly+PhBB+uznYWUmfDURM34yAAuTBfaOdGlkKhk9E AVoxwLEYd6vm7o0zNNc3sVMjic7436jsB83VuGnitdwyerTh3kHon9RtGwn6zXuz miN9LeNa48dySzfLiWiXh/pJuXwghRi/OHetkdDhxTMjBYerF8DYD3M= 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:Received:Received:Date:From:To:Subject:Message-ID:Reply-To:MIME-Version:Content-Type:Content-Disposition:User-Agent:X-IsSubscribed:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=WDWqFMP42vgh1+dAl9bLR8KF8NcS2rYKKuiO9j5ArGFaWxa1L6wh0HKD0fLJjt X//f4tbSrsl1CArHYLRxzW1gK1mmfU6cXbWDNWYO3w1ETd3IsBrPvALMty86ohjJ YlwrhMo9osqIhnAGxIc6T5DSShhR6jPuq4JE5BbiAt58I=; Received: (qmail 29893 invoked by alias); 21 Nov 2012 20:38:39 -0000 Received: (qmail 29682 invoked by uid 22791); 21 Nov 2012 20:38:37 -0000 X-SWARE-Spam-Status: No, hits=-6.5 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, RCVD_IN_DNSWL_HI, RCVD_IN_HOSTKARMA_W, RP_MATCHES_RCVD, SPF_HELO_PASS X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 21 Nov 2012 20:38:33 +0000 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id qALKcWlH011656 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 21 Nov 2012 15:38:32 -0500 Received: from zalov.redhat.com (vpn1-6-55.ams2.redhat.com [10.36.6.55]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id qALKcTEe004386 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Wed, 21 Nov 2012 15:38:32 -0500 Received: from zalov.cz (localhost [127.0.0.1]) by zalov.redhat.com (8.14.5/8.14.5) with ESMTP id qALKcSAr017963 for ; Wed, 21 Nov 2012 21:38:29 +0100 Received: (from jakub@localhost) by zalov.cz (8.14.5/8.14.5/Submit) id qALKcSdS017962 for gcc-patches@gcc.gnu.org; Wed, 21 Nov 2012 21:38:28 +0100 Date: Wed, 21 Nov 2012 21:38:28 +0100 From: Jakub Jelinek To: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix VRP MULT_EXPR handling (PR tree-optimization/54471) Message-ID: <20121121203828.GI2315@tucnak.redhat.com> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes 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 Hi! If a type has 2 * HWI precision, sizem1 is maximum double_int (all ones) and thus size = sizem1 + double_int_one overflows into 0. If either min0 or min1 is also zero, we might wrongly canonicalize the range into a signed one. Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2012-11-21 Jakub Jelinek PR tree-optimization/54471 * tree-vrp.c (extract_range_from_binary_expr_1): For MULT_EXPR, don't canonicalize range if min2 is zero. * gcc.dg/tree-ssa/vrp86.c: New test. * gcc.c-torture/execute/pr54471.c: New test. Jakub --- gcc/tree-vrp.c.jj 2012-11-21 16:00:05.000085079 +0100 +++ gcc/tree-vrp.c 2012-11-21 18:24:58.385290035 +0100 @@ -2653,7 +2653,7 @@ extract_range_from_binary_expr_1 (value_ if (TYPE_UNSIGNED (expr_type)) { double_int min2 = size - min0; - if (min2.cmp (max0, true) < 0) + if (!min2.is_zero () && min2.cmp (max0, true) < 0) { min0 = -min2; max0 -= size; @@ -2661,7 +2661,7 @@ extract_range_from_binary_expr_1 (value_ } min2 = size - min1; - if (min2.cmp (max1, true) < 0) + if (!min2.is_zero () && min2.cmp (max1, true) < 0) { min1 = -min2; max1 -= size; --- gcc/testsuite/gcc.dg/tree-ssa/vrp86.c.jj 2012-11-21 18:27:53.389280736 +0100 +++ gcc/testsuite/gcc.dg/tree-ssa/vrp86.c 2012-11-21 18:27:47.000000000 +0100 @@ -0,0 +1,28 @@ +/* PR tree-optimization/54471 */ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-vrp1" } */ + +#ifdef __SIZEOF_INT128__ +#define T __int128 +#else +#define T long long +#endif + +void fn1call (void); +void fn2call (void); + +void +foo (unsigned T x) +{ + if (x > (unsigned T) -3) + return; + unsigned T y = 2 * x; + if (y == 42) + fn1call (); + else + fn2call (); +} + +/* { dg-final { scan-tree-dump "fn1call" "vrp1"} } */ +/* { dg-final { scan-tree-dump "fn2call" "vrp1"} } */ +/* { dg-final { cleanup-tree-dump "vrp1" } } */ --- gcc/testsuite/gcc.c-torture/execute/pr54471.c.jj 2012-11-21 18:24:58.386289954 +0100 +++ gcc/testsuite/gcc.c-torture/execute/pr54471.c 2012-11-21 18:24:58.386289954 +0100 @@ -0,0 +1,36 @@ +/* PR tree-optimization/54471 */ + +#ifdef __SIZEOF_INT128__ +#define T __int128 +#else +#define T long long +#endif + +extern void abort (void); + +__attribute__ ((noinline)) +unsigned T +foo (T ixi, unsigned ctr) +{ + unsigned T irslt = 1; + T ix = ixi; + + for (; ctr; ctr--) + { + irslt *= ix; + ix *= ix; + } + + if (irslt != 14348907) + abort (); + return irslt; +} + +int +main () +{ + unsigned T res; + + res = foo (3, 4); + return 0; +}