From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 8DB2A385781F; Fri, 17 Feb 2023 13:03:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8DB2A385781F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1676639028; bh=bTCSsCA3JsgmcdDSpgKnxdVNwz7io6Xv91F7RTIa3JI=; h=From:To:Subject:Date:In-Reply-To:References:From; b=LFVh64EPzaLtI+IR2D2n3hOZeRnCFichL0b8wm9kSpdIYux5AZMY9xyXtRg0jSM4K XU+jLFZLrLuGSwAu97GkO4UCyLjoaJvqyBChHIH1v94oKXy65tAJvR7KOWAppPM6QF JUAPSCaULLYwRosL6BMuHo88hlxesmM1xiXzCKfo= From: "jakub at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/90838] Detect table-based ctz implementation Date: Fri, 17 Feb 2023 13:03:48 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 9.0 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: jakub at gcc dot gnu.org X-Bugzilla-Status: RESOLVED X-Bugzilla-Resolution: FIXED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: wilco at gcc dot gnu.org X-Bugzilla-Target-Milestone: 10.0 X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D90838 --- Comment #16 from Jakub Jelinek --- (In reply to Wilco from comment #15) > It would make more sense to move x86 backends to CTZ_DEFINED_VALUE_AT_ZERO > =3D=3D 2 so that you always get the same result even when you don't have = tzcnt. > A conditional move would be possible, so it adds an extra 2 instructions = at > worst (ie. still significantly faster than doing the table lookup, multip= ly > etc). And it could be optimized when you know CLZ/CTZ input is non-zero. Conditional moves are a lottery on x86, in many cases very bad idea. And w= hen people actually use __builtin_clz*, they state that they don't care about t= he 0 value, so emitting terribly performing code for it just in case would be wr= ong. If forwprop emits the conditional in separate blocks for the CTZ_DVAZ!=3D2 = case, on targets where conditional moves are beneficial for it it can also emit t= hem, or emit the jump which say on x86 will be most likely faster than cmov.=