From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by sourceware.org (Postfix) with ESMTPS id E36AA3858287 for ; Sat, 5 Nov 2022 14:23:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E36AA3858287 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 1D3FC219DA; Sat, 5 Nov 2022 14:23:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1667658199; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=ARR0zlkPOh5Pw/UweEpz359Ra8eYTobHwsXuVkuKRVY=; b=Rbdp666cTyWasXugyitQPYejMPEDOqyupRg0ONva14X5eS43VyCZkqQePMyX8M/P6ft/oW Yt+peT5deRJseCx1WfPdVPMvq+TMrGMVIotVy7MDYbS6cTKMEs1qDlmKx6E3g99zCaXsdP sxEbhXz0q10YTJ+UFZOuq7sgdPCMd4Q= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1667658199; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=ARR0zlkPOh5Pw/UweEpz359Ra8eYTobHwsXuVkuKRVY=; b=dHaBn3l4EAyUv+g9ICWkSEjhHI/XQEkzel4pS6wKQIE3Xfl9yLW5Tm8vMSAKzLzt6YdUOO kVZ7VoA6C0ek3GBQ== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id E437F13AA6; Sat, 5 Nov 2022 14:23:18 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id KzVLNtZxZmNLNAAAMHmgww (envelope-from ); Sat, 05 Nov 2022 14:23:18 +0000 Date: Sat, 5 Nov 2022 15:23:18 +0100 (CET) From: Richard Biener To: Aldy Hernandez cc: Tamar Christina , Jeff Law , "gcc-patches@gcc.gnu.org" , nd , "MacLeod, Andrew" Subject: Re: [PATCH 1/2]middle-end: Add new tbranch optab to add support for bit-test-and-branch operations In-Reply-To: Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-5.8 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Wed, 2 Nov 2022, Aldy Hernandez wrote: > On Wed, Nov 2, 2022 at 10:55 AM Tamar Christina wrote: > > > > Hi Aldy, > > > > I'm trying to use Ranger to determine if a range of an expression is a single bit. > > > > If possible in case of a mask then also the position of the bit that's being checked by the mask (or the mask itself). > > Just instantiate a ranger, and ask for the range of an SSA name (or an > arbitrary tree expression) at a particular gimple statement (or an > edge): > > gimple_ranger ranger; > int_range_max r; > if (ranger.range_of_expr (r, , )) { > // do stuff with range "r" > if (r.singleton_p ()) { > wide_int num = r.lower_bound (); > // Check the bits in NUM, etc... > } > } > > You can see the full ranger API in gimple-range.h. > > Note that instantiating a new ranger is relatively lightweight, but > it's not free. So unless you're calling range_of_expr sporadically, > you probably want to have one instance for your pass. You can pass > around the gimple_ranger around your pass. Another way of doing this > is calling enable_rager() at pass start, and then doing: > > get_range_query (cfun)->range_of_expr (r, , )); > > gimple-loop-versioning.cc has an example of using enable_ranger / > disable_ranger. > > I am assuming you are interested in ranges for integers / pointers. > Otherwise (floats, etc) you'd have to use "Value_Range" instead of > int_range_max. I can give you examples on that if necessary. > > Let me know if that helps. I think you maybe just want get_nonzero_bits? > Aldy > > > > > Do you have any pointers/existing code I can look at to do this? > > > > Kind regards, > > Tamar > > > > > -----Original Message----- > > > From: Jeff Law > > > Sent: Tuesday, November 1, 2022 5:00 PM > > > To: Tamar Christina ; gcc-patches@gcc.gnu.org > > > Cc: nd ; rguenther@suse.de > > > Subject: Re: [PATCH 1/2]middle-end: Add new tbranch optab to add support > > > for bit-test-and-branch operations > > > > > > > > > On 11/1/22 09:53, Tamar Christina wrote: > > > >> > > > >>> from the machine description. > > > >>> > > > >>> +@cindex @code{tbranch@var{mode}4} instruction pattern @item > > > >>> +@samp{tbranch@var{mode}4} Conditional branch instruction > > > combined > > > >>> +with a bit test-and-compare instruction. Operand 0 is a comparison > > > >>> +operator. Operand 1 is the operand of the comparison. Operand 2 is > > > >>> +the bit position of Operand 1 to test. > > > >>> +Operand 3 is the @code{code_label} to jump to. > > > >> Should we refine/document the set of comparison operators allowed? > > > >> Is operand 1 an arbitrary RTL expression or more limited? I'm > > > >> guessing its relatively arbitrary given how you've massaged the > > > >> existing branch-on-bit patterns from the aarch backend. > > > > It can be any expression in theory. However in practical terms we > > > > usually force the values to registers before calling the expansion. > > > > My assumption is that this is for CSE purposes but that's only a guess. > > > > > > Understood. And generally yes, forcing expressions into regs is good for CSE. > > > > > > > > > > > > > >> Do we have enough information lying around from Ranger to avoid the > > > need > > > >> to walk the def-use chain to discover that we're masking off all but one > > > bit? > > > >> > > > > That's an interesting thought. I'll try to see if I can figure out how to query > > > > Ranger here. It would be nice to do so here. > > > > > > Reach out to Aldy, I suspect he can probably give you the necessary > > > pseudocode pretty quickly. > > > > > > > > > Jeff > > > > > > > -- Richard Biener SUSE Software Solutions Germany GmbH, Frankenstrasse 146, 90461 Nuernberg, Germany; GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman; HRB 36809 (AG Nuernberg)