From patchwork Wed Jul 13 14:26:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 56030 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9D3803838A81 for ; Wed, 13 Jul 2022 14:27:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9D3803838A81 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1657722470; bh=6FOYY5frTx+lFWiGRGjGOGto5dL33vMWgCcr+6iXtN4=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=BmPB7R+/AQ3oAGk99D/6x5F6OModWCvq+7eANLcPBEbPQ4wIUDaGirXLx5upjNXsy c9uAf+LArNAatf6mmIl7ShkHJuqPZ3MjU/0YV9zMjojiFUu/eA+UPuKwjrtxGbcZ8W Qbe4+Z+YpZCgkEcW64rmD8LfGgOdvT0jAv28vrOo= 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 E4710383A347 for ; Wed, 13 Jul 2022 14:27:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E4710383A347 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-444-CqFJdpOAO4aeferTfoYxYg-1; Wed, 13 Jul 2022 10:27:19 -0400 X-MC-Unique: CqFJdpOAO4aeferTfoYxYg-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 30F4A101A596 for ; Wed, 13 Jul 2022 14:27:19 +0000 (UTC) Received: from abulafia.quesejoda.com (unknown [10.39.195.134]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BD7288287E; Wed, 13 Jul 2022 14:27:18 +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 26DERGI8633767 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 13 Jul 2022 16:27:16 +0200 Received: (from aldyh@localhost) by abulafia.quesejoda.com (8.17.1/8.17.1/Submit) id 26DERGJr633766; Wed, 13 Jul 2022 16:27:16 +0200 To: GCC patches Subject: [COMMITTED] Use nonzero bits in range-ops to determine if < 0 is false. Date: Wed, 13 Jul 2022 16:26:19 +0200 Message-Id: <20220713142619.633492-2-aldyh@redhat.com> In-Reply-To: <20220713142619.633492-1-aldyh@redhat.com> References: <20220713142619.633492-1-aldyh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.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_NONE, 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+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" For a signed integer, x < 0 is false if the sign bit in the nonzero bits of X is clear. Both CCP and ipa-cp can set the global nonzero bits in a range, which means we can now use some of that information in evrp and subsequent passes. I've adjusted two tests which now fold things earlier because of this optimization. Tested on x86-64 Linux. gcc/ChangeLog: * range-op.cc (operator_lt::fold_range): Use nonzero bits. gcc/testsuite/ChangeLog: * g++.dg/ipa/pure-const-3.C: Adjust. * gcc.dg/pr102983.c: Adjust. --- gcc/range-op.cc | 3 +++ gcc/testsuite/g++.dg/ipa/pure-const-3.C | 2 +- gcc/testsuite/gcc.dg/pr102983.c | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/gcc/range-op.cc b/gcc/range-op.cc index 0e16408027c..e184129f9af 100644 --- a/gcc/range-op.cc +++ b/gcc/range-op.cc @@ -803,6 +803,9 @@ operator_lt::fold_range (irange &r, tree type, r = range_true (type); else if (!wi::lt_p (op1.lower_bound (), op2.upper_bound (), sign)) r = range_false (type); + // Use nonzero bits to determine if < 0 is false. + else if (op2.zero_p () && !wi::neg_p (op1.get_nonzero_bits (), sign)) + r = range_false (type); else r = range_true_and_false (type); return true; diff --git a/gcc/testsuite/g++.dg/ipa/pure-const-3.C b/gcc/testsuite/g++.dg/ipa/pure-const-3.C index 172a36bedb5..b4a4673e86e 100644 --- a/gcc/testsuite/g++.dg/ipa/pure-const-3.C +++ b/gcc/testsuite/g++.dg/ipa/pure-const-3.C @@ -1,5 +1,5 @@ /* { dg-do compile } */ -/* { dg-options "-O2 -fno-ipa-vrp -fdump-tree-optimized -fno-tree-ccp" } */ +/* { dg-options "-O2 -fno-ipa-vrp -fdump-tree-optimized -fno-tree-ccp -fdisable-tree-evrp" } */ int *ptr; static int barvar; static int b(int a); diff --git a/gcc/testsuite/gcc.dg/pr102983.c b/gcc/testsuite/gcc.dg/pr102983.c index ef58af6def0..e1bd24b2e39 100644 --- a/gcc/testsuite/gcc.dg/pr102983.c +++ b/gcc/testsuite/gcc.dg/pr102983.c @@ -1,5 +1,5 @@ /* { dg-do compile } */ -/* { dg-options "-O2 -fdump-tree-evrp" } */ +/* { dg-options "-O2 -fdump-tree-evrp -fno-tree-ccp" } */ void foo(void); static int a = 1;