From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 49873 invoked by alias); 13 Oct 2016 08:38:48 -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 49855 invoked by uid 89); 13 Oct 2016 08:38:47 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.1 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,RCVD_IN_SORBS_SPAM,SPF_PASS autolearn=ham version=3.3.2 spammy=lowered X-HELO: mail-qt0-f182.google.com Received: from mail-qt0-f182.google.com (HELO mail-qt0-f182.google.com) (209.85.216.182) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 13 Oct 2016 08:38:37 +0000 Received: by mail-qt0-f182.google.com with SMTP id q7so35062784qtq.1 for ; Thu, 13 Oct 2016 01:38:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=eRD9Zu2bQjLG/v9O2zd+GvOOo7DxkcBAd3TkpAuNX20=; b=XuyTSzOlYn6bnmYmIN/8zwPlIcNMQxpU2/1mSX0j+veoarTmi+gJSIjj9p1NLzwQbN ewbZC6zC3RwGonPi8MmmLorcf0fbPxGzTnBr7ZQ1kJcjDJeVXVMR67AjJMvE/3CztlTN TKL8YmEnb10Pvspi2tC/aLkbuq+DuKiKsSuqfP6Rc1vph9psSmSEUEK12qSYFqPU5nkB ZhZJEn9atc15A8y6ycNKI+xhUgYWsFVU6dT6C1K+ZnfDLRCqUx7UCL7E6j1dhRvXj119 Vp3PBI+2iDwRZO7MgU5C4NLewkjNcvlkZjO9LV5FHHZezSzx2RKmN5fQg4cnp+MbPUu1 Hd5Q== X-Gm-Message-State: AA6/9RmrISe0X2SVxPOc+sWDFeFhxunArTkUycGHlvZDTML2/iIwLD98g8PMFVPZ6lROIlx/UyPw7a4vwb5wEA== X-Received: by 10.28.224.139 with SMTP id x133mr1285232wmg.6.1476347915802; Thu, 13 Oct 2016 01:38:35 -0700 (PDT) MIME-Version: 1.0 Received: by 10.28.155.146 with HTTP; Thu, 13 Oct 2016 01:38:35 -0700 (PDT) In-Reply-To: <18b8d82e-59b8-8607-702f-8185f8e57311@suse.cz> References: <18b8d82e-59b8-8607-702f-8185f8e57311@suse.cz> From: Richard Biener Date: Thu, 13 Oct 2016 08:38:00 -0000 Message-ID: Subject: Re: [RFC] Possible folding opportunities for string built-ins To: =?UTF-8?Q?Martin_Li=C5=A1ka?= Cc: GCC Patches , Jan Hubicka , Jakub Jelinek Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes X-SW-Source: 2016-10/txt/msg00985.txt.bz2 On Wed, Oct 12, 2016 at 3:48 PM, Martin Li=C5=A1ka wrote: > Hi. > > As you probably mentioned, simple folding improvement has grown to multip= le patches > and multiple iterations. Apart from that, I also noticed that we do not d= o the best > for couple of cases and I would like to have a feedback if it worth to im= prove or not? > > $ cat /tmp/string-folding-missing.c > const char global_1[4] =3D {'a', 'b', 'c', 'd' }; > const char global_2[6] =3D "abcdefghijk"; > > int main() > { > const char local1[] =3D "asdfasdfasdf"; > > /* Case 1 */ > __builtin_memchr (global_1, 'c', 5); > > /* Case 2 */ > __builtin_memchr (global_2, 'c', 5); > > /* Case 3 */ > __builtin_memchr (local1, 'a', 5); > > return 0; > } > > Cases: > 1) Currently, calling c_getstr (which calls string_constant) can't handle= CONSTRUCTOR. Potential > solution can be to create on demand STRING_CST, however as string_constan= t is called multiple times, > it can be overkill. I believe somewhere during GENERICIZation / GIMPLIFICATION we should simply turn those COSNTRUCTORs into STRING_CSTs ... (probably not in string_constant itself as that would be somewhat gross of a place). > 2) /tmp/xxxxx.c:2:26: warning: initializer-string for array of chars is t= oo long > const char global_2[6] =3D "abcdefghijk"; > Here I'm not sure whether one can consider global_2 =3D=3D "abcdef" (w/o = trailing zero char) or not? > If so, adding new output argument (string_length) to string_constant can = be solution. Likewise if we are able to warn the FE should be able to truncate the STRING_CST itself. The question is still whether a non-NULL terminated string should be constant folded (it looks like the STRING_PTR in a STRING_CST is always '\0' terminated). > 3) Currently, ctor_for_folding return error_mark_node for local variables= . I'm wondering whether returning > DECL_INITIAL for these would be doable? Will it make any issue for LTO? They do not prevail (ok, you might see this during GENERIC folding). They get lowered to runtime initialization either from a constant or a CONST_DECL (with DECL_INITIAL). For those CONST_DECLs we should return a ctor_for_folding. Richard. > Last question is whether one can aggressively fold strcasecmp in a host c= ompiler? Or are there any situations > where results depends on locale? > > Thanks for thoughts. > Martin