From patchwork Wed Jul 12 16:21:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 1806884 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=2620:52:3:1:0:246e:9693:128c; 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=bIlimRgl; dkim-atps=neutral Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (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 4R1NKY6Q26z20Ph for ; Thu, 13 Jul 2023 02:21:37 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E670F38582BE for ; Wed, 12 Jul 2023 16:21:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E670F38582BE DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1689178895; bh=1WwN6Kqkt9PTSvUC7C2Ptauzkxb9wMMgB1HulgcMJME=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=bIlimRgluo23ol6AzWNZvhNw6MzjEIFIgIyp8/FFnaswZXUdBoLUhfiv6GECZdOVI 8lRIYi4vkL/kkavVDsAX9rCyzIpfnOviw3f7otJJqly9r1I+fbqmoD+3yFP3+UsNm8 I5nnh4EAw48dXloFLwWmCP53KjbHbun2vdk30ba8= 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 024BE3858C62 for ; Wed, 12 Jul 2023 16:21:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 024BE3858C62 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-98-mrYToE7tP8CMf6_TGzOssg-1; Wed, 12 Jul 2023 12:21:13 -0400 X-MC-Unique: mrYToE7tP8CMf6_TGzOssg-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 59A3B280AA4E for ; Wed, 12 Jul 2023 16:21:13 +0000 (UTC) Received: from abulafia.lan (unknown [10.39.192.68]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EFDFB200B402; Wed, 12 Jul 2023 16:21:12 +0000 (UTC) Received: from abulafia.lan (localhost [127.0.0.1]) by abulafia.lan (8.17.1/8.17.1) with ESMTPS id 36CGLADI050243 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 12 Jul 2023 18:21:10 +0200 Received: (from aldyh@localhost) by abulafia.lan (8.17.1/8.17.1/Submit) id 36CGLA9U050242; Wed, 12 Jul 2023 18:21:10 +0200 To: GCC patches Cc: Andrew MacLeod , Aldy Hernandez Subject: [COMMITTED] [range-op] Enable value/mask propagation in range-op. Date: Wed, 12 Jul 2023 18:21:08 +0200 Message-Id: <20230712162108.50227-1-aldyh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 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" Throw the switch in range-ops to make full use of the value/mask information instead of only the nonzero bits. This will cause most of the operators implemented in range-ops to use the value/mask information calculated by CCP's bit_value_binop() function which range-ops uses. This opens up more optimization opportunities. In follow-up patches I will change the global range setter (set_range_info) to be able to save the value/mask pair, and make both CCP and IPA be able to save the known ones bit info, instead of throwing it away. gcc/ChangeLog: * range-op.cc (irange_to_masked_value): Remove. (update_known_bitmask): Update irange value/mask pair instead of only updating nonzero bits. gcc/testsuite/ChangeLog: * gcc.dg/pr83073.c: Adjust testcase. --- gcc/range-op.cc | 53 ++++++++++++++-------------------- gcc/testsuite/gcc.dg/pr83073.c | 2 +- 2 files changed, 23 insertions(+), 32 deletions(-) diff --git a/gcc/range-op.cc b/gcc/range-op.cc index cb584314f4c..56e80c9f3ae 100644 --- a/gcc/range-op.cc +++ b/gcc/range-op.cc @@ -367,23 +367,6 @@ range_op_handler::op1_op2_relation (const vrange &lhs) const } -// Convert irange bitmasks into a VALUE MASK pair suitable for calling CCP. - -static void -irange_to_masked_value (const irange &r, widest_int &value, widest_int &mask) -{ - if (r.singleton_p ()) - { - mask = 0; - value = widest_int::from (r.lower_bound (), TYPE_SIGN (r.type ())); - } - else - { - mask = widest_int::from (r.get_nonzero_bits (), TYPE_SIGN (r.type ())); - value = 0; - } -} - // Update the known bitmasks in R when applying the operation CODE to // LH and RH. @@ -391,25 +374,33 @@ void update_known_bitmask (irange &r, tree_code code, const irange &lh, const irange &rh) { - if (r.undefined_p () || lh.undefined_p () || rh.undefined_p ()) + if (r.undefined_p () || lh.undefined_p () || rh.undefined_p () + || r.singleton_p ()) return; - widest_int value, mask, lh_mask, rh_mask, lh_value, rh_value; + widest_int widest_value, widest_mask; tree type = r.type (); signop sign = TYPE_SIGN (type); int prec = TYPE_PRECISION (type); - signop lh_sign = TYPE_SIGN (lh.type ()); - signop rh_sign = TYPE_SIGN (rh.type ()); - int lh_prec = TYPE_PRECISION (lh.type ()); - int rh_prec = TYPE_PRECISION (rh.type ()); - - irange_to_masked_value (lh, lh_value, lh_mask); - irange_to_masked_value (rh, rh_value, rh_mask); - bit_value_binop (code, sign, prec, &value, &mask, - lh_sign, lh_prec, lh_value, lh_mask, - rh_sign, rh_prec, rh_value, rh_mask); - wide_int tmp = wide_int::from (value | mask, prec, sign); - r.set_nonzero_bits (tmp); + irange_bitmask lh_bits = lh.get_bitmask (); + irange_bitmask rh_bits = rh.get_bitmask (); + + bit_value_binop (code, sign, prec, &widest_value, &widest_mask, + TYPE_SIGN (lh.type ()), + TYPE_PRECISION (lh.type ()), + widest_int::from (lh_bits.value (), sign), + widest_int::from (lh_bits.mask (), sign), + TYPE_SIGN (rh.type ()), + TYPE_PRECISION (rh.type ()), + widest_int::from (rh_bits.value (), sign), + widest_int::from (rh_bits.mask (), sign)); + + wide_int mask = wide_int::from (widest_mask, prec, sign); + wide_int value = wide_int::from (widest_value, prec, sign); + // Bitmasks must have the unknown value bits cleared. + value &= ~mask; + irange_bitmask bm (value, mask); + r.update_bitmask (bm); } // Return the upper limit for a type. diff --git a/gcc/testsuite/gcc.dg/pr83073.c b/gcc/testsuite/gcc.dg/pr83073.c index 1168ae822a4..228e1890086 100644 --- a/gcc/testsuite/gcc.dg/pr83073.c +++ b/gcc/testsuite/gcc.dg/pr83073.c @@ -7,4 +7,4 @@ int f(int x) return x & 1; } -/* { dg-final { scan-tree-dump "gimple_simplified to.* = 1" "evrp" } } */ +/* { dg-final { scan-tree-dump "Folded into: return 1;" "evrp" } } */