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 ESMTPS id 777923858C55 for ; Wed, 2 Nov 2022 11:09:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 777923858C55 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1667387349; h=from:from:reply-to:subject:subject: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=HaJgSkuBX08wusfKuK6iMc8nLDUAnIUsm5th9Lzc36g=; b=ZH8vmVJdgHVafuSuW4lpAFsIgiQnMj0ZJJeVJXowgwxsTalgkpXinscgjnX9d6Rq0PX7lv Q3S4AfHo0eHBSSExDgou2m3bi1ob3ipoZ5yx/hr2cxR5gUcG0qs9R6sVCOuRID2fvWOCKA foJuDyfo+2W1cXEb+0oCw9cupLlkDOw= Received: from mail-yw1-f199.google.com (mail-yw1-f199.google.com [209.85.128.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-592-jSckzz9aMf-qWsmN-qGe6Q-1; Wed, 02 Nov 2022 07:09:08 -0400 X-MC-Unique: jSckzz9aMf-qWsmN-qGe6Q-1 Received: by mail-yw1-f199.google.com with SMTP id 00721157ae682-36bf9c132f9so155778407b3.8 for ; Wed, 02 Nov 2022 04:09:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=HaJgSkuBX08wusfKuK6iMc8nLDUAnIUsm5th9Lzc36g=; b=VecIVHPhmbg0pkehBSq7aK5Jz8dne2PDlUASU6rv6GY9NGY5GmAEZ8+QdfN4/hJXF4 9Mo3CmQPBh/Msf3k0IeOcmvdEIySt/7Ijh8SQauUzRHK7756HavaedlDPUj2W8ZneQrc VLetgajEUKKn4C8wt39T2n5UyVpASyBgqvCPxl+3JJhBpwUDgbNKFm/gXeYgsHl6z9oZ Ev22Cu4so0Wb6Jo0A+iWc7Bdxj7R9Zc4wlTES1oRtqbcA5uv4KL34KUJkyWvvn/qoK5c ngWY18+19MApoN8m1AxlcyIjbFLc/UIuVjqMxtM/C3sI4Oh1qUanjSBZXLCyDtAESm3U Xklw== X-Gm-Message-State: ACrzQf3ewjfVO0tMgPqwjD2oQrwi/HGmim7MBHtcdSjpmvn8Q4GPelaB iWjImj1GcAe47MyRY3rqSxnbJJ6Re8GdRjcrX17JWfzbRleYE20t/IJ8BxuOfgYmfPCfth1qZz8 TvPc9+yGy5qlK3NXo2kbY3rFnX+bV0MndDA== X-Received: by 2002:a81:1c49:0:b0:368:8355:3e98 with SMTP id c70-20020a811c49000000b0036883553e98mr23419646ywc.154.1667387347505; Wed, 02 Nov 2022 04:09:07 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7FLtyYwdne2cMiao4ZCa7vmIKczUkz+OA8tQmnvjhbdSTfSGF++9KC7/ksZpa3poHKXXOxFKBOwBJeZk1Orf4= X-Received: by 2002:a81:1c49:0:b0:368:8355:3e98 with SMTP id c70-20020a811c49000000b0036883553e98mr23419617ywc.154.1667387347249; Wed, 02 Nov 2022 04:09:07 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Aldy Hernandez Date: Wed, 2 Nov 2022 12:08:56 +0100 Message-ID: Subject: Re: [PATCH 1/2]middle-end: Add new tbranch optab to add support for bit-test-and-branch operations To: Tamar Christina Cc: Jeff Law , "gcc-patches@gcc.gnu.org" , nd , "rguenther@suse.de" , "MacLeod, Andrew" X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-6.1 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_H2,SPF_HELO_NONE,SPF_NONE,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, 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. 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 > > >