From patchwork Thu Aug 3 07:28:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prathamesh Kulkarni X-Patchwork-Id: 109300 Delivered-To: patch@linaro.org Received: by 10.140.101.6 with SMTP id t6csp424265qge; Thu, 3 Aug 2017 00:28:26 -0700 (PDT) X-Received: by 10.99.123.81 with SMTP id k17mr742525pgn.432.1501745306477; Thu, 03 Aug 2017 00:28:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1501745306; cv=none; d=google.com; s=arc-20160816; b=onFGsWAEkXkiSzRTAhSlzVcDyi77KGP9YjyGg3Bma0E+nM+CBbTxV+XE2Xv4sm8nfP I0OnQH5MgjGv1q8B9baCBVEs+TtBLG6n472vDY0moDFATzIeCXiNZ2fazChs7Ct8rtP6 HUzgFkXMuGXx6xIa25xS5SipXObnJvZGAF62yHTATLVyTXEGOS1KyODahtlY6m8vwrxG mfwUa4tX+yJoP3M/As/qoRpC+n57MwZvNM7LiiIXPVTXcz+uxo236a60+abdeqyms1dq rqzpIyiFXZpUKOy+2oOxL5pZDpjnC1W9L77+eN1mDmZHiCPTXIvkJh3nJiLAPDJwDkys bdyw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=to:subject:message-id:date:from:mime-version:delivered-to:sender :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:mailing-list:dkim-signature:domainkey-signature :arc-authentication-results; bh=2WyO8hVf/A3AL3vthpQYHeBHS6Ys5HQYtlYPKHO0Zr8=; b=MGABk4C2V+btOTHhNNKsf62zeIX8sIQiGt9rVOJgs4ydtTEEsseTTZ23mzflsPLpXn 52p4t46xLhNRi0yO+NyuXclJfYe60aKgNZIaaDviCTO8NjFT6jqg/CyajT4hd9aztdet WMS2sBns9tCO/n9tzgWWW7+TFmkY+DPE5BuVnjXq9hHlRg84ybH7n/1pGfApsy3vo5D8 BsFg2FDvOBRpyaOD8Rqwfw7PNiJ4C5rFY599+ZvJdG7tfu0KbUSFFlDPjR1F8fPKB+AI pPMRO501YlI0iQ7IGGMXGgN9tcp7m7CtMAEBK30CJvcEkdFolI5L5WcjuDtR6i9GcPXO 3zWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.b=I3R3w1gR; spf=pass (google.com: domain of gcc-patches-return-459696-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-459696-patch=linaro.org@gcc.gnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id o125si2987925pfb.358.2017.08.03.00.28.26 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 03 Aug 2017 00:28:26 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-459696-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 header.b=I3R3w1gR; spf=pass (google.com: domain of gcc-patches-return-459696-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-459696-patch=linaro.org@gcc.gnu.org; dmarc=fail (p=NONE sp=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 :mime-version:from:date:message-id:subject:to:content-type; q= dns; s=default; b=dZ3EWBCqJkCc3QuDvVa1HMOfNCvjnc0PMdAeUfnpfQWsrw gZAtRv1HConP7+glIFYmWiCXwUaPoUn1VpQ8oOp0Xg5OoJs6399wWiMzojWaJ+Hs ZqnhkJBr3ron3i9y5mBVZxEuzd32K2eBxB2n8EXKifA3lrCN9rrop7teUDfrA= 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 :mime-version:from:date:message-id:subject:to:content-type; s= default; bh=29CRSIMP2uPXj4glGFOwn57WdbE=; b=I3R3w1gRIOlz6jO3SR8o YhnHfl0rSRiqh/es/PgR59izRcbJearZG8ij6ZF2nNJcn6T9yov8tGW/YOger6Ws JebIoNd+iX0RDq1nV1eT5G9HA5Ey+ptIfjNlMSIKweLxwlsMCrkIVnXcoYmsJ2s4 Ok3aU5t8zJgr3s5XKwdVcCk= Received: (qmail 67284 invoked by alias); 3 Aug 2017 07:28:12 -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 66640 invoked by uid 89); 3 Aug 2017 07:28:11 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mail-wm0-f42.google.com Received: from mail-wm0-f42.google.com (HELO mail-wm0-f42.google.com) (74.125.82.42) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 03 Aug 2017 07:28:09 +0000 Received: by mail-wm0-f42.google.com with SMTP id t201so7547907wmt.1 for ; Thu, 03 Aug 2017 00:28:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=toLdmZzqBkZS2iPFWsLs9tGhvKKAwrc9+Oj9pLyZ6NY=; b=d9O2KIlAPbhgo9QbvIzF4m7/Eu8gHtgIL6EjfwFVNv43Av3qKb8vCqfIE6C8h4m8dp wbgQwCLVhVQGIvGh5QWpS3CoZlHrNajSA7bSt7982qy3R4aZvVrrdqyeqtD0MDTIW0xg VdHIvPLG/vtCCTsq5T1YB6OVBX2B+uh1yVGPlytl2qW6t3ovry0ssdTOMPEfQCxd6tSV VLi6XmVc3IH33XUK6PB/XQYh8fOZegrx+xoqdD/2Ty6tbtKSpI5JcI0dMIlYaEi4BJip 5lfTUujD9x86vHYrr5R2s3jY0FKp229Bto68i+LIbY6GPiKBHEI5dbYg0o09eEr1Mb+f PxCw== X-Gm-Message-State: AHYfb5hBZenfEIfo6vsEnQb2G8aQJYWx88A0LQ3DlkgeqMJT7r/5S2Qx Gy3eBRQpPuxY2Rs+NC4gEzV7wy3NjkWZ/ClnUQ== X-Received: by 10.28.144.68 with SMTP id s65mr457759wmd.175.1501745287494; Thu, 03 Aug 2017 00:28:07 -0700 (PDT) MIME-Version: 1.0 Received: by 10.223.134.103 with HTTP; Thu, 3 Aug 2017 00:28:06 -0700 (PDT) From: Prathamesh Kulkarni Date: Thu, 3 Aug 2017 12:58:06 +0530 Message-ID: Subject: PR78888 - add value range info for tolower/toupper To: gcc Patches X-IsSubscribed: yes Hi, The attached patch adds value-range info for __builtin_tolower and __builtin_toupper. In the patch, I have just settled for anti-range ~['a', 'z'] for return value of toupper. Would that be correct albeit imprecise ? A more precise range would be: [0, UCHAR_MAX] intersect ~['a', 'z'] union EOF as mentioned in PR. I am not sure though if it's possible for a SSA_NAME to have multiple disjoint ranges ? Bootstrap+tested on x86_64-unknown-linux-gnu. Thanks, Prathamesh diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr78888.c b/gcc/testsuite/gcc.dg/tree-ssa/pr78888.c new file mode 100644 index 00000000000..2bcddf1f2c3 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr78888.c @@ -0,0 +1,16 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-evrp-slim" } */ + +void g (int x) +{ + if (__builtin_toupper ((unsigned char)x) == 'a') + __builtin_abort (); +} + +void h (int x) +{ + if (__builtin_tolower ((unsigned char)x) == 'A') + __builtin_abort (); +} + +/* { dg-final { scan-tree-dump-not "__builtin_abort" "evrp" } } */ diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c index 79a29bf0efb..7137a4c52ec 100644 --- a/gcc/tree-vrp.c +++ b/gcc/tree-vrp.c @@ -3778,6 +3778,19 @@ extract_range_basic (value_range *vr, gimple *stmt) return; } break; + case CFN_BUILT_IN_TOUPPER: + case CFN_BUILT_IN_TOLOWER: + if (tree lhs = gimple_call_lhs (stmt)) + { + tree type = TREE_TYPE (lhs); + unsigned char min = (cfn == CFN_BUILT_IN_TOUPPER) ? 'a' : 'A'; + unsigned char max = (cfn == CFN_BUILT_IN_TOUPPER) ? 'z' : 'Z'; + tree range_min = build_int_cstu (type, min); + tree range_max = build_int_cstu (type, max); + set_value_range (vr, VR_ANTI_RANGE, range_min, range_max, NULL); + return; + } + break; default: break; }