From patchwork Wed Feb 1 18:11:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 51501 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp429103wrn; Wed, 1 Feb 2023 10:12:26 -0800 (PST) X-Google-Smtp-Source: AK7set9NifoW8Pw7IbxcZ4el5Q1OVFHyMhhUcU72BzEC38II38ztzu/QoY03jqcUTkT5fFP2slxL X-Received: by 2002:a17:906:cc8f:b0:889:d998:1576 with SMTP id oq15-20020a170906cc8f00b00889d9981576mr3680986ejb.66.1675275146209; Wed, 01 Feb 2023 10:12:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675275146; cv=none; d=google.com; s=arc-20160816; b=Jj6jjvr887WLNhprhB1zoENkKWOLpQwArkW5A0bo4Zy4BKqamxqQQkb3adFM7igAYU upaNgBBpPtLQoaWYzoZglLmmnmYHFpk2u5tStADHs4sv2IJ2CSvT7ddznHl84KRIuoF3 GgAOMH2HtN14yKcp7h7EalBwvYauAvOxz4H33o3sr7EaBlPQl/T2bxtLCynMX2YBK2a7 ZrBfIijC6oqSZtPm4UkGsYheVB2cp573PIevS4Uuy0d8hQdFUbpNqKAkIEXRGEx6TL/T mvUzfYwlkKg7SGBTj0rfh+5lUGrDVxOJtPbwbAm7FFfLjPRf+dJstzZ3zozQ2T05EhJ3 l/Vw== 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=wYLYIlcDWxgJEWqSkqv6JRjWODWmWSTuFtvtxDE/hK0=; b=vzq+iTDkF5bGwrbCvKJMHYZi7Gm47Zsxw4cVUydBZ3r/jEqGaYYuZaDG1gtlaIm3wL h0x+z8oXX66HPZIdTtrLQfmgqvul/+Oaubtbax4bWfdLDb6WEY4RljlwmUKV85iqnvBR T0VxVJDRUsb0RyGUmDpXmJbmBjN6R/nw0zhrtS7utdHMqpcF0RFBPiZ3U4OfAZCjJLl4 1ME4aZRIT7oRvNaOqcizk54SzxDJl7azZiyb3CFkedFIkiKxm07Bh7vS4HBpfoQnTd7K rW6G2CJf2Tp9CVjXSaPBAY23QcWNQ/tKhB7IPLX8be5tANg8kCZTo+vhErTINwtP7mmO GZ+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=IPy5u24L; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id vl16-20020a17090730d000b00889a7745914si6274523ejb.176.2023.02.01.10.12.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Feb 2023 10:12:26 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=IPy5u24L; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 7F7653858C2D for ; Wed, 1 Feb 2023 18:12:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7F7653858C2D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1675275137; bh=wYLYIlcDWxgJEWqSkqv6JRjWODWmWSTuFtvtxDE/hK0=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=IPy5u24L2odI2ncIuW52TVZqlVK5+G4jDe4MinmwGngyUMhdspZdmL3BXDrPqdEQj TxWLxRcJTf42NByAMuM7KF2/BlAWYvNKn7Xs/hFojIoZeWF0Suf1T7oVVBFYFnfdtS VlPTYGFs0oNGq23+I1GsF2xpzMnMjOj9RZp/9JF4= 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 422223858D33 for ; Wed, 1 Feb 2023 18:11:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 422223858D33 Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-580-Hu9b7h_NNKKsd1CuBVoqWg-1; Wed, 01 Feb 2023 13:11:30 -0500 X-MC-Unique: Hu9b7h_NNKKsd1CuBVoqWg-1 Received: by mail-qk1-f198.google.com with SMTP id bj31-20020a05620a191f00b0072ad2273eafso646653qkb.16 for ; Wed, 01 Feb 2023 10:11:30 -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=nWFdXRx00Ho3Y7jMSYE91sR+RJRDSrqY12FC19MrpBQ=; b=jn73nqJxIEyhryjtQdrbxJAn3gpD6jmhQZ56LpAgkey680zNYepZa0hs8bsPv93avz Xy+Tjj8OAhXrO4/Lg+dzXafiX4kWmQCQVwdtslj2lU0InnCl81VpRun/nIkY75qVIEc3 hROoO8w6i3D+G35ErOT3OufnzY80jhUkGS3pcaeDAnPQUD4DmaYY/HpaHaul7dT7eDQz 8EOoaJ82eIRE4NCmVSFPz62+C90YPWUWe09jK1unVdexcarK1whbgdiPmYgyzjLVFo2m eOhoC8zr550GQ4cDGggj42GBSl6H13ukCJCEnd8oFASAOsfSCkqhO1TfB0m+Mbi7eU3H vUBw== X-Gm-Message-State: AO0yUKUsyr5Q8Ldj+EZFaygomc+68Dl3nhVGSKWLbQZIBKH6uikZzSSD yHzMb0PT9BfQmdSYTVeaAU3nWAdFuDU8XRLtFqPAXKZiv75K5bc7DeVMlbiEsb9Uy8/3Sl4yKID ObUmx1F/aZ5FRFrfn4ABLSmU0ELHS0f+jOMqxL3rFJhuW9k25lLuQpjFUZEiS2YrSr4soqw== X-Received: by 2002:a05:6214:5442:b0:537:6bc5:6c3b with SMTP id kz2-20020a056214544200b005376bc56c3bmr5751734qvb.30.1675275089430; Wed, 01 Feb 2023 10:11:29 -0800 (PST) X-Received: by 2002:a05:6214:5442:b0:537:6bc5:6c3b with SMTP id kz2-20020a056214544200b005376bc56c3bmr5751708qvb.30.1675275089169; Wed, 01 Feb 2023 10:11:29 -0800 (PST) Received: from ?IPV6:2607:fea8:a263:f600::fa90? ([2607:fea8:a263:f600::fa90]) by smtp.gmail.com with ESMTPSA id s27-20020a05620a081b00b0072ad54e36b2sm605757qks.93.2023.02.01.10.11.28 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 01 Feb 2023 10:11:28 -0800 (PST) Message-ID: Date: Wed, 1 Feb 2023 13:11:27 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.6.0 To: gcc-patches Cc: "hernandez, aldy" Subject: [PATCH] PR tree-optimization/107570 - Reset SCEV after folding in VRP. X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US X-Spam-Status: No, score=-12.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?1756653311236725091?= X-GMAIL-MSGID: =?utf-8?q?1756653311236725091?= We can reset SCEV after we fold, then SCEVs cache shouldn't have anything in it when we go to remove ssa-names in remove_unreachable(). We were resetting it later sometimes if we were processing the array bounds warning, so I removed that call and just always reset it now. Bootstraps on x86_64-pc-linux-gnu. Testing running. Assuming no regressions,  OK for trunk? Andrew From 450b058445ffb0a1ffbdec08732d4267f03a8ce5 Mon Sep 17 00:00:00 2001 From: Andrew MacLeod Date: Wed, 1 Feb 2023 11:46:18 -0500 Subject: [PATCH] Reset SCEV after folding in VRP. SCEV needs to be reset to processing array bounds in VRP, but it should also be reset before trying to remove unreachable globals so it's cache doesn't cause issues. PR tree-optimization/107570 gcc/ * tree-vrp.cc (execute_ranger_vrp): Reset SCEV after folding. gcc/testsuite/ gcc.dg/pr107570.c: New. --- gcc/testsuite/gcc.dg/pr107570.c | 25 +++++++++++++++++++++++++ gcc/tree-vrp.cc | 6 +++++- 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/pr107570.c diff --git a/gcc/testsuite/gcc.dg/pr107570.c b/gcc/testsuite/gcc.dg/pr107570.c new file mode 100644 index 00000000000..ba5b535a867 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr107570.c @@ -0,0 +1,25 @@ +/* { dg-do compile } */ +/* { dg-options "-Os" } */ + +long int n; + +void +foo (int *p, int x) +{ + for (;;) + { + for (*p = 0; *p < 1; ++*p) + { + n += *p < 0; + if (n < x) + { + while (x < 1) + ++x; + + __builtin_unreachable (); + } + } + + p = &x; + } +} diff --git a/gcc/tree-vrp.cc b/gcc/tree-vrp.cc index 3c431760a16..0b69374adba 100644 --- a/gcc/tree-vrp.cc +++ b/gcc/tree-vrp.cc @@ -1096,6 +1096,11 @@ execute_ranger_vrp (struct function *fun, bool warn_array_bounds_p, gimple_ranger *ranger = enable_ranger (fun, false); rvrp_folder folder (ranger); folder.substitute_and_fold (); + + // SCEV needs to be reset for array bounds, and we do not wish to trigger + // any SCEV lookups when removing unreachable globals, so reset it here. + scev_reset (); + // Remove tagged builtin-unreachable and maybe update globals. folder.m_unreachable.remove_and_update_globals (final_p); if (dump_file && (dump_flags & TDF_DETAILS)) @@ -1116,7 +1121,6 @@ execute_ranger_vrp (struct function *fun, bool warn_array_bounds_p, else e->flags |= EDGE_EXECUTABLE; } - scev_reset (); array_bounds_checker array_checker (fun, ranger); array_checker.check (); } -- 2.39.0