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 0CCAF3858426 for ; Fri, 3 Feb 2023 09:16:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0CCAF3858426 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=1675415768; 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=gw18ABCgfVrO+4m5OCpxIOkTGmfPVnbvZ4iIRJ6deC0=; b=Zpf3IJZMPSvQ4sGpwum//TFFXLTDTMJ1+j8hFm987YeiLWDC5MsLfuKZFPH4ZdHtoHdUfG 7eBYbjtByT0+kvDGJ2YF+HfxeZuXNgPHyeDSMaQzl9lwIAo/VXPQJOWSXHBAYAoP3FIOnm 04LRuocqcs/HLHw2+FMJ/+yBam8uMQg= 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-618-O3J5vo8tPVizBY9Ox5eWlw-1; Fri, 03 Feb 2023 04:16:04 -0500 X-MC-Unique: O3J5vo8tPVizBY9Ox5eWlw-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 9CDC11C04320 for ; Fri, 3 Feb 2023 09:16:04 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.223]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5D0D1404CD80; Fri, 3 Feb 2023 09:16:04 +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 3139G1Iw3476212 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 3 Feb 2023 10:16:02 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 3139G1jT3476211; Fri, 3 Feb 2023 10:16:01 +0100 Date: Fri, 3 Feb 2023 10:16:01 +0100 From: Jakub Jelinek To: Aldy Hernandez Cc: Andrew MacLeod , GCC patches Subject: Re: [PATCH] [PR tree-optimization/18639] Compare nonzero bits in irange with widest_int. Message-ID: Reply-To: Jakub Jelinek References: <20230203085043.157321-1-aldyh@redhat.com> MIME-Version: 1.0 In-Reply-To: <20230203085043.157321-1-aldyh@redhat.com> 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 Fri, Feb 03, 2023 at 09:50:43AM +0100, Aldy Hernandez wrote: > [PR tree-optimization/18639] Compare nonzero bits in irange with widest_int. 0 missing in the bug number in the subject line, though the current recommended formatting of the subject is I think: value-range: Compare nonzero bits in irange with widest_int [PR180639] PR 108639/tree-optimization Reversed component and number > --- a/gcc/value-range.cc > +++ b/gcc/value-range.cc > @@ -1259,7 +1259,10 @@ irange::legacy_equal_p (const irange &other) const > other.tree_lower_bound (0)) > && vrp_operand_equal_p (tree_upper_bound (0), > other.tree_upper_bound (0)) > - && get_nonzero_bits () == other.get_nonzero_bits ()); > + && (widest_int::from (get_nonzero_bits (), > + TYPE_SIGN (type ())) > + == widest_int::from (other.get_nonzero_bits (), > + TYPE_SIGN (other.type ())))); > } > > bool > @@ -1294,7 +1297,11 @@ irange::operator== (const irange &other) const > || !operand_equal_p (ub, ub_other, 0)) > return false; > } > - return get_nonzero_bits () == other.get_nonzero_bits (); > + widest_int nz1 = widest_int::from (get_nonzero_bits (), > + TYPE_SIGN (type ())); > + widest_int nz2 = widest_int::from (other.get_nonzero_bits (), > + TYPE_SIGN (other.type ())); > + return nz1 == nz2; > } While the above avoids the ICE (and would be certainly correct for the bounds, depending on the sign of their type sign or zero extended to widest int), but is the above what we want for non-zero bits to be considered equal? The wide_ints (which ought to have precision of the corresponding type) don't represent normal numbers but bitmasks, 0 - this bit is known to be zero, 1 - nothing is known about this bit). So, if there are different precisions and the narrower value has 0 in the MSB of the bitmask (so MSB is known to be zero), the above requires for equality that in the other range all upper bits are known to be zero too for both signed and unsigned. That is ok. Similarly for MSB set if TYPE_SIGN of the narrower is unsigned, the MSB value is unknown, but we require on the wider to have all the upper bits cleared. But for signed narrower type with MSB set, i.e. it is unknown if it is positive or negative, the above requires that all the above bits are unknown too. And that is the case I'm not sure about, whether in that case the upper bits of the wider wide_int should be checked at all. Though, perhaps from the POV of nonzero bits derived from the sign-extended values in the ranges sign bit copies (so all above bits 1) is what one would get, so maybe it is ok. Just food for thought. As for retesting, if you have done full bootstrap/regtest with the patch without the testcases in it, it should be more than enough to test just make check-gcc \ RUNTESTFLAGS='--target_board=unix\{-m32,-m64\} compile.exp=pr10863*.c' You don't really need to rerun all tests just for it. Jakub