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 44AAE38388DB; Tue, 13 Dec 2022 21:03:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 44AAE38388DB 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 2BDL2XcS031187; Tue, 13 Dec 2022 15:02:33 -0600 Received: (from segher@localhost) by gate.crashing.org (8.14.1/8.14.1/Submit) id 2BDL2WUr031186; Tue, 13 Dec 2022 15:02:32 -0600 X-Authentication-Warning: gate.crashing.org: segher set sender to segher@kernel.crashing.org using -f Date: Tue, 13 Dec 2022 15:02:32 -0600 From: Segher Boessenkool To: Jiufu Guo Cc: gcc-patches@gcc.gnu.org, dje.gcc@gmail.com, linkw@gcc.gnu.org Subject: Re: [PATCH V6] rs6000: Optimize cmp on rotated 16bits constant Message-ID: <20221213210232.GM25951@gate.crashing.org> References: <20220829034216.94029-1-guojiufu@linux.ibm.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220829034216.94029-1-guojiufu@linux.ibm.com> User-Agent: Mutt/1.4.2.3i X-Spam-Status: No, score=-3.0 required=5.0 tests=BAYES_00,JMQ_SPF_NEUTRAL,KAM_DMARC_STATUS,SPF_HELO_PASS,SPF_PASS,TXREP autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Hi! Sorry for the tardiness. On Mon, Aug 29, 2022 at 11:42:16AM +0800, Jiufu Guo wrote: > When checking eq/ne with a constant which has only 16bits, it can be > optimized to check the rotated data. By this, the constant building > is optimized. > > As the example in PR103743: > For "in == 0x8000000000000000LL", this patch generates: > rotldi %r3,%r3,16 > cmpldi %cr0,%r3,32768 > instead: > li %r9,-1 > rldicr %r9,%r9,0,0 > cmpd %cr0,%r3,%r9 FWIW, I find the winnt assembler syntax very hard to read, and I doubt I am the only one. So you're doing rotldi 3,3,16 ; cmpldi 3,0x8000 instead of li 9,-1 ; rldicr 9,9,0,0 ; cmpd 3,9 > +/* Check if C can be rotated from an immediate which starts (as 64bit integer) > + with at least CLZ bits zero. > + > + Return the number by which C can be rotated from the immediate. > + Return -1 if C can not be rotated as from. */ > + > +int > +rotate_from_leading_zeros_const (unsigned HOST_WIDE_INT c, int clz) The name does not say what the function does. Can you think of a better name? Maybe it is better to not return magic values anyway? So perhaps bool can_be_done_as_compare_of_rotate (unsigned HOST_WIDE_INT c, int clz, int *rot) (with *rot written if the return value is true). > + /* case c. xx10.....0xx: rotate 'clz + 1' bits firstly, then check case b. s/firstly/first/ > +/* Check if C can be rotated from an immediate operand of cmpdi or cmpldi. */ > + > +bool > +compare_rotate_immediate_p (unsigned HOST_WIDE_INT c) No _p please, this function is not a predicate (at least, the name does not say what it tests). So a better name please. This matters even more for extern functions (like this one) because the function implementation is always farther away so you do not easily have all interface details in mind. Good names help :-) > +(define_code_iterator eqne [eq ne]) > +(define_code_attr EQNE [(eq "EQ") (ne "NE")]) Just or should work? Please fix these things. Almost there :-) Segher