From patchwork Wed Dec 7 16:44:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 61666 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 37B5E390CE99 for ; Wed, 7 Dec 2022 16:44:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 37B5E390CE99 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1670431486; bh=Xc0mV1Z60tNP4w1L5E9vUFxMBrQVvOfwjoxt//+lGmc=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=HRI8ZQYFtsHzYJIdObtl4nhugDd2bRjWml87Xu1O27zXzioxQIgLv/p+CRO7iHjxC 2GHQ/lX1gqbzAAKT07BxSHRSipbOeO1bs0YsCDgMw2YDC82JDMI5ZRxQgzkkEBtzC6 hZQQOysPnvX9maFpnpUKqL0DhSlWVjtcFlebAwro= 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 7ED6B3898391 for ; Wed, 7 Dec 2022 16:44:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 7ED6B3898391 Received: from mail-io1-f69.google.com (mail-io1-f69.google.com [209.85.166.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-479-kHZxeznoNESk8moje9q4YQ-1; Wed, 07 Dec 2022 11:44:07 -0500 X-MC-Unique: kHZxeznoNESk8moje9q4YQ-1 Received: by mail-io1-f69.google.com with SMTP id c20-20020a5d9754000000b006dbd4e6a5abso13961290ioo.17 for ; Wed, 07 Dec 2022 08:44:07 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=subject:from:cc:to:content-language:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=7gsNjG5pxtPOL9dIn3nReFkP3vFLeJVwmjr9OCP+4yk=; b=ryz7PEHzKCe91+3Q1ohl+cbl6zrqn23S+7WvCc3stkTq+TGF2LxKWXYapwBFTbnrix Y6tVZKGlxUInx+54PaOc4I5ggGrGHVaguWV7zK8P0zQ5TPyqV67aMfRSr/EHMuvq8ZcV k7rOGIjUymH4ep6DAXHdNx0n+ZNUt62slUKVCstiokZs1bwfPWr9vPNstESsOs9Z5X28 uZVymb9RqBFNqv9nVLCbvgt3KBw7ndDf1nRwQPvvtEWzqfL7q7StZqAb2CFZhJnxx/T1 Y+DhMXiqvbtCKib+wMC95DtN0nLqAplAymxtyRsnrcyt3reC2ZumcTwTrEHP1T0bJrXI rOtg== X-Gm-Message-State: ANoB5pn1v5aVrY87xgY1x94bAk0Sr2N5cN9e62C+RKlErzQiL90+CbKV QBYcJJDzF2+JYeqKAEWKx2I2jiZCzatHSWvPmpHhBZgyn5xGfTAjCnAXC5ZosLj+wTAAqnxa1jG jpjUF7FHJ4FSTUc7C67jO+yfmwZwwdFcTMlaZk29+C78R699w/y4ko7gVDPw+rFWY7A907g== X-Received: by 2002:a05:6638:1914:b0:389:cc3c:414b with SMTP id p20-20020a056638191400b00389cc3c414bmr24039465jal.313.1670431446521; Wed, 07 Dec 2022 08:44:06 -0800 (PST) X-Google-Smtp-Source: AA0mqf5KqSopUR4Hh1xzrH5w3FWl6N9nZ2o5MK3M7n7mmlQdY8MXWUoFUSERxgZlejO8vqW30BNmaw== X-Received: by 2002:a05:6638:1914:b0:389:cc3c:414b with SMTP id p20-20020a056638191400b00389cc3c414bmr24039461jal.313.1670431446292; Wed, 07 Dec 2022 08:44:06 -0800 (PST) Received: from ?IPV6:2607:fea8:a263:f600::6c01? ([2607:fea8:a263:f600::6c01]) by smtp.gmail.com with ESMTPSA id k7-20020a6bba07000000b006cecd92164esm3528402iof.34.2022.12.07.08.44.05 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 07 Dec 2022 08:44:05 -0800 (PST) Message-ID: <1752ce19-956b-a055-2585-a6b0e2827572@redhat.com> Date: Wed, 7 Dec 2022 11:44:04 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.5.0 To: gcc-patches Cc: "hernandez, aldy" Subject: [PATCH] PR tree-optimization/107985 - Ensure arguments to range-op handler are supported. X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US X-Spam-Status: No, score=-11.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_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP 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: 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 invalidates a range-op handler object if an operand type in the statement is not supported. This also triggered a check in stmt dependency resolution which assumed there must be a valid handler for any stmt with an appropriate LHS type... which is a false assumption. This should do for now, but long term I will rework the dispatch code to ensure it matches the specifically supported patterns of operands. This will make the handler creation a little slower, but speed up the actual dispatch, especially as we add new range types next release.  Its also much more invasive... too much for this release I think. bootstraps on x86_64-pc-linux-gnu with no regressions.  OK? Andrew From 966076046e5687937eeac61df762f89178aa17c7 Mon Sep 17 00:00:00 2001 From: Andrew MacLeod Date: Tue, 6 Dec 2022 10:41:29 -0500 Subject: [PATCH 1/2] Ensure arguments to range-op handler are supported. PR tree-optimization/107985 gcc/ * gimple-range-op.cc (gimple_range_op_handler::gimple_range_op_handler): Check if type of the operands is supported. * gimple-range.cc (gimple_ranger::prefill_stmt_dependencies): Do not assert if here is no range-op handler. gcc/testsuite/ * g++.dg/pr107985.C: New. --- gcc/gimple-range-op.cc | 6 ++++++ gcc/gimple-range.cc | 24 +++++++++++++----------- gcc/testsuite/g++.dg/pr107985.C | 18 ++++++++++++++++++ 3 files changed, 37 insertions(+), 11 deletions(-) create mode 100644 gcc/testsuite/g++.dg/pr107985.C diff --git a/gcc/gimple-range-op.cc b/gcc/gimple-range-op.cc index 7764166d5fb..c36c49ac1da 100644 --- a/gcc/gimple-range-op.cc +++ b/gcc/gimple-range-op.cc @@ -148,6 +148,9 @@ gimple_range_op_handler::gimple_range_op_handler (gimple *s) case GIMPLE_COND: m_op1 = gimple_cond_lhs (m_stmt); m_op2 = gimple_cond_rhs (m_stmt); + if (!Value_Range::supports_type_p (TREE_TYPE (m_op1)) || + !Value_Range::supports_type_p (TREE_TYPE (m_op2))) + m_valid = false; return; case GIMPLE_ASSIGN: m_op1 = gimple_range_base_of_assignment (m_stmt); @@ -164,6 +167,9 @@ gimple_range_op_handler::gimple_range_op_handler (gimple *s) } if (gimple_num_ops (m_stmt) >= 3) m_op2 = gimple_assign_rhs2 (m_stmt); + if ((m_op1 && !Value_Range::supports_type_p (TREE_TYPE (m_op1))) || + (m_op2 && !Value_Range::supports_type_p (TREE_TYPE (m_op2)))) + m_valid = false; return; default: gcc_unreachable (); diff --git a/gcc/gimple-range.cc b/gcc/gimple-range.cc index ecd6039e0fd..8c055826e17 100644 --- a/gcc/gimple-range.cc +++ b/gcc/gimple-range.cc @@ -422,18 +422,20 @@ gimple_ranger::prefill_stmt_dependencies (tree ssa) else { gimple_range_op_handler handler (stmt); - gcc_checking_assert (handler); - tree op = handler.operand2 (); - if (op) + if (handler) { - Value_Range r (TREE_TYPE (op)); - prefill_name (r, op); - } - op = handler.operand1 (); - if (op) - { - Value_Range r (TREE_TYPE (op)); - prefill_name (r, op); + tree op = handler.operand2 (); + if (op) + { + Value_Range r (TREE_TYPE (op)); + prefill_name (r, op); + } + op = handler.operand1 (); + if (op) + { + Value_Range r (TREE_TYPE (op)); + prefill_name (r, op); + } } } } diff --git a/gcc/testsuite/g++.dg/pr107985.C b/gcc/testsuite/g++.dg/pr107985.C new file mode 100644 index 00000000000..8d244b54efb --- /dev/null +++ b/gcc/testsuite/g++.dg/pr107985.C @@ -0,0 +1,18 @@ +/* { dg-do compile } */ +/* { dg-options "-O1 -ftree-vrp -fno-tree-ccp -fno-tree-forwprop -fno-tree-fre" } */ + +struct B { + int f; +}; + +struct D : public B { +}; + +void foo() { + D d; + d.f = 7; + + int B::* pfb = &B::f; + int D::* pfd = pfb; + int v = d.*pfd; +} -- 2.38.1