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 [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id D7E623857C6F for ; Thu, 8 Oct 2020 11:25:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org D7E623857C6F 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-247-RBxbAlPzMTCcTUGj735oEQ-1; Thu, 08 Oct 2020 07:25:40 -0400 X-MC-Unique: RBxbAlPzMTCcTUGj735oEQ-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 77CC084A5E0; Thu, 8 Oct 2020 11:25:39 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-112-37.ams2.redhat.com [10.36.112.37]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C89986EF5F; Thu, 8 Oct 2020 11:25:38 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id 098BPaS2018065; Thu, 8 Oct 2020 13:25:36 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id 098BPZC7018064; Thu, 8 Oct 2020 13:25:35 +0200 Date: Thu, 8 Oct 2020 13:25:35 +0200 From: Jakub Jelinek To: Wilco Dijkstra Cc: GCC Patches , "aldyh@redhat.com" Subject: Re: [PATCH] PR target/97312: Tweak gcc.target/aarch64/pr90838.c Message-ID: <20201008112535.GT2176@tucnak> Reply-To: Jakub Jelinek References: <20201008110912.GS2176@tucnak> MIME-Version: 1.0 In-Reply-To: User-Agent: Mutt/1.11.3 (2019-02-01) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-6.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, 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: Thu, 08 Oct 2020 11:25:44 -0000 On Thu, Oct 08, 2020 at 11:22:34AM +0000, Wilco Dijkstra wrote: > >> I think a better way forward would be to make the builtin_clz/ctz more defined. > >> Having undefined values is a source of unnecessary bugs given practically all > >> modern targets return the number of bits for the zero input - it is relatively > >> easy to ensure this on the few targets that don't. > > > > Well, e.g. i?86/x86_64 in most commonly used CPU flags is really undefined > > (the register is unchanged).  And -1 is also quite commonly used value, > > e.g. powerpc, gcn, xtensa. > > So wouldn't it be easy to initialize the register before you do the bsr to get > the same result as with BMI? I don't think an extra mov can affect performance > in actual code (and GCC could still optimize the zero case if the input range > doesn't include zero). > > -1 is more complex, if these targets don't want to add extra instructions to fix > it up, we could define the zero result either -1 or #bits depending on the target > (still better than completely undefined). Having it undefined allows optimizations, and has been that way for years. We just should make sure that we optimize code like x ? __builtin_c[lt]z (x) : 32; etc. properly (and I believe we do). Jakub