From patchwork Tue Jun 22 13:18:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 1495682 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: 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=UAUlPrOf; dkim-atps=neutral Received: from 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 RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4G8Rst0MGvz9sS8 for ; Tue, 22 Jun 2021 23:23:14 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0DEC53896C26 for ; Tue, 22 Jun 2021 13:23:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0DEC53896C26 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1624368191; bh=6FvWg9NWzFbAilEdKqfrK54BTuA88oeeufN6C31COZc=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=UAUlPrOfEn1f6HNiaIcy5Db1SpomjWg8kQ+gk8h7kclu2orHJxw8bpMmcfEog/i3b Ixu1e/v8mZ/Mbvt03vrgKQNB9+J4PCAq9A6/OylpxzEw2n3iSKMXtAXzeF+KE5WqAc YYxzk0cjj17FpQERLlOjbrYcxEqhSMiAA9On0nz0= 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 ESMTP id 582CC383D023 for ; Tue, 22 Jun 2021 13:18:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 582CC383D023 Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-350-4ZkEYnMINmemb1xybwF46A-1; Tue, 22 Jun 2021 09:18:51 -0400 X-MC-Unique: 4ZkEYnMINmemb1xybwF46A-1 Received: by mail-qv1-f69.google.com with SMTP id s9-20020ad452490000b02902786b63dbfeso2064922qvq.5 for ; Tue, 22 Jun 2021 06:18:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:cc:from:subject:message-id:date:user-agent :mime-version:content-language; bh=6FvWg9NWzFbAilEdKqfrK54BTuA88oeeufN6C31COZc=; b=QTRx24yfPGDP6DmVyhg5imtqvhtbpSfKF1Bf+cgfvbhNRr9F+c3hZgtM7mLyok6tsu u49cAkuuXqhZl/moG7CIxnQ1XOMgbWEFJue6p6CksZJ2Bg8hYQJCNm/a6zMUGHDlQhzq tj3cZWupooBU47IL+WefMSbB6TMJAvzXiXsTkedGFsFFWzkkdUBesh0qY0KtbUMeoYjd PI4zjW3TaOsvlPnNEZb3B/Eh3VKGXXfbsaTwdN3qUvMdmEqV76X8Y8+S12cVkhPLg3i2 WuefTXmZxktI8kKH1nPhEtQRM+AgpAF92CfrJgpNoAmutL9gGMIRTJmbde5BWcejP7C4 so/w== X-Gm-Message-State: AOAM5331pAf6+p7BkWMcHAhS9rKCcGilPBjcBaHfQmh+dS+zNolxmojD GO1zeKTNtg9oifG1bv3bifQtyW2pXxSI8nEZ7JxGEwUU04ES2vnk67cBYhuvyfptyXKY/GOmM8R zRd987DJPjUulpDkA9Q== X-Received: by 2002:a05:6214:4b:: with SMTP id c11mr18161343qvr.18.1624367931240; Tue, 22 Jun 2021 06:18:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyjc2W5ib15VRZ1ch2ypQbC+IiIQLndslHzWEM+XcAO0vKvF7vLIKnF07hYzhkccyT2TqezWw== X-Received: by 2002:a05:6214:4b:: with SMTP id c11mr18161317qvr.18.1624367931023; Tue, 22 Jun 2021 06:18:51 -0700 (PDT) Received: from ?IPv6:2607:fea8:a241:4600:84d5:145a:ba5d:a5af? ([2607:fea8:a241:4600:84d5:145a:ba5d:a5af]) by smtp.gmail.com with ESMTPSA id z16sm1669455qta.39.2021.06.22.06.18.48 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 22 Jun 2021 06:18:49 -0700 (PDT) To: gcc-patches Subject: [COMMITTED 5/7] Add relation effects between operands to MINUS_EXPR. Message-ID: <59a8dcbe-1755-abda-54cf-92e5fe8bdcea@redhat.com> Date: Tue, 22 Jun 2021 09:18:48 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.10.0 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-CA X-Spam-Status: No, score=-12.6 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_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: Andrew MacLeod via Gcc-patches From: Andrew MacLeod Reply-To: Andrew MacLeod Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" This patch enhances processing of OP_MINUS to show how we can utilize relations between op1 and op2 to produce a better result. Given: a_3 = b_4 - d_1 if we know b_4 > d_1, on top of whatever other range calculations we can do with the actual ranges, we can apply the knowledge that the result must also  be  in the range [1, +INF] as well. likewise, if we know b_4 == d_1, we know the result is [0,0] This provide a sample of how applying a relation between 2 operands is implemented. Bootstraps on x86_64-pc-linux-gnu with no regressions.  Pushed. Andrew From ae6b830f31a47aca7ca24c4fea245c29214eef3a Mon Sep 17 00:00:00 2001 From: Andrew MacLeod Date: Thu, 17 Jun 2021 13:38:03 -0400 Subject: [PATCH 5/7] Add relation effects between operands to MINUS_EXPR. * range-op.cc (operator_minus::op1_op2_relation_effect): New. --- gcc/range-op.cc | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/gcc/range-op.cc b/gcc/range-op.cc index a7698f21b0d..ec4816d69fa 100644 --- a/gcc/range-op.cc +++ b/gcc/range-op.cc @@ -1279,6 +1279,11 @@ public: const wide_int &lh_ub, const wide_int &rh_lb, const wide_int &rh_ub) const; + virtual bool op1_op2_relation_effect (irange &lhs_range, + tree type, + const irange &op1_range, + const irange &op2_range, + relation_kind rel) const; } op_minus; void @@ -1293,6 +1298,45 @@ operator_minus::wi_fold (irange &r, tree type, value_range_with_overflow (r, type, new_lb, new_ub, ov_lb, ov_ub); } +// Check to see if the relation REL between OP1 and OP2 has any effect on the +// LHS of the epxression. If so, apply it to LHS_RANGE. + +bool +operator_minus::op1_op2_relation_effect (irange &lhs_range, tree type, + const irange &op1_range ATTRIBUTE_UNUSED, + const irange &op2_range ATTRIBUTE_UNUSED, + relation_kind rel) const +{ + if (rel == VREL_NONE) + return false; + + int_range<2> rel_range; + unsigned prec = TYPE_PRECISION (type); + signop sgn = TYPE_SIGN (type); + + switch (rel) + { + // op1 > op2, op1 - op2 can be restricted to [1, max] + case GT_EXPR: + rel_range = int_range<2> (type, wi::one (prec), + wi::max_value (prec, sgn)); + break; + // op1 >= op2, op1 - op2 can be restricted to [0, max] + case GE_EXPR: + rel_range = int_range<2> (type, wi::zero (prec), + wi::max_value (prec, sgn)); + break; + // op1 == op2, op1 - op2 can be restricted to [0, 0] + case EQ_EXPR: + rel_range = int_range<2> (type, wi::zero (prec), wi::zero (prec)); + break; + default: + return false; + } + lhs_range.intersect (rel_range); + return true; +} + bool operator_minus::op1_range (irange &r, tree type, const irange &lhs, -- 2.17.2