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 648A93858004 for ; Fri, 13 Jan 2023 21:55:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 648A93858004 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=1673646902; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=nwSuv3/CJX9tFgUyD+QmE2JinlOmygu/OMNVdLHNg3c=; b=Eo9mp4Qq3zWWKuLT46Jn2Qz+a0whZX7k/1LGtzw8HliHGvPaARBbXxu1PPwlPtdq9VOc5J la1if6+bCUA8xJwyi+sR0eimmXynypkS7DmKGsMmFixJckc8KemWiniM3mx2Lf4UYUseV2 bCVbBm8hSpNc/XwyEI0jOW5KT/QF6bA= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-299-HiH4YILzMhiBpbx2MK_Gyw-1; Fri, 13 Jan 2023 16:55:00 -0500 X-MC-Unique: HiH4YILzMhiBpbx2MK_Gyw-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 81559858F09 for ; Fri, 13 Jan 2023 21:55:00 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.223]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 375D51121314; Fri, 13 Jan 2023 21:55:00 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 30DLsvep1368972 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 13 Jan 2023 22:54:58 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 30DLsvGJ1368971; Fri, 13 Jan 2023 22:54:57 +0100 Date: Fri, 13 Jan 2023 22:54:56 +0100 From: Jakub Jelinek To: Andrew MacLeod Cc: gcc-patches , "hernandez, aldy" Subject: Re: [PATCH] PR tree-optimization/108359 - Utilize op1 == op2 when invoking range-ops folding. Message-ID: Reply-To: Jakub Jelinek References: <3815f4c2-7a8d-c662-54d8-eac1ab315fbb@redhat.com> MIME-Version: 1.0 In-Reply-To: <3815f4c2-7a8d-c662-54d8-eac1ab315fbb@redhat.com> X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 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=-3.5 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 Fri, Jan 13, 2023 at 04:23:20PM -0500, Andrew MacLeod via Gcc-patches wrote: > fold_range() already invokes wi_fold_in_parts to try to get more refined > information. If the subranges are quite small, it will do each individual > calculation and combine the results. > > x * y with x = [1,3] and y = [1,3]  is broken down and we calculate each > possibility and we end up with [1,4][6,6][9,9] instead of [1,9] > > We limit this as the time is between quadratic to exponential depending on > the number of elements in x and y. > > If we also check the relation and determine that x == y, we don't need to > worry about that growth as this process is linear.  The above case will be > broken down to just  1*1, 2*2 and 3*3, resulting in a range of [1, > 1][4,4][9,9]. > >  In the testcase, it happens to be the right_shift operation, but this > solution is generic and applies to all range-op operations. I added a > testcase which checks >>, *, + and %. > > I also arbitrarily chose 8 elements as the limit for breaking down > individual operations.  The overall compile time change for this is > negligible. > > Although this is a regression fix, it will affect all operations where x == > y, which is where my initial hesitancy arose. > > Regardless, bootstrapped on x86_64-pc-linux-gnu with no regressions.  OK for > trunk? Will defer to Aldy, just some nits. > + // if there are 1 to 8 values in the LH range, split them up. > + r.set_undefined (); > + if (lh_range >= 0 && lh_range <= 7) > + { > + unsigned x; > + for (x = 0; x <= lh_range; x++) Nothing uses x after the loop, so why not for (unsigned x = 0; x <= lh_range; x++) instead? > @@ -234,6 +264,26 @@ range_operator::fold_range (irange &r, tree type, > unsigned num_lh = lh.num_pairs (); > unsigned num_rh = rh.num_pairs (); > > + // If op1 and op2 are equivalences, then we don't need a complete cross > + // product, just pairs of matching elements. > + if (relation_equiv_p (rel) && (lh == rh)) The ()s around lh == rh look superfluous to me. > + { > + int_range_max tmp; > + r.set_undefined (); > + for (unsigned x = 0; x < num_lh; ++x) fold_range has an upper bound of num_lh * num_rh > 12, shouldn't something like that be there for this case too? I mean, every wi_fold_in_parts_equiv can result in 8 subranges, but num_lh could be up to 255 here, it is true it is linear and union_ should merge excess ones, but still I wonder if some larger num_lh upper bound like 20 or 32 wouldn't be useful. Up to you... > + { > + wide_int lh_lb = lh.lower_bound (x); > + wide_int lh_ub = lh.upper_bound (x); > + wi_fold_in_parts_equiv (tmp, type, lh_lb, lh_ub); > + r.union_ (tmp); > + if (r.varying_p ()) > + break; > + } > + op1_op2_relation_effect (r, type, lh, rh, rel); > + update_known_bitmask (r, m_code, lh, rh); > + return true; > + } > + Jakub