From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id 7DC16385482F for ; Tue, 4 May 2021 09:42:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 7DC16385482F Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-464-EZBU0X66OeC4bIawTsd6Qg-1; Tue, 04 May 2021 05:42:14 -0400 X-MC-Unique: EZBU0X66OeC4bIawTsd6Qg-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B3E3A107ACC7; Tue, 4 May 2021 09:42:13 +0000 (UTC) Received: from localhost (unknown [10.33.36.164]) by smtp.corp.redhat.com (Postfix) with ESMTP id 53BCC5D735; Tue, 4 May 2021 09:42:13 +0000 (UTC) Date: Tue, 4 May 2021 10:42:12 +0100 From: Jonathan Wakely To: Jakub Jelinek Cc: Richard Biener , Jason Merrill , gcc-patches@gcc.gnu.org Subject: Re: [PATCH] phiopt: Optimize (x <=> y) cmp z [PR94589] Message-ID: <20210504094212.GH3008@redhat.com> References: <20210504074413.GI1179226@tucnak> MIME-Version: 1.0 In-Reply-To: <20210504074413.GI1179226@tucnak> X-Clacks-Overhead: GNU Terry Pratchett X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline X-Spam-Status: No, score=-8.3 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: Tue, 04 May 2021 09:42:17 -0000 On 04/05/21 09:44 +0200, Jakub Jelinek wrote: >Hi! > >genericize_spaceship genericizes i <=> j to approximately >({ int c; if (i == j) c = 0; else if (i < j) c = -1; else c = 1; c; }) >for strong ordering and >({ int c; if (i == j) c = 0; else if (i < j) c = -1; else if (i > j) c = 1; else c = 2; c; }) >for partial ordering. >The C++ standard supports then == or != comparisons of that against >strong/partial ordering enums, or />= comparisons of <=> result >against literal 0. > >In some cases we already optimize that but in many cases we keep performing >all the 2 or 3 comparisons, compute the spaceship value and then compare >that. > >The following patch recognizes those patterns if the <=> operands are >integral types or floating point (the latter only for -ffast-math) and >optimizes it to the single comparison that is needed (plus adds debug stmts >if needed for the spaceship result). > >Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? > >There are two things I'd like to address in a follow-up: >1) if (HONOR_NANS (TREE_TYPE (lhs1)) || HONOR_SIGNED_ZEROS (TREE_TYPE (lhs1))) >is what I've copied from elsewhere in phiopt, but thinking about it, >alll we care is probably only HONOR_NANS, the matched pattern starts with >== or != comparison and branches to the PHI bb with -1/0/1/2 result if it is >equal, which should be the case for signed zero differences. >2) the pr94589-2.C testcase should be matching just 12 times each, but runs >into operator>=(strong_ordering, unspecified) being defined as Should this say s/strong/partial/ ?