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.129.124]) by sourceware.org (Postfix) with ESMTPS id 7037638582A6 for ; Tue, 8 Nov 2022 14:19:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 7037638582A6 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=1667917163; 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=rDboeHKocrtBZi5U0s9FP/ILfmglPFdvsmKE/Nofr6Y=; b=hme4wETfA26OihI9ncgCVG3htUqU0tGSyZy/8V2QPcqnGK12Y9cRSw7isQenmcRdUOrtTk dI2D9pP+iZBRXPg9F5PFy+HuvjmDIVvJ9ZTYUs0fhrCLcBnOHyU/h14qj0yMKC8zh8NDSW mpW/0QT1xrQabuhd2HQcusUWGbxdyoI= Received: from mail-yb1-f197.google.com (mail-yb1-f197.google.com [209.85.219.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-139-CpWwsAoRNVWpjVFl57nyzQ-1; Tue, 08 Nov 2022 09:19:21 -0500 X-MC-Unique: CpWwsAoRNVWpjVFl57nyzQ-1 Received: by mail-yb1-f197.google.com with SMTP id m4-20020a258004000000b006cbf32f7ed8so14045480ybk.9 for ; Tue, 08 Nov 2022 06:19:21 -0800 (PST) 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=rDboeHKocrtBZi5U0s9FP/ILfmglPFdvsmKE/Nofr6Y=; b=X3VjXWvQeQv8qJAjQyl51SNmQV5uN4jeHdpZf/a3KGkWxGUCBZMKIjhpsiJ75Auo6n G2BUhuoyOPkHMH+dQe6rW0j1qAr+95ggzb3FLqwJR1KXDZoq9c2yxUCs9n+H1hZuGgFf a/+SHQQ5QIzrefxn152iWf//0/7qLaRI3PUV8ISey2ekotB2VudasG29BzKRiF5O8wfK oGINRmkFPWxj/tXPUII98ZYopMrxFsVTS5GmZG0sfmzyy5jO7HCJ2FgQHtLdkD69z1Ix Hx3vhBaOv8Ogss04axh9Y9NiWvpZUPhn105DY8bmJo+rMp0Q40ff0T2UoyjEiwA7G4AH 01+g== X-Gm-Message-State: ACrzQf34icrlMXnE0+jhZpWm+fuJ11isJn2WKV7443R0w5rJ3nimc99t SUO0wg5+V/yDNqfwe+KqMEEza5bW/21AaSeRh4hgcJ9wDdt7rGcCCUULCXc1V3B0f+f0CURsd+J J/0+9f9tkL+TrCeXAyRIQrFzY3DvLI2Iv4g== X-Received: by 2002:a81:1086:0:b0:36f:ce5a:982 with SMTP id 128-20020a811086000000b0036fce5a0982mr54390184ywq.158.1667917160759; Tue, 08 Nov 2022 06:19:20 -0800 (PST) X-Google-Smtp-Source: AMsMyM4CL0dvP+pQVQaEQESmpeRTF9r5ZfeycBN8n54B5ZTkGJQIBch8trwuhwvh8lXigCAeHw8u3qt3KEiK5jOyctE= X-Received: by 2002:a81:1086:0:b0:36f:ce5a:982 with SMTP id 128-20020a811086000000b0036fce5a0982mr54390160ywq.158.1667917160492; Tue, 08 Nov 2022 06:19:20 -0800 (PST) MIME-Version: 1.0 References: <20221106161420.522485-1-aldyh@redhat.com> In-Reply-To: <20221106161420.522485-1-aldyh@redhat.com> From: Aldy Hernandez Date: Tue, 8 Nov 2022 15:19:09 +0100 Message-ID: Subject: Re: [PATCH] Use bit-CCP in range-ops. To: GCC patches Cc: Richard Biener , Jakub Jelinek , Andrew MacLeod X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-11.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,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: Pushed. I'd still love to hear feedback though ;-). Aldy On Sun, Nov 6, 2022 at 5:14 PM Aldy Hernandez wrote: > > After Jakub and Richi's suggestion of using the same representation > for tracking known bits as we do in CCP, I took a peek at the code and > realized there's a plethora of bit-tracking code there that we could > be sharing with range-ops. For example, the multiplication > optimizations are way better than what I had cobbled together. For > that matter, our maybe nonzero tracking as a whole has a lot of room > for improvement. Being the lazy ass that I am, I think we should just > use one code base (CCP's). > > This patch provides a thin wrapper for converting the irange maybe > nonzero bits to what CCP requires, and uses that to call into > bit_value_binop(). I have so far converted the MULT_EXPR range-op > entry to use it, as the DIV_EXPR entry we have gets a case CCP doesn't > get so I'd like to contribute the enhancement to CCP before converting > over. > > I'd like to use this approach with the dozen or so tree_code's that > are handled in CCP, thus saving us from having to implement any of > them :). > > Early next season I'd like to change irange's internal representation > to a pair of value / mask, and start tracking all known bits. This > ties in nicely with our plan for tracking known set bits. > > Perhaps if the stars align, we could merge the bit twiddling in CCP > into range-ops and have a central repository for it. That is, once we > make the switch to wide-ints, and assuming there are no performance > issues. Note that range-ops is our lowest level abstraction. > i.e. it's just the math, there's no GORI or ranger, or even the > concept of a symbolic or SSA. > > I'd love to hear comments and ideas, and if no one objects push this. > Please let me know if I missed anything. > > Tested on x86-64 Linux. > > gcc/ChangeLog: > > * range-op.cc (irange_to_masked_value): New. > (update_known_bitmask): New. > (operator_mult::fold_range): Call update_known_bitmask. > --- > gcc/range-op.cc | 63 +++++++++++++++++++++++++++++++++++++++---------- > 1 file changed, 50 insertions(+), 13 deletions(-) > > diff --git a/gcc/range-op.cc b/gcc/range-op.cc > index 25c004d8287..6d9914d8d12 100644 > --- a/gcc/range-op.cc > +++ b/gcc/range-op.cc > @@ -46,6 +46,54 @@ along with GCC; see the file COPYING3. If not see > #include "wide-int.h" > #include "value-relation.h" > #include "range-op.h" > +#include "tree-ssa-ccp.h" > + > +// Convert irange bitmasks into a VALUE MASK pair suitable for calling CCP. > + > +static void > +irange_to_masked_value (const irange &r, widest_int &value, widest_int &mask) > +{ > + if (r.singleton_p ()) > + { > + mask = 0; > + value = widest_int::from (r.lower_bound (), TYPE_SIGN (r.type ())); > + } > + else > + { > + mask = widest_int::from (r.get_nonzero_bits (), TYPE_SIGN (r.type ())); > + value = 0; > + } > +} > + > +// Update the known bitmasks in R when applying the operation CODE to > +// LH and RH. > + > +static void > +update_known_bitmask (irange &r, tree_code code, > + const irange &lh, const irange &rh) > +{ > + if (r.undefined_p ()) > + return; > + > + widest_int value, mask, lh_mask, rh_mask, lh_value, rh_value; > + tree type = r.type (); > + signop sign = TYPE_SIGN (type); > + int prec = TYPE_PRECISION (type); > + signop lh_sign = TYPE_SIGN (lh.type ()); > + signop rh_sign = TYPE_SIGN (rh.type ()); > + int lh_prec = TYPE_PRECISION (lh.type ()); > + int rh_prec = TYPE_PRECISION (rh.type ()); > + > + irange_to_masked_value (lh, lh_value, lh_mask); > + irange_to_masked_value (rh, rh_value, rh_mask); > + bit_value_binop (code, sign, prec, &value, &mask, > + lh_sign, lh_prec, lh_value, lh_mask, > + rh_sign, rh_prec, rh_value, rh_mask); > + > + int_range<2> tmp (type); > + tmp.set_nonzero_bits (value | mask); > + r.intersect (tmp); > +} > > // Return the upper limit for a type. > > @@ -1774,21 +1822,10 @@ operator_mult::fold_range (irange &r, tree type, > if (!cross_product_operator::fold_range (r, type, lh, rh, trio)) > return false; > > - if (lh.undefined_p ()) > + if (lh.undefined_p () || rh.undefined_p ()) > return true; > > - tree t; > - if (rh.singleton_p (&t)) > - { > - wide_int w = wi::to_wide (t); > - int shift = wi::exact_log2 (w); > - if (shift != -1) > - { > - wide_int nz = lh.get_nonzero_bits (); > - nz = wi::lshift (nz, shift); > - r.set_nonzero_bits (nz); > - } > - } > + update_known_bitmask (r, MULT_EXPR, lh, rh); > return true; > } > > -- > 2.38.1 >