From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 130365 invoked by alias); 18 Oct 2019 14:04:53 -0000 Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org Received: (qmail 130353 invoked by uid 89); 18 Oct 2019 14:04:52 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-5.8 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.3.1 spammy=Wouldn't, Wouldnt X-HELO: foss.arm.com Received: from Unknown (HELO foss.arm.com) (217.140.110.172) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 18 Oct 2019 14:04:51 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 8DA8AFD9; Fri, 18 Oct 2019 07:04:43 -0700 (PDT) Received: from e120077-lin.cambridge.arm.com (e120077-lin.cambridge.arm.com [10.2.206.225]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 1C57E3F6C4; Fri, 18 Oct 2019 07:04:43 -0700 (PDT) Subject: Re: Crash when cross compiling for ARM with GCC-8-2-0 and -ftree-loop-distribute-patterns To: Josef Wolf , gcc-help@gcc.gnu.org References: <20191016131759.GA11171@raven.inka.de> <5b75d9aa-9f33-2ec6-ff46-713b113b3539@gmail.com> <20191017113157.GC11171@raven.inka.de> <20191017140423.GD11171@raven.inka.de> <20191018085314.GE11171@raven.inka.de> <20191018124107.GI11171@raven.inka.de> From: "Richard Earnshaw (lists)" Message-ID: <313d0deb-7aa3-3d80-5705-959423189f1e@arm.com> Date: Fri, 18 Oct 2019 14:04:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: <20191018124107.GI11171@raven.inka.de> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-SW-Source: 2019-10/txt/msg00086.txt.bz2 On 18/10/2019 13:41, Josef Wolf wrote: > On Fri, Oct 18, 2019 at 11:25:53AM +0100, Richard Earnshaw (lists) wrote: >> >> void * >> __attribute__ ((__optimize__ ("-fno-tree-loop-distribute-patterns"))) >> memset (void *s, int c, size_t n) >> { >> int i; >> for (i=0; i> ((char *)s)[i] = c; >> >> return s; >> } > > Wouldn't > > void *memset (void *s, int c, size_t n) > { > return __builtin_memset (s, c, n); > } > > be a cleaner solution to this? > > Unfortunately, this compiles to a jump to itself. No matter whether I use the > -fno-builtin-memset flag or not. > On most targets __builtin_memset will only compile to in-lined code if the size is known (and sufficiently small), it's intended for cases where you probably don't want a loop, but do want to make use of known size and alignment. It's not expected to be an all-singing all-dancing memset for this specific CPU. Writing a good memset can be hard (writing memcpy is even harder) and compilers rarely do as well as the best assembly code when trying to handle all the important cases; but they can do better in the limited conditions where the size and alignment are statically known since many hard-to-predict branches can be entirely eliminated. So in most cases, you *want* the compiler to call memset if the operation cannot really be optimized. R.