From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate.crashing.org (gate.crashing.org [63.228.1.57]) by sourceware.org (Postfix) with ESMTP id 8662F3858C2F; Mon, 15 Aug 2022 21:13:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 8662F3858C2F Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=kernel.crashing.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=kernel.crashing.org Received: from gate.crashing.org (localhost.localdomain [127.0.0.1]) by gate.crashing.org (8.14.1/8.14.1) with ESMTP id 27FLCQir006853; Mon, 15 Aug 2022 16:12:26 -0500 Received: (from segher@localhost) by gate.crashing.org (8.14.1/8.14.1/Submit) id 27FLCQZZ006852; Mon, 15 Aug 2022 16:12:26 -0500 X-Authentication-Warning: gate.crashing.org: segher set sender to segher@kernel.crashing.org using -f Date: Mon, 15 Aug 2022 16:12:25 -0500 From: Segher Boessenkool To: Jiufu Guo Cc: gcc-patches@gcc.gnu.org, dje.gcc@gmail.com, linkw@gcc.gnu.org Subject: Re: [RFC]rs6000: split complicated constant to memory Message-ID: <20220815211225.GJ25951@gate.crashing.org> References: <20220815052519.194582-1-guojiufu@linux.ibm.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220815052519.194582-1-guojiufu@linux.ibm.com> User-Agent: Mutt/1.4.2.3i X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, KAM_SHORT, SPF_HELO_PASS, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=no 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-List-Received-Date: Mon, 15 Aug 2022 21:13:29 -0000 Hi! On Mon, Aug 15, 2022 at 01:25:19PM +0800, Jiufu Guo wrote: > This patch tries to put the constant into constant pool if building the > constant requires 3 or more instructions. > > But there is a concern: I'm wondering if this patch is really profitable. > > Because, as I tested, 1. for simple case, if instructions are not been run > in parallel, loading constant from memory maybe faster; but 2. if there > are some instructions could run in parallel, loading constant from memory > are not win comparing with building constant. As below examples. > > For f1.c and f3.c, 'loading' constant would be acceptable in runtime aspect; > for f2.c and f4.c, 'loading' constant are visibly slower. > > For real-world cases, both kinds of code sequences exist. > > So, I'm not sure if we need to push this patch. > > Run a lot of times (1000000000) below functions to check runtime. > f1.c: > long foo (long *arg, long*, long *) > { > *arg = 0x1234567800000000; > } > asm building constant: > lis 10,0x1234 > ori 10,10,0x5678 > sldi 10,10,32 > vs. asm loading > addis 10,2,.LC0@toc@ha > ld 10,.LC0@toc@l(10) This is just a load insn, unless this is the only thing needing the TOC. You can use crtl->uses_const_pool as an approximation here, to figure out if we have that case? > The runtime between 'building' and 'loading' are similar: some times the > 'building' is faster; sometimes 'loading' is faster. And the difference is > slight. When there is only one constant, sure. But that isn't the expensive case we need to avoid :-) > addis 9,2,.LC2@toc@ha > ld 7,.LC0@toc@l(7) > ld 10,.LC1@toc@l(10) > ld 9,.LC2@toc@l(9) > For this case, 'loading' is always slower than 'building' (>15%). Only if there is nothing else to do, and only in cases where code size does not matter (i.e. microbenchmarks). > --- /dev/null > +++ b/gcc/testsuite/gcc.target/powerpc/pr63281.c > @@ -0,0 +1,11 @@ > +/* PR target/63281 */ > +/* { dg-do compile { target lp64 } } */ > +/* { dg-options "-O2 -std=c99" } */ Why std=c99 btw? The default is c17. Is there something we need to disable here? Segher