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: 30933 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp289799wrr; Wed, 7 Dec 2022 08:45:17 -0800 (PST) X-Google-Smtp-Source: AA0mqf52SRfBjyvyHoRxeujN6jmypSKlsmVvJva2SotIYPuN2VcKNJukOq3g3TxGDpAvHOvSX4c7 X-Received: by 2002:a17:906:688f:b0:7c0:ced7:7c99 with SMTP id n15-20020a170906688f00b007c0ced77c99mr18085481ejr.401.1670431517061; Wed, 07 Dec 2022 08:45:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670431517; cv=none; d=google.com; s=arc-20160816; b=NzMx1Ss4sm/1IcNQtQeow1gdHcwQF7Y1ZEI7WTgcK0Q3yNL+HuLXOgPU/ZQIryWl1T zS4xJHuLFWZZpNZ3GQ+gstL/JqvcSQdmNWY1Obf9+bS1wxGz+pGOWINCiHOzd5iUbVdY JiuFptxXZtBuUiQpoamN9jXr1z6XE+ed8lh5ZXtW0euMrojFFmqe27EpBA63+7asr4cp 3O1PwFrBTgxBQS1/3TqLQxPBrPLJUlJRx2ZKfOwClZVcBohh8KW+hdPHk82VSHVtwjZH vqBtwQWMHFKVfz+LykTby0EgN4aDSA0ItmvIGoiE62dkvJ/k7AcmMeH1/Knjkx2+3VLk SNug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:content-language :subject:cc:to:user-agent:mime-version:date:message-id:dmarc-filter :delivered-to:dkim-signature:dkim-filter; bh=Xc0mV1Z60tNP4w1L5E9vUFxMBrQVvOfwjoxt//+lGmc=; b=TiQMWw8n5SmzziDPjFtSKrnp4XavkldmNCg7SwPf8MVTKKasHib2qPOFNk8hQP0cGH fn6tJz8PJkSy9RfYqBD6NLZqCaWFJVMTcJdQcShil49V+77M1TsVg7A0z/RAOHALrX4y YfUVe3kJqvXdGjSsCC/BTaTjwSbBZdQdoJiALI9oAqxitpNGVxxqhJCC3R/D7Duvg0AH zPpxIn96SlyirvhosDt31QylRTCscq+iX0a9JUy2frG8n2xlsP3Olij6oGUnVYQM5kGB LiX3AL00eZSUEqVTOo/LGx21kouCaiIDYGjEZLGPtMsTvIl0n8aYpE0AGnKZErv7hp7v SrHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=i0zdQj3Y; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id dp21-20020a170906c15500b007c0b777d1c0si15287527ejc.737.2022.12.07.08.45.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Dec 2022 08:45:17 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=i0zdQj3Y; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 75A6B392B14F for ; Wed, 7 Dec 2022 16:45:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 75A6B392B14F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1670431501; 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=i0zdQj3Ytv2eIAMstIsL1znsbBlMlKYoSHrr/uMDF14GrAV3fdkxsPJzVi9NEXf1d vYPfUIb7VDViZI41t05r/Va12c7RZMDe+ZKWvFqSW+h/keokYapEajwyY8V/8qp9q4 eeU1mvOhHf3gS9N0dGqqDfxTLdlRWbepd0+ovAYI= 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-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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1751574398173869328?= X-GMAIL-MSGID: =?utf-8?q?1751574398173869328?= 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