From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 95255 invoked by alias); 12 Oct 2016 13:48: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 93827 invoked by uid 89); 12 Oct 2016 13:48:41 -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=built-ins, grown, Hx-languages-length:1546, overkill 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, 12 Oct 2016 13:48:39 +0000 Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 36BACAC9C; Wed, 12 Oct 2016 13:48:37 +0000 (UTC) Subject: [RFC] Possible folding opportunities for string built-ins To: gcc-patches@gcc.gnu.org References: From: =?UTF-8?Q?Martin_Li=c5=a1ka?= Cc: Richard Biener , Jan Hubicka , Jakub Jelinek Message-ID: <18b8d82e-59b8-8607-702f-8185f8e57311@suse.cz> Date: Wed, 12 Oct 2016 13:48: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: Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-IsSubscribed: yes X-SW-Source: 2016-10/txt/msg00899.txt.bz2 Hi. As you probably mentioned, simple folding improvement has grown to multiple patches and multiple iterations. Apart from that, I also noticed that we do not do the best for couple of cases and I would like to have a feedback if it worth to improve or not? $ cat /tmp/string-folding-missing.c const char global_1[4] = {'a', 'b', 'c', 'd' }; const char global_2[6] = "abcdefghijk"; int main() { const char local1[] = "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_constant is called multiple times, it can be overkill. 2) /tmp/xxxxx.c:2:26: warning: initializer-string for array of chars is too long const char global_2[6] = "abcdefghijk"; Here I'm not sure whether one can consider global_2 == "abcdef" (w/o trailing zero char) or not? If so, adding new output argument (string_length) to string_constant can be solution. 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? Last question is whether one can aggressively fold strcasecmp in a host compiler? Or are there any situations where results depends on locale? Thanks for thoughts. Martin