From patchwork Sat Jun 20 07:12:08 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kugan Vivekanandarajah X-Patchwork-Id: 50120 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f200.google.com (mail-lb0-f200.google.com [209.85.217.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 89F1D228D9 for ; Sat, 20 Jun 2015 07:12:33 +0000 (UTC) Received: by lbcak1 with SMTP id ak1sf33276206lbc.2 for ; Sat, 20 Jun 2015 00:12:32 -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 :subject:content-type:x-original-sender :x-original-authentication-results; bh=wC6LEdR3yKv8o+wdcHWG13AJRhuzKfoRVjeD2i2QQrg=; b=dQ7gb95soH3fxnQRPJwLZLYByb+0A8Kt8T0SqUUkuRjvXXgLutQuSLnFtokTJ7I8ZQ TwbuewuaRSNT+73l3RwTR09M6mLxpfcmsNpqshekpXMoZe+DftHTT3jkHqDRcWOoP6sI PyAX6rn7yVioMQUzSHel8eGFS51ZYm8WFPBZpxHbob5GG7R4AiE24anj6QgGKIF2SMxK XPaaT6Jit9yFthh4KkqBTjP+zi1senhPHC1ULiKnJ4wFQKleYWs4bU+nGeIaRFY9IhPr +Y+hDiJ11slzdleOwiCzqXlSa2FNwgOVWVldY2pvLLf7+iC4AzG0RRiVxC+PMfo3eH5L YnvA== X-Gm-Message-State: ALoCoQlw+LBAFY30GxBrQtwNjkz+V29SKiTJw2Myp/cB4vWIw6/uM6kXCg+Pef6tQVnWZwrpxK2O X-Received: by 10.180.216.12 with SMTP id om12mr6701445wic.1.1434784352123; Sat, 20 Jun 2015 00:12:32 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.18.199 with SMTP id y7ls607075lad.47.gmail; Sat, 20 Jun 2015 00:12:31 -0700 (PDT) X-Received: by 10.112.126.136 with SMTP id my8mr21091506lbb.18.1434784351904; Sat, 20 Jun 2015 00:12:31 -0700 (PDT) Received: from mail-la0-x235.google.com (mail-la0-x235.google.com. [2a00:1450:4010:c03::235]) by mx.google.com with ESMTPS id js14si11091203lab.166.2015.06.20.00.12.31 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 20 Jun 2015 00:12:31 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2a00:1450:4010:c03::235 as permitted sender) client-ip=2a00:1450:4010:c03::235; Received: by labko7 with SMTP id ko7so85565795lab.2 for ; Sat, 20 Jun 2015 00:12:31 -0700 (PDT) X-Received: by 10.152.88.68 with SMTP id be4mr20937147lab.76.1434784351322; Sat, 20 Jun 2015 00:12:31 -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 hn6csp1058906lbb; Sat, 20 Jun 2015 00:12:29 -0700 (PDT) X-Received: by 10.70.90.162 with SMTP id bx2mr15161875pdb.60.1434784349037; Sat, 20 Jun 2015 00:12:29 -0700 (PDT) Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id za1si19926161pbb.154.2015.06.20.00.12.28 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 20 Jun 2015 00:12:29 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-400849-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Received: (qmail 100690 invoked by alias); 20 Jun 2015 07:12:16 -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 100676 invoked by uid 89); 20 Jun 2015 07:12:16 -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-f170.google.com Received: from mail-pd0-f170.google.com (HELO mail-pd0-f170.google.com) (209.85.192.170) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Sat, 20 Jun 2015 07:12:15 +0000 Received: by pdbci14 with SMTP id ci14so46323392pdb.2 for ; Sat, 20 Jun 2015 00:12:13 -0700 (PDT) X-Received: by 10.70.130.35 with SMTP id ob3mr39252984pdb.64.1434784333197; Sat, 20 Jun 2015 00:12:13 -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 kk6sm13231421pdb.94.2015.06.20.00.12.11 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 20 Jun 2015 00:12:12 -0700 (PDT) Message-ID: <55851248.3010408@linaro.org> Date: Sat, 20 Jun 2015 17:12:08 +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: "gcc-patches@gcc.gnu.org" Subject: [VRP] Improve value ranges for unsigned division 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:c03::235 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 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? 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..2e1c84b 100644 --- a/gcc/tree-vrp.c +++ b/gcc/tree-vrp.c @@ -3158,7 +3158,16 @@ extract_range_from_binary_expr_1 (value_range_t *vr, 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