From patchwork Wed Jun 24 06:36:25 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kugan Vivekanandarajah X-Patchwork-Id: 50252 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f69.google.com (mail-la0-f69.google.com [209.85.215.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id BE075216E1 for ; Wed, 24 Jun 2015 06:36:50 +0000 (UTC) Received: by laka10 with SMTP id a10sf8344490lak.2 for ; Tue, 23 Jun 2015 23:36: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:delivered-to:mailing-list:precedence:list-id :list-unsubscribe:list-archive:list-post:list-help:sender :delivered-to:message-id:date:from:user-agent:mime-version:to:cc :subject:references:in-reply-to:content-type:x-original-sender :x-original-authentication-results; bh=NFdJBKWQ2ERaM7KDoxdI1ijvtcvwC4LJrz43N6XV65Y=; b=Qa8Rt7pYvCUGUJ2vi+8ba3DKVsrM/R7x/eFoQd+LC2wtX4qrF3mW2hfACRizmysKlZ WfLUT5I8d961CytlsaGHzAyU2I5ioH2BCuW8hcMWhKnXzMSbGLM9KXShZE5J8ODcmGi2 3Qb36BKw1DyulvDns4rjimjs0RncnsBkWAVXik1VzVw62dNr/M9N1Q+JaSKtE22Q5WPb /G4scmfh4iMDuuk6gQOFhfAlBSBSFuGJJEJIQQVd+RnEG+Ur3no6yR+t2q9AvOAIBPZx SmaTn4bo02CXplMkeVL3xm+h8VNOQJC/MLI9B/YszAitv0ak9OaiN/qL+e4nCS+WITG0 xSoQ== X-Gm-Message-State: ALoCoQkkJpeQNWtx502fKtU3b5PfG5RejG6BbmJUGO/NEUrxyKUj9i92L680CdA+qG/Mc7Iyj+cg X-Received: by 10.112.148.101 with SMTP id tr5mr34902543lbb.13.1435127809566; Tue, 23 Jun 2015 23:36:49 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.204.103 with SMTP id kx7ls160522lac.62.gmail; Tue, 23 Jun 2015 23:36:49 -0700 (PDT) X-Received: by 10.152.21.5 with SMTP id r5mr38240355lae.24.1435127809312; Tue, 23 Jun 2015 23:36:49 -0700 (PDT) Received: from mail-lb0-x229.google.com (mail-lb0-x229.google.com. [2a00:1450:4010:c04::229]) by mx.google.com with ESMTPS id e8si21192703lah.96.2015.06.23.23.36.49 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 23 Jun 2015 23:36:49 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2a00:1450:4010:c04::229 as permitted sender) client-ip=2a00:1450:4010:c04::229; Received: by lbbpo10 with SMTP id po10so20197146lbb.3 for ; Tue, 23 Jun 2015 23:36:49 -0700 (PDT) X-Received: by 10.112.209.106 with SMTP id ml10mr38024399lbc.112.1435127808951; Tue, 23 Jun 2015 23:36:48 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.108.230 with SMTP id hn6csp3574264lbb; Tue, 23 Jun 2015 23:36:47 -0700 (PDT) X-Received: by 10.70.22.131 with SMTP id d3mr77028416pdf.67.1435127806794; Tue, 23 Jun 2015 23:36:46 -0700 (PDT) Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id tz6si38314912pab.216.2015.06.23.23.36.45 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 23 Jun 2015 23:36:46 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-401120-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Received: (qmail 32380 invoked by alias); 24 Jun 2015 06:36:34 -0000 Mailing-List: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org Precedence: list 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 32363 invoked by uid 89); 24 Jun 2015 06:36:33 -0000 X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.4 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-pd0-f173.google.com Received: from mail-pd0-f173.google.com (HELO mail-pd0-f173.google.com) (209.85.192.173) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Wed, 24 Jun 2015 06:36:32 +0000 Received: by pdjn11 with SMTP id n11so23776583pdj.0 for ; Tue, 23 Jun 2015 23:36:30 -0700 (PDT) X-Received: by 10.66.147.4 with SMTP id tg4mr77852706pab.69.1435127790283; Tue, 23 Jun 2015 23:36:30 -0700 (PDT) Received: from [10.1.1.6] (58-6-183-210.dyn.iinet.net.au. [58.6.183.210]) by mx.google.com with ESMTPSA id y1sm25475730pdy.2.2015.06.23.23.36.28 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 23 Jun 2015 23:36:29 -0700 (PDT) Message-ID: <558A4FE9.1090201@linaro.org> Date: Wed, 24 Jun 2015 16:36:25 +1000 From: Kugan User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.5.0 MIME-Version: 1.0 To: Richard Biener CC: "gcc-patches@gcc.gnu.org" Subject: Re: [VRP] Improve value ranges for unsigned division References: <55851248.3010408@linaro.org> In-Reply-To: X-IsSubscribed: yes X-Original-Sender: kugan.vivekanandarajah@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2a00:1450:4010:c04::229 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org; dkim=pass header.i=@gcc.gnu.org X-Google-Group-Id: 836684582541 On 23/06/15 01:09, Richard Biener wrote: > On Sat, Jun 20, 2015 at 9:12 AM, Kugan > wrote: >> As discussed in PR64130, this patch improves the VRP value ranges for >> unsigned division. >> >> Bootstrapped and regression tested on x86_64-linux-gnu and regression >> tested on arm-none-linux-gnu with no new regression. >> >> Is this OK for trunk? > > Hum, the patch is at least incomplete not covering the > cmp == -1 case in the max value computation, no? Thanks for the review. Attached patch adds this as well. > > Also I wonder if we have two VR_RANGEs as you require > the code using extract_range_from_multiplicative_op_1 isn't > better suited and already handles the case properly? > I tried with this approach. But, for value range of vr1 where min or max is zero, extract_range_from_multiplicative_op_1 will not be able to infer range. If we check for vr1 having zero before calling extract_range_from_multiplicative_op_1, then it is not going get the value range for the test case in PR (which is 2305843009213693951 / a where a has a range [0, 4294967295]) Thanks, Kugan > Richard. > >> Thanks, >> Kugan >> >> gcc/ChangeLog: >> >> 2015-06-20 Kugan Vivekanandarajah >> >> PR middle-end/64130 >> * tree-vrp.c (extract_range_from_binary_expr_1): For unsigned >> division, compute minimum when value ranges for dividend and >> divisor are available. >> >> >> gcc/testsuite/ChangeLog: >> >> 2015-06-20 Kugan Vivekanandarajah >> >> PR middle-end/64130 >> * gcc.dg/tree-ssa/pr64130.c: New test. diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr64130.c b/gcc/testsuite/gcc.dg/tree-ssa/pr64130.c index e69de29..9e96abb 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/pr64130.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr64130.c @@ -0,0 +1,11 @@ + +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-vrp1" } */ + +int funsigned(unsigned a) +{ + return 0x1ffffffffL / a == 0; +} + +/* { dg-final { scan-tree-dump ": \\\[2, 8589934591\\\]" "vrp1" } } */ + diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c index b517363..0b8fb31 100644 --- a/gcc/tree-vrp.c +++ b/gcc/tree-vrp.c @@ -3151,14 +3151,33 @@ extract_range_from_binary_expr_1 (value_range_t *vr, and all numbers from min to 0 for negative min. */ cmp = compare_values (vr0.max, zero); if (cmp == -1) - max = zero; + { + /* When vr0.max < 0, vr1.min != 0 and value + ranges for dividend and divisor are available. */ + if (vr1.type == VR_RANGE + && !symbolic_range_p (&vr0) + && !symbolic_range_p (&vr1) + && !compare_values (vr1.min, zero)) + max = int_const_binop (code, vr0.max, vr1.min); + else + max = zero; + } else if (cmp == 0 || cmp == 1) max = vr0.max; else type = VR_VARYING; cmp = compare_values (vr0.min, zero); if (cmp == 1) - min = zero; + { + /* For unsigned division when value ranges for dividend + and divisor are available. */ + if (vr1.type == VR_RANGE + && !symbolic_range_p (&vr0) + && !symbolic_range_p (&vr1)) + min = int_const_binop (code, vr0.min, vr1.max); + else + min = zero; + } else if (cmp == 0 || cmp == -1) min = vr0.min; else