From patchwork Thu Jan 13 13:57:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 1579636 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=vHsXAJpT; dkim-atps=neutral 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=) Received: from sourceware.org (server2.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 bilbo.ozlabs.org (Postfix) with ESMTPS id 4JZQyW5fcYz9sRR for ; Fri, 14 Jan 2022 00:58:59 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6604E3951C14 for ; Thu, 13 Jan 2022 13:58:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6604E3951C14 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1642082337; bh=X+JDSEw+Tp1jq1LCRteirolT0PPwZRLg/ribRFfbEQs=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=vHsXAJpTmgvNOkLj3NvbGQAVxVePCdZo3xF/+97C0S/cYAJ5EGJorQd7xWEi2ckBV JSk/ni2XW83jVdzlYZejUfRa5DOjkaY8nWXgV/37IZpzv/J02otR+jyV0vCTcC+F1z PslGvz8lnNJ95yBr0Zj1/MtwZWVSf4k2hoxVYjmE= 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.129.124]) by sourceware.org (Postfix) with ESMTPS id D18BC3951C11 for ; Thu, 13 Jan 2022 13:57:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D18BC3951C11 Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-219-cFpfT9iGO9-IKAl4Ao-5rA-1; Thu, 13 Jan 2022 08:57:45 -0500 X-MC-Unique: cFpfT9iGO9-IKAl4Ao-5rA-1 Received: by mail-qt1-f200.google.com with SMTP id x10-20020ac8700a000000b002c3ef8fc44cso4976691qtm.8 for ; Thu, 13 Jan 2022 05:57:45 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent :content-language:to:cc:from:subject; bh=9t/c4bXCp95Zh0AD2lHFKO93va2M8HeP0Y1jevHnjck=; b=Doi8tdUBzpw7btd1aog2xpf58fFpUvVvRkBm1oPGWBRXVoVm/Qt+D/suY8Apz7SSGI 5joYaro0UmPd1Lp64bEkoc6rXYl/ZRl9tYVSDphISljAoEj3U0s7ZTaJo1cmPbWP3fVZ Fy06zZGC4PfGQvHilkqUwMJZsQMtyp4uKw8F9vFOqlGgUO8ELWhSOXQu3DcLmavIJHBX 5s/DOfe01VG+DiHEWd2hZiTbfT2nm2KzmUuFp/GnzVTwB3BOI+fjmFUEfa6GaYqR8r1z 7BObv7wIzimNlyM0t41/EOqZ3hDKI5+2E2Ri/+9CpihBlmUa6kRtguTMN9iMpar/4zc9 JIvA== X-Gm-Message-State: AOAM5338q8F9bp6tTV++r35Yo2A5jO42X+gFHuEkbH8M0LWaRPxS1Cuf 3Hn9yKTicBPrTMWUUkOJmBuNl5c+C2pFiz2pH2CrdDoQpLUFhHvxIu9oDAwuIVFR4ZxVf/m7KKo UQC3vbUWtYYTssmXdvl9LAXP96jemUzEJpM7D1FT6JJvtSNhtAuXEtPgecydyDEF4rCJtog== X-Received: by 2002:a05:6214:f25:: with SMTP id iw5mr4089348qvb.72.1642082264688; Thu, 13 Jan 2022 05:57:44 -0800 (PST) X-Google-Smtp-Source: ABdhPJzO2Nq2K07Cg8z1isolWcfgB7kZvbMFnmZ1IvpTGSOC9LnUoxCmCXygEeeAiC4hpIyarZRMgg== X-Received: by 2002:a05:6214:f25:: with SMTP id iw5mr4089336qvb.72.1642082264520; Thu, 13 Jan 2022 05:57:44 -0800 (PST) Received: from ?IPV6:2607:fea8:a262:5f00:e36d:32da:80f:d4e1? ([2607:fea8:a262:5f00:e36d:32da:80f:d4e1]) by smtp.gmail.com with ESMTPSA id f13sm2077088qtf.21.2022.01.13.05.57.43 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 13 Jan 2022 05:57:43 -0800 (PST) Message-ID: <159ff48e-32cf-da90-5b74-262b94d04095@redhat.com> Date: Thu, 13 Jan 2022 08:57:42 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.4.1 To: gcc-patches Subject: [PATCH] tree-optimization/83072 - Allow more precision when querying from fold_const. X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-CA X-Spam-Status: No, score=-12.3 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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 actually addresses a few PRs. The root PR was 97909.   Ranger context functionality was added to fold_const back in early November (https://gcc.gnu.org/pipermail/gcc-patches/2021-November/583216.html) The other 2 PRs mentioned (83072 and 83073) partially worked after this, but the original patch did not change the result of the query in expr_not_equal_to () to a multi-range object. This patch simply changes the value_range variable in that routine to an int_range<5> so we can pick up more precision. This in turn allows us to capture all the tests as expected. Bootstrapped on x86_64-pc-linux-gnu with no regressions. OK for trunk? Andrew From 329626a426d21dfe484053f7b6ac4f2d0c14fa0e Mon Sep 17 00:00:00 2001 From: Andrew MacLeod Date: Wed, 12 Jan 2022 13:31:08 -0500 Subject: [PATCH 2/2] Allow more precision when querying from fold_const. fold_const::expr_not_equal_to queries for a current range, but still uses the old value_range class. This is causing it to miss opportunities when ranger can provide something better. PR tree-optimization/83072 PR tree-optimization/83073 PR tree-optimization/97909 gcc/ * fold-const.c (expr_not_equal_to): Use a multi-range class. gcc/testsuite/ * gcc.dg/pr83072-2.c: New. * gcc.dg/pr83073.c: New. --- gcc/fold-const.c | 2 +- gcc/testsuite/gcc.dg/pr83072-2.c | 18 ++++++++++++++++++ gcc/testsuite/gcc.dg/pr83073.c | 10 ++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/pr83072-2.c create mode 100644 gcc/testsuite/gcc.dg/pr83073.c diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 397fa9a03a1..7945b8d9eda 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -10734,7 +10734,7 @@ tree_expr_nonzero_p (tree t) bool expr_not_equal_to (tree t, const wide_int &w) { - value_range vr; + int_range<5> vr; switch (TREE_CODE (t)) { case INTEGER_CST: diff --git a/gcc/testsuite/gcc.dg/pr83072-2.c b/gcc/testsuite/gcc.dg/pr83072-2.c new file mode 100644 index 00000000000..f495f2582c4 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr83072-2.c @@ -0,0 +1,18 @@ +/* { dg-do compile} */ +/* { dg-options "-O2 -fdump-tree-evrp-details" } */ + +int f1(int a, int b, int c){ + if(c==0)__builtin_unreachable(); + a *= c; + b *= c; + return a == b; +} + +int f2(int a, int b, int c){ + c |= 1; + a *= c; + b *= c; + return a == b; +} + +/* { dg-final { scan-tree-dump-times "gimple_simplified to" 2 "evrp" } } */ diff --git a/gcc/testsuite/gcc.dg/pr83073.c b/gcc/testsuite/gcc.dg/pr83073.c new file mode 100644 index 00000000000..1168ae822a4 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr83073.c @@ -0,0 +1,10 @@ +/* { dg-do compile} */ +/* { dg-options "-O2 -fdump-tree-evrp-details -fno-tree-fre -fno-tree-ccp -fno-tree-forwprop" } */ + +int f(int x) +{ + x = x|1; + return x & 1; +} + +/* { dg-final { scan-tree-dump "gimple_simplified to.* = 1" "evrp" } } */ -- 2.17.2