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 B07493858C5F for ; Fri, 3 Feb 2023 16:23:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B07493858C5F 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=1675441412; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Po7TwOcTiOIKdgVtNKhnNNnoqIi/6Q8/dxoYmoKN0yA=; b=MavySEd+1yhSOjG/JdN9g3zGORc3XQAhBTOZ1QB07fMwzZ+6X/GYYaFmQl5ulm3R1JCyyE H1+XnXAx9ctJGm+dOJEf2Mu12Tlc/A+hR8IbsKLzIzWgFScVV5jmwdHrN1x1l3ZPZBCSpW SQtznDHBK6yU1xZDKlucTEhwfwz5mJM= Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-113-cN04FstXOKKV7LT2bj1Thg-1; Fri, 03 Feb 2023 11:23:31 -0500 X-MC-Unique: cN04FstXOKKV7LT2bj1Thg-1 Received: by mail-qk1-f198.google.com with SMTP id a198-20020ae9e8cf000000b007259083a3c8so3596514qkg.7 for ; Fri, 03 Feb 2023 08:23:30 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Po7TwOcTiOIKdgVtNKhnNNnoqIi/6Q8/dxoYmoKN0yA=; b=IDfOFcwZaQPlcBLXtF4QhnzqzbEdP0b04Zq64LYdg3MzRd0/uXL1ZPPS9ar2bGxwmj a+dVoBNrt2wA+usXkxzxPfjOrYxymxYGbXgoq4X4fjxFAoANuGeR5Gef2G1UhKJtU4g6 EVevbApMclO1pAmrCF4xxxwzxX3JaeXwpYGpQCaWJ+chWZ3m0CijoDoPKIjBX0aFT/a4 eeQJV4NWLfkOfbYM1bmBzKD0ji9t4LIpaKQy+Whlnw/cREHogWE5nQU/Bwjhhp7S/byi GlYJk8OFT5psOACnEqNYMfyvB8Qz/SXnWHskOjekgSkvqZTi5e485do8VXxaXgCQLL1C fzlg== X-Gm-Message-State: AO0yUKUVVwv5ZkZA6vpmubm0/Obo5tF8Xy+z/+TMCw/appZtl1dAz+JI 6vW8Y08XlDs5P+wNoUABCspMX5kFhY039aTja0H06Gaid1WLfrjM2sABP/TezcT7EM+zUKawzgb 5qsdq6Tyu9HnUfrm5tw== X-Received: by 2002:a05:622a:1489:b0:3b9:e1a2:6261 with SMTP id t9-20020a05622a148900b003b9e1a26261mr10359304qtx.36.1675441410466; Fri, 03 Feb 2023 08:23:30 -0800 (PST) X-Google-Smtp-Source: AK7set/hLh7vXXZlmj44bw5zpIuXiLzFV8OMDT3/NYM1eT8F/7e51LJI/qGb63ocPDjHwq4uMTVEpQ== X-Received: by 2002:a05:622a:1489:b0:3b9:e1a2:6261 with SMTP id t9-20020a05622a148900b003b9e1a26261mr10359264qtx.36.1675441410195; Fri, 03 Feb 2023 08:23:30 -0800 (PST) Received: from ?IPV6:2607:fea8:a263:f600::fa90? ([2607:fea8:a263:f600::fa90]) by smtp.gmail.com with ESMTPSA id j24-20020ac84058000000b003b635a5d56csm1844996qtl.30.2023.02.03.08.23.29 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 03 Feb 2023 08:23:29 -0800 (PST) Message-ID: <4fc527b8-c5e0-97a6-725f-8e86b7c1e494@redhat.com> Date: Fri, 3 Feb 2023 11:23:28 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.6.0 Subject: Re: [PATCH] [PR tree-optimization/18639] Compare nonzero bits in irange with widest_int. To: Jakub Jelinek , Aldy Hernandez Cc: GCC patches References: <20230203085043.157321-1-aldyh@redhat.com> From: Andrew MacLeod In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-6.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,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 2/3/23 04:16, Jakub Jelinek wrote: > 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. > if the bits match exactly along with everything else, then we can be sure the ranges are truly equal.  If for some reason the numbers are all the same but the non-zero bits don't compare equal,  then I can't think of what harm it could cause to compare unequal..  Worst case is we dont perform some optimization in this extremely rare scenario of differing precisions.  And in fact they could actually be unequal... So I suspect this is fine... Andrew