From patchwork Tue Jan 31 20:10:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 51029 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp9641wrn; Tue, 31 Jan 2023 12:11:29 -0800 (PST) X-Google-Smtp-Source: AK7set8Xr2v0X17xsS4oEedOGumyZDcgJQSBMMcQbzLixtFBGfHmFEvQjNUSjbUlWY46J8hL6U3R X-Received: by 2002:a05:6402:1388:b0:4a2:1a65:f0c4 with SMTP id b8-20020a056402138800b004a21a65f0c4mr16773249edv.35.1675195888844; Tue, 31 Jan 2023 12:11:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675195888; cv=none; d=google.com; s=arc-20160816; b=dMl3gjSBbtfuL/PnX8hfXo5hY9JqCIVOl5dqZ0szjgqEkk7Cg4eVRzC83fIQBIb6OS 10dNoEQu1kOQpDbzqirlfk2bJIcnYwDDi4JkciYiBZlA4ow2oq7Dw4A22FJy9osAjrCB /8ckQYuq3YrAhQzGKR2eLqwYFKtm7q4znIz7C9AZoYY1Kkem/B8uk6LrK2B4IhGpkSec 932m9Od0Q+76q4lVEAjYZasEkNgCZiCjtNu+Ei/fD5tS/Q8QhVwTzS3WPYVNbD+xPKCk IPG9lBzRtJ61VqnPn1vZPtwIFeQEnpOqGdc9F5OucjMIjgH8lyzYe2JxOtwD0X0Ir2jA P3Yg== 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=FbYXeIgCkzDFFCFfV1tVOnh4NJMzoX8a1nKW+UQaVnE=; b=F1NDATGPLt8OCYeZV8uu3c2E8vaEB3V4MOBDgaSjd34/dWt/JO1AG3OAVi0/fVDNGk 8TJMZwQSzHCY+AJGiw742TjaLrHFbgg6/xwQmDm50uvCV/qqAk6ibhnmwdd6LYqWlAiX azCp4To5iWeyJg3/QdJFcQzmbGvT3DWAZtsntiVxwgmfX/mAIIhCVtomtsJiuR/jJIlf VreKHiHjUD9oA+Am1uEB//Zcov1wGHMHaPL/HRWlg/zZlH0h+iOFcnSYwSQ4Q8aNz7rH xs5ukoNxvlF7KBEb2tGkbSkJUahNv34N8Qg+xREZZ6fPglxzI43soZiZ7Py87/BYIK35 9GBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="V/zk43Wb"; 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 s9-20020a50d489000000b004a2649708c8si5065498edi.86.2023.01.31.12.11.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Jan 2023 12:11:28 -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="V/zk43Wb"; 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 B6F493858C36 for ; Tue, 31 Jan 2023 20:11:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B6F493858C36 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1675195887; bh=FbYXeIgCkzDFFCFfV1tVOnh4NJMzoX8a1nKW+UQaVnE=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=V/zk43WbvSNe/h7M4M9MB7uHaGriuMZ6EDolEfbSlp65KMYr5pkeIZ4CvrdqPDyXd 6JybPOGs75Z8Ae2haJV0EHjL8jnI8Iao8hw59kfQkSpQPA/XpHcYlvLFzFG3g/1B06 fXd4Ta5FQuvusJ820YjCGBsD2FqecTG2z0gh5Iss= 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 8B67E3858D33 for ; Tue, 31 Jan 2023 20:10:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8B67E3858D33 Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-620-qP_KdCCMNOKhlTxWQbnKdw-1; Tue, 31 Jan 2023 15:10:42 -0500 X-MC-Unique: qP_KdCCMNOKhlTxWQbnKdw-1 Received: by mail-qk1-f199.google.com with SMTP id g6-20020ae9e106000000b00720f9e6e3e2so3533989qkm.13 for ; Tue, 31 Jan 2023 12:10:42 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=subject:cc:to:from:content-language:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=7xVF6YqKn/S21Yut1VWx95sX9Tod3dypcdgrKMpG0j4=; b=E/lttoo1H6hxW/aodapetUWQ3OsxDmK9H7HfM4Rr9A1GiIQKUsDdPNABbW7kG0OF/E JWp0u93slpmx/Ia+Dzdx+ATJSOGBImD8rLHepvcLmsDm7cstbeYSWboYXHLC2eus6aEN jUG9s+iIdYUcN8yjb1ClVFkIWiN83WkSbMlt6V57euE9T0SGiEK3eolMloVQYGYS4V2V 5QuEjc6UWpDpA/VJpY8oI1x34jO/11bBI4sykRn3LD44Fg/zXSxcvw3krSvLOdEP4y0P SDsZQHl7MIp5RwelHw4oLQVM5x7QoaDsJKn4dgXYN6EdwDcWRsGX6XuCpte4u7zUUCy6 rejQ== X-Gm-Message-State: AO0yUKX7ZHxJxUvvwOHGB9it3NMZWyMd3S4lo2PbY4Wfb/+Wp3r1MFc6 NLqBHz6ADLggOXMJxCmTRmQc2BZrzOYNMRiQLrzi7CdDXVaHpWghuqNDVlupM8vVjr4XoeFiyff DLvWXUPlBKdT7aiXLEQeFmy6jAj+h/Zv6nqbDnk9shq2eLjc2e9rwlUKIQ6ksf8EaD9pTHA== X-Received: by 2002:ac8:7d94:0:b0:3b8:5057:377b with SMTP id c20-20020ac87d94000000b003b85057377bmr19919567qtd.65.1675195841932; Tue, 31 Jan 2023 12:10:41 -0800 (PST) X-Received: by 2002:ac8:7d94:0:b0:3b8:5057:377b with SMTP id c20-20020ac87d94000000b003b85057377bmr19919531qtd.65.1675195841595; Tue, 31 Jan 2023 12:10:41 -0800 (PST) Received: from ?IPV6:2607:fea8:a263:f600::fa90? ([2607:fea8:a263:f600::fa90]) by smtp.gmail.com with ESMTPSA id u9-20020ae9c009000000b0072526a43ef7sm2225362qkk.120.2023.01.31.12.10.40 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 31 Jan 2023 12:10:40 -0800 (PST) Message-ID: <4edb00e2-4691-bdd4-1b4d-12e6b9983ad7@redhat.com> Date: Tue, 31 Jan 2023 15:10:39 -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/108356 - Ranger cache - always use range_from_dom when updating. 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?1756570204298515109?= X-GMAIL-MSGID: =?utf-8?q?1756570204298515109?= This turned out to be a more interesting problem than I wanted. the situation boils down to: # g_5 = PHI <0(2), 2(8)>   if (g_5 <= 1)     goto ; [INV] :   if (g_5 != 0)     goto ; [INV]   else     goto ; [INV]   :   c = 0;   :     goto ; [INV]  We globally know that g_5 is [0,0][2,2] we also know that 10->4 , g_5 will be [0,0] Which means we also know that that the branch in bb_4 will never be taken, and will always go to bb 8. THis is all processed in EVRP, the branch is changed, and the next time VRP is called, we blow the block with c = 0 like we want... Unfortunately it doesnt happen within EVRP because when this updated range for g_5 is propagated in the cache, it was tripping over a shotcut which tried to avoid using lookups when it thinks it didnt matter, and would occasionally drop back to the global range. In particular, the cache had originally propagated [0,0][2,2] as the on entry range to bb8. when we rewrite the branch, we mark 4->7 and 7->8  as unexecutable edges, then propagate the new range for g_5..  This requires recalculating the existing range on entry to bb8. It properly picked up [0,0] from 4->8, but when the cache query checked the range from 7->8, it discovered that no value was yet set, so instead of looking it up, it fell back to the global range of [0,0][2,2].  If it properly calculates that edge instead, it comes up with UNDEFINED (as it is unexecutable) and results in [0,0]... and EVRP then also removes the block is c = 0 in. By picking up the global value, it still thought 2 was a possibility later on, and a single VRP pass couldn't eliminate the branch ultimately leading to the store... it required a second one with the adjusted CFG to catch it. This patch tells the cache to always do a read-only scan of the dominator tree to find the nearest actual value and use that instead.  This may solve other lingering weird propagation issues. I also ran a performance run on this change. It does slow VRP by down about 1%, but the overall change is nominal at around 0.05%. Bootstraps on x86_64-pc-linux-gnu with no regressions.  OK? Andrew From ddb9df254ed2bc5f11bdde213e1485d7971a25d9 Mon Sep 17 00:00:00 2001 From: Andrew MacLeod Date: Tue, 10 Jan 2023 13:40:56 -0500 Subject: [PATCH] Ranger cache - always use range_from_dom when updating. When updating an existing range, if we dont query the dom tree, we can get the global range instead of a proper range on some incoming edges which cause the range to not be refined properly. PR tree-optimization/108356 gcc/ * gimple-range-cache.cc (ranger_cache::range_on_edge): Always do a search of the DOM tree for a range. gcc/testsuite/ * gcc.dg/pr108356.c: New. --- gcc/gimple-range-cache.cc | 2 +- gcc/testsuite/gcc.dg/pr108356.c | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/pr108356.c diff --git a/gcc/gimple-range-cache.cc b/gcc/gimple-range-cache.cc index a8202f0e895..20c444bc4f4 100644 --- a/gcc/gimple-range-cache.cc +++ b/gcc/gimple-range-cache.cc @@ -998,7 +998,7 @@ bool ranger_cache::range_on_edge (vrange &r, edge e, tree expr) { if (gimple_range_ssa_p (expr)) - return edge_range (r, e, expr, RFD_NONE); + return edge_range (r, e, expr, RFD_READ_ONLY); return get_tree_range (r, expr, NULL); } diff --git a/gcc/testsuite/gcc.dg/pr108356.c b/gcc/testsuite/gcc.dg/pr108356.c new file mode 100644 index 00000000000..1df6b278e45 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr108356.c @@ -0,0 +1,23 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-optimized" } */ + +char a; +static char c = 3; +char d; +void foo(); +short(b)(short e, short f) { return e + f; } +int main() { + unsigned g = 0; + if (c) + ; + else + foo(); + for (; g < 2; g = b(g, 2)) { + d = g ? 0 : a; + if (g) + c = 0; + } +} + + +/* { dg-final { scan-tree-dump-not "foo" "optimized" } } */ -- 2.39.0