From patchwork Thu Sep 22 19:05:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 1390 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5044:0:0:0:0:0 with SMTP id h4csp344806wrt; Thu, 22 Sep 2022 12:06:25 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7MZuATsuZH6iC0WoR3s8EysxKTAKxInxL9+uBHApXQYOOanHVMzGwhdqQAciRQ9DDRq2t1 X-Received: by 2002:a17:907:7d8b:b0:781:cfa4:5058 with SMTP id oz11-20020a1709077d8b00b00781cfa45058mr4050459ejc.15.1663873585226; Thu, 22 Sep 2022 12:06:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663873585; cv=none; d=google.com; s=arc-20160816; b=Hk92aL9MIxkHh6Cfe5rlQIH2Hb39VLktfxRdHYsZWKiGiez898LibkwpoUbYUh8e9s Jcx7JStGyc1YgqRZIdZOcswHYzfqHDEXpdh8xHk7rDXrJRVkREuSQj6k9SCGcH3ugbUo 1BWw6jNZrA+4tLXwC5o/5I14j20w7GxARFqPu6MtK3Fv8rz4ji6D5L3gRfNrXS4v0Bp5 bk/kD2yuluRuQb7b0/tgJHhSqqzVKUnCoXZPkfiSQ72JNwLXUMB3wpnquCxVTBEeSEsi ubjW1wKwBb9I5GeRHXrvSSixA4YTmvN8hHKLZfyqaR2gSRY7z7oLqegypdSEGjy9KpGR Hj5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:content-language :in-reply-to:references:to:subject:user-agent:mime-version:date :message-id:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=rOU9oQ28uz5Lj5xeL1DV8G/MK5weGXp3Rz66r99dohA=; b=P353t6i0QAZ1rlUxYpysfjVtLBCi8cRhPZMAlBynCcH5Nsb9dQJs/L3W+9FMDcsQ3D QA4Awbnu3olryF11opsCg9pKK0RvheRKRY6h0ZSbRpizBalgASKq5KHAWLwauoyGu614 QtPe7KOrCEztMI/xcjyxJqdOgWXj/5KQa3AS+Z38oDx7ew+uTCKd3m1zxsEpNgAX5UBO ve9uH+QI7yY2Ucu2pW9CoyMszAGt8DQGbdqVb0vns/iiC4lFUfoJZPexV1ykh20F4aiy wfcMt+GzB4TovuoSUvcNOl1kY70H22AdU8hpHn7DAANZIM96uYW/EKarr3bnzBhi1s8G w4/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=dYf9u0O2; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id jg24-20020a170907971800b00734be0ce0e5si6572085ejc.311.2022.09.22.12.06.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Sep 2022 12:06:25 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=dYf9u0O2; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6DC4C3857BBE for ; Thu, 22 Sep 2022 19:06:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6DC4C3857BBE DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1663873560; bh=rOU9oQ28uz5Lj5xeL1DV8G/MK5weGXp3Rz66r99dohA=; h=Date:Subject:To:References:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=dYf9u0O2OeARinCCeZNBYlog8x5dNjYCbNZX/5P2c/bGnfc3J+9MX7jJuNN5weBCl XcANZTGhGYocbev5l/5WMDkBG1RxDeK8UvIpIRedc04PBeEbKLOBYeQacfjRf1EToz E883wdkuod6+Lk6K9LOT69jPv02vZ04Oq96xO5lM= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 136523858D38 for ; Thu, 22 Sep 2022 19:05:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 136523858D38 Received: from mail-io1-f70.google.com (mail-io1-f70.google.com [209.85.166.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-280-VghFO8FcN4u8Bo0DMNH0fg-1; Thu, 22 Sep 2022 15:05:11 -0400 X-MC-Unique: VghFO8FcN4u8Bo0DMNH0fg-1 Received: by mail-io1-f70.google.com with SMTP id e14-20020a6b500e000000b006a13488a320so5255282iob.12 for ; Thu, 22 Sep 2022 12:05:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:references:cc:to:from:content-language:subject :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date; bh=5A6g9okRxuw7nwmv3WZG55WH3BZM30HH8oaRwpCg/os=; b=gNG9XC5H5To6Bw2rB/R80WiVLEcOaoV1AQoKHawN+v2DYHAAvWa9Gb6PrphdoDFSj+ 3UrT3LLeTktizMpSbPTc6+EGy4HXYdszjGWHKDQyHlr7QtSSsp+Bo2MnwqlSnOvHEeX3 KA5ebir4CZz7EEgbs0hqR0qI653CdMbiUbyKbq4GyvSwHZ26JTHwIHe3bK7IZlS8CjQq Fg8aaoMC9zCV7vQ374vXRv11fDdXoM/X5cFpelq2gQqqV5HaoWGutDvboi0Qhat5j40i KqZ0Dr+zWWUjw1hFTiJoxDJeT5R6dfScfrMtbzpsWqGZUQFO8r7StEOCqOs0WyDio1vs KuZA== X-Gm-Message-State: ACrzQf2j796J/FyQ3Ji1i0bwDyn+J6IVGdCOgErMhk5QXaldVbCbHr39 LcvBWwEhsQupcdGTn9cosgte9iyW00Z7KxuR6/cy9jqlWOupnjUIKcLkGAGz0a2fugDEs9qfFwQ aD77MGTvxmGNjnzU7+KQIGixBFkQ106QzANLv8Bdn0xBe5kbTYnGov54y4yqtVDpZorxi1g== X-Received: by 2002:a05:6638:4192:b0:34a:4959:edf5 with SMTP id az18-20020a056638419200b0034a4959edf5mr2750284jab.193.1663873510369; Thu, 22 Sep 2022 12:05:10 -0700 (PDT) X-Received: by 2002:a05:6638:4192:b0:34a:4959:edf5 with SMTP id az18-20020a056638419200b0034a4959edf5mr2750270jab.193.1663873510090; Thu, 22 Sep 2022 12:05:10 -0700 (PDT) Received: from ?IPV6:2607:fea8:a263:f600::3dbe? ([2607:fea8:a263:f600::3dbe]) by smtp.gmail.com with ESMTPSA id i124-20020a6bb882000000b006a0cd2ab8dfsm2619469iof.8.2022.09.22.12.05.08 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 22 Sep 2022 12:05:09 -0700 (PDT) Message-ID: <99671c98-c81e-1fa3-b851-263492a54669@redhat.com> Date: Thu, 22 Sep 2022 15:05:08 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.2.1 Subject: [PATCH 09/17] Convert CFN_BUILT_IN_TOUPPER and TOLOWER to range-ops. To: gcc-patches References: <571782f9-72e6-5c30-da55-b8d62d3a153e@redhat.com> In-Reply-To: <571782f9-72e6-5c30-da55-b8d62d3a153e@redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US X-Spam-Status: No, score=-12.7 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Andrew MacLeod via Gcc-patches From: Andrew MacLeod Reply-To: Andrew MacLeod Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1744697908681143384?= X-GMAIL-MSGID: =?utf-8?q?1744697908681143384?= Bootstrapped on x86_64-pc-linux-gnu with no regressions.  Pushed. Andrew From 2f5da730f159de238500c82b0c6ef6c9ab91b1c2 Mon Sep 17 00:00:00 2001 From: Andrew MacLeod Date: Tue, 20 Sep 2022 17:14:30 -0400 Subject: [PATCH 09/17] Convert CFN_BUILT_IN_TOUPPER and TOLOWER to range-ops. * gimple-range-fold.cc (get_letter_range): Move to new class. (range_of_builtin_int_call): Remove case for CFN_BUILT_IN_TOUPPER and CFN_BUILT_IN_TOLOWER. * gimple-range-op.cc (class cfn_toupper_tolower): New. (gimple_range_op_handler::maybe_builtin_call): Set arguments. --- gcc/gimple-range-fold.cc | 66 ---------------------------------- gcc/gimple-range-op.cc | 77 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+), 66 deletions(-) diff --git a/gcc/gimple-range-fold.cc b/gcc/gimple-range-fold.cc index 417a925ac9f..af1f83f7409 100644 --- a/gcc/gimple-range-fold.cc +++ b/gcc/gimple-range-fold.cc @@ -887,28 +887,6 @@ fold_using_range::range_of_builtin_ubsan_call (irange &r, gcall *call, r.set_varying (type); } -// Return TRUE if we recognize the target character set and return the -// range for lower case and upper case letters. - -static bool -get_letter_range (tree type, irange &lowers, irange &uppers) -{ - // ASCII - int a = lang_hooks.to_target_charset ('a'); - int z = lang_hooks.to_target_charset ('z'); - int A = lang_hooks.to_target_charset ('A'); - int Z = lang_hooks.to_target_charset ('Z'); - - if ((z - a == 25) && (Z - A == 25)) - { - lowers = int_range<2> (build_int_cst (type, a), build_int_cst (type, z)); - uppers = int_range<2> (build_int_cst (type, A), build_int_cst (type, Z)); - return true; - } - // Unknown character set. - return false; -} - // For a builtin in CALL, return a range in R if known and return // TRUE. Otherwise return FALSE. @@ -944,50 +922,6 @@ fold_using_range::range_of_builtin_int_call (irange &r, gcall *call, switch (func) { - case CFN_BUILT_IN_TOUPPER: - { - arg = gimple_call_arg (call, 0); - // If the argument isn't compatible with the LHS, do nothing. - if (!range_compatible_p (type, TREE_TYPE (arg))) - return false; - if (!src.get_operand (r, arg)) - return false; - - int_range<3> lowers; - int_range<3> uppers; - if (!get_letter_range (type, lowers, uppers)) - return false; - - // Return the range passed in without any lower case characters, - // but including all the upper case ones. - lowers.invert (); - r.intersect (lowers); - r.union_ (uppers); - return true; - } - - case CFN_BUILT_IN_TOLOWER: - { - arg = gimple_call_arg (call, 0); - // If the argument isn't compatible with the LHS, do nothing. - if (!range_compatible_p (type, TREE_TYPE (arg))) - return false; - if (!src.get_operand (r, arg)) - return false; - - int_range<3> lowers; - int_range<3> uppers; - if (!get_letter_range (type, lowers, uppers)) - return false; - - // Return the range passed in without any upper case characters, - // but including all the lower case ones. - uppers.invert (); - r.intersect (uppers); - r.union_ (lowers); - return true; - } - CASE_CFN_FFS: CASE_CFN_POPCOUNT: // __builtin_ffs* and __builtin_popcount* return [0, prec]. diff --git a/gcc/gimple-range-op.cc b/gcc/gimple-range-op.cc index d62dff5f92e..45384d990ae 100644 --- a/gcc/gimple-range-op.cc +++ b/gcc/gimple-range-op.cc @@ -322,6 +322,71 @@ public: } } op_cfn_signbit; +// Implement range operator for CFN_BUILT_IN_TOUPPER and CFN_BUILT_IN_TOLOWER. +class cfn_toupper_tolower : public range_operator +{ +public: + using range_operator::fold_range; + cfn_toupper_tolower (bool toupper) { m_toupper = toupper; } + virtual bool fold_range (irange &r, tree type, const irange &lh, + const irange &, relation_kind) const; +private: + bool get_letter_range (tree type, irange &lowers, irange &uppers) const; + bool m_toupper; +} op_cfn_toupper (true), op_cfn_tolower (false); + +// Return TRUE if we recognize the target character set and return the +// range for lower case and upper case letters. + +bool +cfn_toupper_tolower::get_letter_range (tree type, irange &lowers, + irange &uppers) const +{ + // ASCII + int a = lang_hooks.to_target_charset ('a'); + int z = lang_hooks.to_target_charset ('z'); + int A = lang_hooks.to_target_charset ('A'); + int Z = lang_hooks.to_target_charset ('Z'); + + if ((z - a == 25) && (Z - A == 25)) + { + lowers = int_range<2> (build_int_cst (type, a), build_int_cst (type, z)); + uppers = int_range<2> (build_int_cst (type, A), build_int_cst (type, Z)); + return true; + } + // Unknown character set. + return false; +} + +bool +cfn_toupper_tolower::fold_range (irange &r, tree type, const irange &lh, + const irange &, relation_kind) const +{ + int_range<3> lowers; + int_range<3> uppers; + if (!get_letter_range (type, lowers, uppers)) + return false; + + r = lh; + if (m_toupper) + { + // Return the range passed in without any lower case characters, + // but including all the upper case ones. + lowers.invert (); + r.intersect (lowers); + r.union_ (uppers); + } + else + { + // Return the range passed in without any lower case characters, + // but including all the upper case ones. + uppers.invert (); + r.intersect (uppers); + r.union_ (lowers); + } + return true; +} + // Set up a gimple_range_op_handler for any built in function which can be // supported via range-ops. @@ -358,6 +423,18 @@ gimple_range_op_handler::maybe_builtin_call () m_valid = true; break; + case CFN_BUILT_IN_TOUPPER: + case CFN_BUILT_IN_TOLOWER: + // Only proceed If the argument is compatible with the LHS. + m_op1 = gimple_call_arg (call, 0); + if (range_compatible_p (type, TREE_TYPE (m_op1))) + { + m_valid = true; + m_int = (func == CFN_BUILT_IN_TOLOWER) ? &op_cfn_tolower + : &op_cfn_toupper; + } + break; + default: break; } -- 2.37.3