From patchwork Tue Jun 15 11:48:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 1492152 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=8.43.85.97; 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=ctCAsKoO; dkim-atps=neutral Received: from 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 RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4G467l4dJZz9sTD for ; Tue, 15 Jun 2021 21:50:11 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7770D3840015 for ; Tue, 15 Jun 2021 11:50:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7770D3840015 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1623757809; bh=ZnTutl1o2RWQ/qp/6p18A90ypYmJwLwvKKwekRXo9yw=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=ctCAsKoOSVfaC5EepTANEc5Wyui3+y+eRGz8lwFi1nW+EbCVQeq09lZAFptcqzJuJ z1eUVYzs7/bQw0LNvlU+pX7VtdVPPpeJ0YggTUh/+LdeB4XCqaZX8YqiphIjsKwFBg ++x70cLSgsYFxu/o2BfErwTIHoV4CWXXNkci14Dw= 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 [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id 2F275385781B for ; Tue, 15 Jun 2021 11:49:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 2F275385781B Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-265--MESeM5xMj22_MuxbRz1rw-1; Tue, 15 Jun 2021 07:49:23 -0400 X-MC-Unique: -MESeM5xMj22_MuxbRz1rw-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 31BDD10068F6 for ; Tue, 15 Jun 2021 11:49:22 +0000 (UTC) Received: from abulafia.quesejoda.com (ovpn-112-150.ams2.redhat.com [10.36.112.150]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 29D23620DE; Tue, 15 Jun 2021 11:49:20 +0000 (UTC) Received: from abulafia.quesejoda.com (localhost [127.0.0.1]) by abulafia.quesejoda.com (8.16.1/8.15.2) with ESMTPS id 15FBnJ9I151636 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 15 Jun 2021 13:49:19 +0200 Received: (from aldyh@localhost) by abulafia.quesejoda.com (8.16.1/8.16.1/Submit) id 15FBnJJ7151635; Tue, 15 Jun 2021 13:49:19 +0200 To: GCC patches Subject: [PATCH] range-ops: (nonzero | X) is nonzero Date: Tue, 15 Jun 2021 13:48:39 +0200 Message-Id: <20210615114838.151530-1-aldyh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.1 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: 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" For bitwise or, nonzero|X is always nonzero. Make sure we don't drop to varying in this case. This was found while examining differences between VRP/DOM threaders and the upcoming work, but it could be useful for any user of range-ops. Tested on x86-64 Linux. OK? gcc/ChangeLog: * range-op.cc (operator_bitwise_or::wi_fold): Make sure nonzero|X is nonzero. (range_op_bitwise_and_tests): Add tests for above. --- gcc/range-op.cc | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/gcc/range-op.cc b/gcc/range-op.cc index 742e54686b4..59978466b45 100644 --- a/gcc/range-op.cc +++ b/gcc/range-op.cc @@ -2534,11 +2534,20 @@ operator_bitwise_or::wi_fold (irange &r, tree type, new_lb = wi::max (new_lb, lh_lb, sign); if (wi::lt_p (rh_ub, 0, sign)) new_lb = wi::max (new_lb, rh_lb, sign); - // If the limits got swapped around, return varying. + // If the limits got swapped around, return a conservative range. if (wi::gt_p (new_lb, new_ub,sign)) - r.set_varying (type); - else - value_range_with_overflow (r, type, new_lb, new_ub); + { + // Make sure that nonzero|X is nonzero. + if (wi::gt_p (lh_lb, 0, sign) + || wi::gt_p (rh_lb, 0, sign) + || wi::lt_p (lh_ub, 0, sign) + || wi::lt_p (rh_ub, 0, sign)) + r.set_nonzero (type); + else + r.set_varying (type); + return; + } + value_range_with_overflow (r, type, new_lb, new_ub); } bool @@ -3744,6 +3753,17 @@ range_op_bitwise_and_tests () i1 = int_range<1> (integer_type_node); op_bitwise_and.op1_range (res, integer_type_node, i1, i2); ASSERT_TRUE (res == int_range<1> (integer_type_node)); + + // (NONZERO | X) is nonzero. + i1.set_nonzero (integer_type_node); + i2.set_varying (integer_type_node); + op_bitwise_or.fold_range (res, integer_type_node, i1, i2); + ASSERT_TRUE (res.nonzero_p ()); + + // (NEGATIVE | X) is nonzero. + i1 = int_range<1> (INT (-5), INT (-3)); + i2.set_varying (integer_type_node); + op_bitwise_or.fold_range (res, integer_type_node, i1, i2); } void