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 E99053858D32 for ; Mon, 16 Jan 2023 08:32:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E99053858D32 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=1673857953; 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:in-reply-to:in-reply-to: references:references; bh=MIYMMtn9v/iVQxlBsg3xuYK+y+2WrFppi3EWn5jaNG4=; b=gkZY/IwP+YB4pLsIxg3szmP9ZoFmiaLnaznTXQHAupiy0znihE/ncAtKQpn5bu/I9K5FQM nf4w2JUDX92PcyJgz9aEUtdX0hk4pXaans5odW5HQnvqfIrIIu6ilebirVRWtT+rkRB+io Pz5scp9g3O2wxPPDbNxmOZYWkXVJs3I= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-573-nf2ZEjV7Nvml0wjyQqoTUw-1; Mon, 16 Jan 2023 03:32:30 -0500 X-MC-Unique: nf2ZEjV7Nvml0wjyQqoTUw-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 03A903C10EC0; Mon, 16 Jan 2023 08:32:30 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.223]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B1F524010D46; Mon, 16 Jan 2023 08:32:29 +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 30G8WQSf3487750 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Mon, 16 Jan 2023 09:32:27 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 30G8WQaN3487749; Mon, 16 Jan 2023 09:32:26 +0100 Date: Mon, 16 Jan 2023 09:32:25 +0100 From: Jakub Jelinek To: Richard Biener Cc: Andrew MacLeod , 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> <110a8f5a-665d-9e36-d980-b4bec4e819c7@redhat.com> MIME-Version: 1.0 In-Reply-To: X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-3.8 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 Mon, Jan 16, 2023 at 08:19:25AM +0100, Richard Biener wrote: > + // 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 && num_lh <= 16) > + { > + int_range_max tmp; > + r.set_undefined (); > + for (unsigned x = 0; x < num_lh; ++x) > + { > + 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); > > and that does > > + widest_int lh_range = wi::sub (widest_int::from (lh_ub, TYPE_SIGN (type)), > + widest_int::from (lh_lb, TYPE_SIGN (type))); > + // if there are 1 to 8 values in the LH range, split them up. > + r.set_undefined (); > + if (lh_range >= 0 && lh_range <= 7) > + { > + for (unsigned x = 0; x <= lh_range; x++) > > which in total limits the number of sub-ranges in the output but in an > odd way. It's also all-or-nothing. IIRC there's a hard limit on the > number of sub-ranges in the output anyway via int_range, so > why not use that and always do the first loop over the sub-ranges > of the inputs and the second loop over the range members but > stop when we reach N-1 and then use wi_fold on the remainds? > > Your above code suggests we go up to 112 sub-ranges and once > we'd reach 113 we'd fold down to a single. > > Maybe my "heuristic" wouldn't be much better, but then somehow > breaking the heuristic down to a single magic number would be > better, esp. since .union_ will undo some of the breakup when > reaching N? The <= X in the first case is what I've suggested, the previous behavior didn't suffer from this all or nothing case, but I was worried because the behavior is that we create many subranges and then in the end just merge the last ones into a single subrange such that it fits into the limit. So we could create 255 * 8 subranges and then merge the last 255 * 7 + 1 into one. We could call that wi_fold_in_parts_equiv only if r.num_parts () < m_max_ranges and wi_fold otherwise... Jakub