From patchwork Mon Jul 17 07:16:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 1808571 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=sicvRp2f; dkim-atps=neutral Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4R4D2C1WHBz20Ct for ; Mon, 17 Jul 2023 17:18:11 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9DAA33858296 for ; Mon, 17 Jul 2023 07:18:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9DAA33858296 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1689578288; bh=BLiVAIus14TolX5Wmapi34CT+euejsOQfrxBw7l8yqs=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=sicvRp2f4lvuRMMVC7djL47UM7AMUbKXVQtv4X33RbibVWTp7F9geJx+WEc5EJ4xB k5MOTT29utHR0alOLKRdSZ9pEsSVkuYdAuEf/L2c4X+YbzuLDP9akHlxTA4HzbjrkQ Cradp7Xx5nwCdAu2dPlBB/fxaGAgfEaA6Jod7Rp4= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 8CBC83858D1E for ; Mon, 17 Jul 2023 07:17:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8CBC83858D1E Received: from mimecast-mx02.redhat.com (66.187.233.73 [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-610-uGDvfMAYOmixs6VEAZwGvQ-1; Mon, 17 Jul 2023 03:17:45 -0400 X-MC-Unique: uGDvfMAYOmixs6VEAZwGvQ-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 71338380392D for ; Mon, 17 Jul 2023 07:17:45 +0000 (UTC) Received: from abulafia.quesejoda.com (unknown [10.39.193.153]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1BB5240C2063; Mon, 17 Jul 2023 07:17:44 +0000 (UTC) Received: from abulafia.quesejoda.com (localhost [127.0.0.1]) by abulafia.quesejoda.com (8.17.1/8.17.1) with ESMTPS id 36H7HgAj242463 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Mon, 17 Jul 2023 09:17:42 +0200 Received: (from aldyh@localhost) by abulafia.quesejoda.com (8.17.1/8.17.1/Submit) id 36H7HgO0242462; Mon, 17 Jul 2023 09:17:42 +0200 To: GCC patches Cc: Andrew MacLeod , Aldy Hernandez Subject: [COMMITTED] Normalize irange_bitmask before union/intersect. Date: Mon, 17 Jul 2023 09:16:02 +0200 Message-Id: <20230717071603.242424-1-aldyh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.7 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_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Aldy Hernandez via Gcc-patches From: Aldy Hernandez Reply-To: Aldy Hernandez Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" The bit twiddling in union/intersect for the value/mask pair must be normalized to have the unknown bits with a value of 0 in order to make the math simpler. Normalizing at construction slowed VRP by 1.5% so I opted to normalize before updating the bitmask in range-ops, since it was the only user. However, with upcoming changes there will be multiple setters of the mask (IPA and CCP), so we need something more general. I played with various alternatives, and settled on normalizing before union/intersect which were the ones needing the bits cleared. With this patch, there's no noticeable difference in performance either in VRP or in overall compilation. gcc/ChangeLog: * value-range.cc (irange_bitmask::verify_mask): Mask need not be normalized. * value-range.h (irange_bitmask::union_): Normalize beforehand. (irange_bitmask::intersect): Same. --- gcc/value-range.cc | 3 --- gcc/value-range.h | 12 ++++++++++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/gcc/value-range.cc b/gcc/value-range.cc index 011bdbdeae6..2abf57bcee8 100644 --- a/gcc/value-range.cc +++ b/gcc/value-range.cc @@ -1953,9 +1953,6 @@ void irange_bitmask::verify_mask () const { gcc_assert (m_value.get_precision () == m_mask.get_precision ()); - // Unknown bits must have their corresponding value bits cleared as - // it simplifies union and intersect. - gcc_assert (wi::bit_and (m_mask, m_value) == 0); } void diff --git a/gcc/value-range.h b/gcc/value-range.h index 0170188201b..d8af6fca7d7 100644 --- a/gcc/value-range.h +++ b/gcc/value-range.h @@ -211,8 +211,12 @@ irange_bitmask::operator== (const irange_bitmask &src) const } inline bool -irange_bitmask::union_ (const irange_bitmask &src) +irange_bitmask::union_ (const irange_bitmask &orig_src) { + // Normalize mask. + irange_bitmask src (orig_src.m_value & ~orig_src.m_mask, orig_src.m_mask); + m_value &= ~m_mask; + irange_bitmask save (*this); m_mask = (m_mask | src.m_mask) | (m_value ^ src.m_value); m_value = m_value & src.m_value; @@ -222,8 +226,12 @@ irange_bitmask::union_ (const irange_bitmask &src) } inline bool -irange_bitmask::intersect (const irange_bitmask &src) +irange_bitmask::intersect (const irange_bitmask &orig_src) { + // Normalize mask. + irange_bitmask src (orig_src.m_value & ~orig_src.m_mask, orig_src.m_mask); + m_value &= ~m_mask; + irange_bitmask save (*this); // If we have two known bits that are incompatible, the resulting // bit is undefined. It is unclear whether we should set the entire