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 BC024385841C for ; Fri, 18 Nov 2022 15:11:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org BC024385841C 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 2AIFAVNH016462; Fri, 18 Nov 2022 09:10:31 -0600 Received: (from segher@localhost) by gate.crashing.org (8.14.1/8.14.1/Submit) id 2AIFAUYJ016461; Fri, 18 Nov 2022 09:10:30 -0600 X-Authentication-Warning: gate.crashing.org: segher set sender to segher@kernel.crashing.org using -f Date: Fri, 18 Nov 2022 09:10:30 -0600 From: Segher Boessenkool To: "Kewen.Lin" Cc: GCC Patches , David Edelsohn , Peter Bergner , Michael Meissner Subject: Re: [PATCH 1/2] rs6000: Emit vector fp comparison directly in rs6000_emit_vector_compare Message-ID: <20221118151030.GA25951@gate.crashing.org> References: <20221116184437.GW25951@gate.crashing.org> <30553cb3-35d0-c51b-ffc4-0f8a320bd1ed@linux.ibm.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <30553cb3-35d0-c51b-ffc4-0f8a320bd1ed@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! On Thu, Nov 17, 2022 at 02:59:00PM +0800, Kewen.Lin wrote: > on 2022/11/17 02:44, Segher Boessenkool wrote: > > On Wed, Nov 16, 2022 at 02:48:25PM +0800, Kewen.Lin wrote: > >> * config/rs6000/rs6000.cc (rs6000_emit_vector_compare_inner): Remove > >> float only comparison operators. > > > > Why? Is that correct? Your mail says nothing about this :-( > > > > Is there any testcase that covers this, and that shows things still > > generate the same code? > > > > Sorry for the unclear description, I thought mistakenly that it's > probably straightforward. > > With the change in this patch, all 14 vector float comparison operators > (unordered/ordered/eq/ne/gt/lt/ge/le/ungt/unge/unlt/unle/uneq/ltgt) > would be handled early in rs6000_emit_vector_compare. > > For unordered/ordered/ltgt/uneq, the new way is exactly the same > as what we do in rs6000_emit_vector_compare_inner, it means there is > no chance to get into rs6000_emit_vector_compare_inner with any of them. Ah! In that case, please add an assert there. It helps catch problems, but much more importantly even, if helps the reader understand what is going on :-) > For eq/ge/gt, it's the same too, but they are shared with vector integer > comparison, I just left them alone here. Just noticed we can remove ge > safely too as it's guarded with !MODE_VECTOR_INT. ge is nasty for float, it means something different with and without -ffast-math (with fast-math ge means not lt, le means not gt; both can be done with a simple single condition, no cror needed. (Compare to ne which is the same with and without -ffast-math, that is because it has a "not" in its definition!) > For ne/ungt/unlt/unge/unle, rs6000_emit_vector_compare changes the code > with reverse_condition_maybe_unordered and invert the result, it's the > same as what we have in vector.md. > > ; unge(a,b) = ~lt(a,b) > ; unle(a,b) = ~gt(a,b) > ; ne(a,b) = ~eq(a,b) > ; ungt(a,b) = ~le(a,b) > ; unlt(a,b) = ~ge(a,b) But for these last two do we generate identical code still? Since forever we have only use cror here (with CCEQ), not crnor etc. (and will CCEQ still do the correct thing always then?) > Then eq/ge/gt on the right side would match the cases that were mentioned > above. So we just need to focus on lt and le then. > > For lt, rs6000_emit_vector_compare swaps operands and the operator to gt, > it's the same as what we have in vector.md: > > ; lt(a,b) = gt(b,a) > > , and further matches the case mentioned above. > > As to le, rs6000_emit_vector_compare tries to split it into lt IOR eq, > and further handle lt recursively, that is: > le = lt(a,b) || eq(a,b) > = gt(b,a) || eq(a,b) > > actually this is worse than what vector.md supports: > > ; le(a,b) = ge(b,a) > > In short, the function rs6000_emit_vector_compare_inner is only called by > twice in rs6000_emit_vector_compare, there is no chance to enter > rs6000_emit_vector_compare_inner with codes unordered/ordered/ltgt/uneq > any more, I think it's safe to make the change in function > rs6000_emit_vector_compare_inner. Besides, the proposed way to handle > vector float comparison can improve slightly for UNGT and LE handlings. Thanks for the explanation! Can you do this in multiple steps, which will make it much easier to review, and to spot the problem if some unexpected problem shows up? > I constructed a test case, compiled with option -O2 -ftree-vectorize > -fno-vect-cost-model on ppc64le, which goes into this function > rs6000_emit_vector_compare with all 14 vector float comparison codes, > the assembly of most functions doesn't change after this patch, > excepting for test_UNGT_{float,double} and test_LE_{float,double}. For, this is a separate change, a separate and the other patches will show no changes in generated code at all. > Maybe it's good to add one test case with function test_{UNGT,LE}_{float,double} > and scan not xvcmp{gt,eq}[sd]p. In the patch that changes code gen for those, sure :-) Segher