From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 124768 invoked by alias); 17 Aug 2016 07:52:26 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 124679 invoked by uid 89); 17 Aug 2016 07:52:25 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_PASS autolearn=ham version=3.3.2 spammy=eaten X-HELO: mx2.suse.de Received: from mx2.suse.de (HELO mx2.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 17 Aug 2016 07:52:15 +0000 Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id B35DAABEF; Wed, 17 Aug 2016 07:52:12 +0000 (UTC) Subject: Re: [PATCH 1/3] Fold BUILT_IN_STRNCASECMP To: Jakub Jelinek References: <20160817071031.GE14857@tucnak.redhat.com> Cc: gcc-patches@gcc.gnu.org From: =?UTF-8?Q?Martin_Li=c5=a1ka?= Message-ID: <2c13f061-faa4-5606-ae8e-2674a5dcabde@suse.cz> Date: Wed, 17 Aug 2016 07:52:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2 MIME-Version: 1.0 In-Reply-To: <20160817071031.GE14857@tucnak.redhat.com> Content-Type: multipart/mixed; boundary="------------C05A21323A51D75CE621F880" X-IsSubscribed: yes X-SW-Source: 2016-08/txt/msg01239.txt.bz2 This is a multi-part message in MIME format. --------------C05A21323A51D75CE621F880 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Content-length: 471 On 08/17/2016 09:10 AM, Jakub Jelinek wrote: > Did you really mean to use this block for strncasecmp only (rather than for > strncmp only, i.e. !is_strncasecmp)? Sure, that was a typo. Unfortunately I had a test case with strings that was eaten by fold_const_call. I enhanced test coverage for that. > > Also, while you are changing this, I'd replace > tree_fits_uhwi_p (len) && tree_to_uhwi (len) == 1 > with integer_onep (len). Fixed in v2. Martin > > Jakub --------------C05A21323A51D75CE621F880 Content-Type: text/x-patch; name="0001-Fold-BUILT_IN_STRNCASECMP-v2.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="0001-Fold-BUILT_IN_STRNCASECMP-v2.patch" Content-length: 2895 >From f1c30311d2f9274bd213fa703ad51da8151a1b1b Mon Sep 17 00:00:00 2001 From: marxin Date: Tue, 16 Aug 2016 15:10:13 +0200 Subject: [PATCH 1/3] Fold BUILT_IN_STRNCASECMP gcc/ChangeLog: 2016-08-16 Martin Liska * builtins.c (fold_builtin_strncmp): Rename to fold_builtin_strncmp_strncasecmp and support also strncasecmp. (fold_builtin_3): Handle BUILT_IN_STRNCASECMP. --- gcc/builtins.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/gcc/builtins.c b/gcc/builtins.c index 03a0dc8..3926049 100644 --- a/gcc/builtins.c +++ b/gcc/builtins.c @@ -150,7 +150,8 @@ static tree fold_builtin_strchr (location_t, tree, tree, tree); static tree fold_builtin_memchr (location_t, tree, tree, tree, tree); static tree fold_builtin_memcmp (location_t, tree, tree, tree); static tree fold_builtin_strcmp (location_t, tree, tree); -static tree fold_builtin_strncmp (location_t, tree, tree, tree); +static tree fold_builtin_strncmp_strncasecmp (location_t, tree, tree, tree, + bool); static tree fold_builtin_isascii (location_t, tree); static tree fold_builtin_toascii (location_t, tree); static tree fold_builtin_isdigit (location_t, tree); @@ -7383,11 +7384,13 @@ fold_builtin_strcmp (location_t loc, tree arg1, tree arg2) return NULL_TREE; } -/* Fold function call to builtin strncmp with arguments ARG1, ARG2, and LEN. - Return NULL_TREE if no simplification can be made. */ +/* Fold function call to builtin strncmp (or strncasecmp) with arguments ARG1, + ARG2, and LEN. Return NULL_TREE if no simplification can be made. + IS_STRNCASECMP is true for strncasecmp, false otherwise. */ static tree -fold_builtin_strncmp (location_t loc, tree arg1, tree arg2, tree len) +fold_builtin_strncmp_strncasecmp (location_t loc, tree arg1, tree arg2, + tree len, bool is_strncasecmp) { if (!validate_arg (arg1, POINTER_TYPE) || !validate_arg (arg2, POINTER_TYPE) @@ -7442,7 +7445,7 @@ fold_builtin_strncmp (location_t loc, tree arg1, tree arg2, tree len) /* If len parameter is one, return an expression corresponding to (*(const unsigned char*)arg1 - (const unsigned char*)arg2). */ - if (tree_fits_uhwi_p (len) && tree_to_uhwi (len) == 1) + if (!is_strncasecmp && integer_onep (len)) { tree cst_uchar_node = build_type_variant (unsigned_char_type_node, 1, 0); tree cst_uchar_ptr_node @@ -8483,7 +8486,10 @@ fold_builtin_3 (location_t loc, tree fndecl, break; case BUILT_IN_STRNCMP: - return fold_builtin_strncmp (loc, arg0, arg1, arg2); + return fold_builtin_strncmp_strncasecmp (loc, arg0, arg1, arg2, false); + + case BUILT_IN_STRNCASECMP: + return fold_builtin_strncmp_strncasecmp (loc, arg0, arg1, arg2, true); case BUILT_IN_MEMCHR: return fold_builtin_memchr (loc, arg0, arg1, arg2, type); -- 2.9.2 --------------C05A21323A51D75CE621F880--