From patchwork Tue Oct 26 00:03:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 46645 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 15DB8385800A for ; Tue, 26 Oct 2021 00:04:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 15DB8385800A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1635206651; bh=u620wCM2qcR0Wlp61aiauTQHuL/Hz/JEIBolBr50QkM=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=CrAofT6fC5mRRS6Pygh04DovwYaluAGgXvZ19xjiqvvkfd+9E+SSW4orUFE9x/9f6 aaHSdzpdaFULMnZP6IF4UdgUCNyISMV1LtFiD32zUVxV8LIG+yrUL4Vbd83Il6X2Jn LWO8ZuWiWCrQdCnRls1AgkkoTSRADp50XbYJ13Yo= 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 D4EBD3858C27 for ; Tue, 26 Oct 2021 00:03:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D4EBD3858C27 Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-101-NaELZ8XJPG-KiCdbG3EYlQ-1; Mon, 25 Oct 2021 20:03:38 -0400 X-MC-Unique: NaELZ8XJPG-KiCdbG3EYlQ-1 Received: by mail-qt1-f197.google.com with SMTP id d19-20020ac85d93000000b002a82aa20c11so1721854qtx.12 for ; Mon, 25 Oct 2021 17:03:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:to:cc:from:subject:message-id:date:user-agent :mime-version:content-language; bh=u620wCM2qcR0Wlp61aiauTQHuL/Hz/JEIBolBr50QkM=; b=PvijGWTKuWI/AhK2RWEw79gp0LPvEKT0k1jDHgcq341q7vk/Pc8uAmChLD5YrHlGpP w0LkRVq5QbSgzMY5MfCGYCaNGbtz3goZr9rHQ8OlNGuuevkmJup1t2eby6rL6sWFOn8d zjFRUzR4hATAAwD66bYUlFmH+8YGZ2iG5AAc+EV1xMhm78lDbcLuk4riAixTgDGfDCWc D/+y6AidjDhYsiRIF533bj8IFXEJB27aUS2OxmljeG9iTWv1BgnSrjX4eEnxe6Uz83Ti v+1plPSzCjyGsuP323qecbTUoyumEI6wgc1YJloxppPzQaQ2NXVb1F4hrXDcZXX3sVVG VW/Q== X-Gm-Message-State: AOAM533B4bsyONqpAhcIGq61+N98GyK5Ik19hqw46yPlu6LFx6/eoRPq m3aoeXQgARhPlfGHGKh/SvbcV2Ah+Bit3PS4dVN7UyA8QawsQGjcIkRW2GQbLOXJg+KUTE3KF9o crgy1/IC2o5BjBkfiJw== X-Received: by 2002:ad4:5fce:: with SMTP id jq14mr19295689qvb.33.1635206618502; Mon, 25 Oct 2021 17:03:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxHPgkOnk3XQnUsDy2FhFo+BM6UE/9Izzq6UN3fGxVFRQ4yw0TY0vqg78P1DfbP3bTUlAa4zg== X-Received: by 2002:ad4:5fce:: with SMTP id jq14mr19295672qvb.33.1635206618334; Mon, 25 Oct 2021 17:03:38 -0700 (PDT) Received: from [192.168.0.102] ([192.24.49.122]) by smtp.gmail.com with ESMTPSA id t9sm10081211qtx.47.2021.10.25.17.03.36 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 25 Oct 2021 17:03:37 -0700 (PDT) To: gcc-patches Subject: [COMMITTED] Fold all statements in Ranger VRP. Message-ID: Date: Mon, 25 Oct 2021 20:03:35 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.14.0 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-CA X-Spam-Status: No, score=-11.5 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_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+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" This patch changes the ranger VRP pass to simplify all statements, not just the ones with ranges.  I believe Jeff had mentioned we were no longer doing this a while back.  Now we need it when running as the VRP2 pass to satisfy the testcase: gcc.dg/wrapped-binop-simplify.c This also requires a testcase adjustment since EVRP will now perform this simplification, and it causes a test looking for it in VRP1 to fail.  In that test, I simply disable evrp, and then add a duplicate of the test which then tests that EVRP also performs the optimization. Bootstrapped on x86_64-pc-linux-gnu with no regressions. Pushed. Andrew From cb153222404e2e149aa65a4b3139b09477551203 Mon Sep 17 00:00:00 2001 From: Andrew MacLeod Date: Wed, 20 Oct 2021 13:37:29 -0400 Subject: [PATCH 1/2] Fold all statements in Ranger VRP. Until now, ranger VRP has only simplified statements with ranges. This patch enables us to fold all statements. gcc/ * tree-vrp.c (rvrp_folder::fold_stmt): If simplification fails, try to fold anyway. gcc/testsuite/ * gcc.dg/tree-ssa/vrp98.c: Disable evrp for vrp1 test. * gcc.dg/tree-ssa/vrp98-1.c: New. Test for folding in evrp. --- gcc/testsuite/gcc.dg/tree-ssa/vrp98-1.c | 41 +++++++++++++++++++++++++ gcc/testsuite/gcc.dg/tree-ssa/vrp98.c | 2 +- gcc/tree-vrp.c | 5 ++- 3 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/vrp98-1.c diff --git a/gcc/testsuite/gcc.dg/tree-ssa/vrp98-1.c b/gcc/testsuite/gcc.dg/tree-ssa/vrp98-1.c new file mode 100644 index 00000000000..daa3f073b92 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/vrp98-1.c @@ -0,0 +1,41 @@ +/* { dg-do compile } */ +/* { dg-require-effective-target int128 } */ +/* { dg-options "-Os -fdump-tree-evrp-details" } */ + +#include +#include + +typedef unsigned int word __attribute__((mode(word))); +typedef unsigned __int128 bigger_than_word; + +int +foo (bigger_than_word a, word b, uint8_t c) +{ + /* Must fold use of t1 into use of b, as b is no wider than word_mode. */ + const uint8_t t1 = b % UCHAR_MAX; + + /* Must NOT fold use of t2 into use of a, as a is wider than word_mode. */ + const uint8_t t2 = a % UCHAR_MAX; + + /* Must fold use of t3 into use of c, as c is narrower than t3. */ + const uint32_t t3 = (const uint32_t)(c >> 1); + + uint16_t ret = 0; + + if (t1 == 1) + ret = 20; + else if (t2 == 2) + ret = 30; + else if (t3 == 3) + ret = 40; + /* Th extra condition below is necessary to prevent a prior pass from + folding away the cast. Ignored in scan-tree-dump. */ + else if (t3 == 4) + ret = 50; + + return ret; +} + +/* { dg-final { scan-tree-dump "Folded into: if \\(_\[0-9\]+ == 1\\)" "evrp" } } */ +/* { dg-final { scan-tree-dump-not "Folded into: if \\(_\[0-9\]+ == 2\\)" "evrp" } } */ +/* { dg-final { scan-tree-dump "Folded into: if \\(_\[0-9\]+ == 3\\)" "evrp" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/vrp98.c b/gcc/testsuite/gcc.dg/tree-ssa/vrp98.c index 982f091080c..78d3bbaf499 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/vrp98.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/vrp98.c @@ -1,6 +1,6 @@ /* { dg-do compile } */ /* { dg-require-effective-target int128 } */ -/* { dg-options "-Os -fdump-tree-vrp1-details" } */ +/* { dg-options "-Os -fdisable-tree-evrp -fdump-tree-vrp1-details" } */ #include #include diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c index ba7a4efc7c6..a948c524098 100644 --- a/gcc/tree-vrp.c +++ b/gcc/tree-vrp.c @@ -50,6 +50,7 @@ along with GCC; see the file COPYING3. If not see #include "gimple-range.h" #include "gimple-range-path.h" #include "value-pointer-equiv.h" +#include "gimple-fold.h" /* Set of SSA names found live during the RPO traversal of the function for still active basic-blocks. */ @@ -4381,7 +4382,9 @@ public: bool fold_stmt (gimple_stmt_iterator *gsi) OVERRIDE { - return m_simplifier.simplify (gsi); + if (m_simplifier.simplify (gsi)) + return true; + return ::fold_stmt (gsi, follow_single_use_edges); } private: -- 2.17.2