From patchwork Mon Nov 6 18:15:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 162108 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:8f47:0:b0:403:3b70:6f57 with SMTP id j7csp2840779vqu; Mon, 6 Nov 2023 10:15:36 -0800 (PST) X-Google-Smtp-Source: AGHT+IH+d+Q3ksZdOYW4Ck5kRr0TWMHSty7FV+HicxjRdH1JS1r5evOFkmnMbzCfKnDN6WxhJRyE X-Received: by 2002:a05:6808:1898:b0:3a4:225d:8135 with SMTP id bi24-20020a056808189800b003a4225d8135mr38132627oib.31.1699294536256; Mon, 06 Nov 2023 10:15:36 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1699294536; cv=pass; d=google.com; s=arc-20160816; b=F2e3CCqD6Vgrr38ZYYpw5LRFsIePXkVtT0GTzyQCrxLTgr+xl6h3HuP7+AZ8OYzk50 PkB2Z66QyB6o5JY4/UFc9LUHmZ8diCGFVnFnfLHBzeLTSnkG0xG+6ekGJqSqkxz9kEE5 Wt4CLoRvHGMyS6vdKEp+maOcVrtRO43wfl/zkKOCpq3iw6Sh/DhLt09twTK6ZUNdpm99 9PqfPIovy0RJIdzuVSG4x2iOvg19VEPrSF2PbhwfLUJHpuTix+1Eoh/bFU4pGAhZ07Yu KjGhstwsLwJgTFspvqEhPppz8wQ5DIiCa5HcDdnppvpwfVbvVm+lhxW/gCG7F8zo8kJv 3STw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-language:subject:from :to:user-agent:mime-version:date:message-id:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=iEtCftu8RbcoBU8PXAwFGjGNvO9LXBFPVkkbbpc2W4Q=; fh=8G0fvw9kezX2+yjwifXgHvTII1omy92vRpR1R+rFCOA=; b=ShtrV0CMEvhWf/DszAqNezgQ4Xam/sq+/726V4Ke8bOXw7yaR7yrneskJy/7kGrUHA naF+odOaUL1EOOswSgurGt0uMz20ZfHiSAYdZzx3awqxkqQUdyyiR0/ja4SZusR9k9/Q nQI6LaTtzgmMAIWd9hwcMNbiK9CbF/A5A2VWzaVPL2Iz52T2ZlGQRptxHSbBLV/EnMc6 PmHZuFVq7aWzTaSfFZuMo+d8UhHYPE9YXDibDwp+MhGnvHnm2C0xrsRv00Qghf9TpS/B 3PEUvPv2rYoPZ9J/vM975FCqITxRTIm1Gf5ZIPyEuZlS8GGE5Gvyrg3IHFN5+P0JgqOc WESg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=WoKopggy; arc=pass (i=1); 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=redhat.com Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id c19-20020a056214071300b0067088804691si6129181qvz.549.2023.11.06.10.15.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 10:15:36 -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=@redhat.com header.s=mimecast20190719 header.b=WoKopggy; arc=pass (i=1); 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=redhat.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id EE938385841A for ; Mon, 6 Nov 2023 18:15:35 +0000 (GMT) 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 301183858D33 for ; Mon, 6 Nov 2023 18:15:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 301183858D33 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 301183858D33 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699294513; cv=none; b=J7JmEwig4xYGxk51uMlxxuFP3SUnZWVLbDx/lw3+BOMHT+MBnHh+KXHYXMHXZZ7NSnx1PBD0rmcfQWjRHFDeP7wPE/ScaPfZc4tfgEBTORe2qMTz90AHATydRVtPBOcj54AavFFgX0FVYwPLj0zh2ge9hprwnFK3W44pwaO2M80= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699294513; c=relaxed/simple; bh=otFDLfDJI0old+JMmdLoZ13HaNssPNMoiUQEBowNRw8=; h=DKIM-Signature:Message-ID:Date:MIME-Version:To:From:Subject; b=LAF8TFFIM1go0bZGlv78xpf3KzAKsMF5vgl7qmV7Wsn8n57FxY5j6GWxaQpN0BXvH05B5PzPXKuOGkdtHDjlzWqrfPnXJfm59Xg06evVHHCPCZ0NRep2ZLYxVULJqh6zlzMxyAddcQ/NEyhFvaaksEW3opqDAPF8G7B3RG1ULbY= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1699294511; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type; bh=iEtCftu8RbcoBU8PXAwFGjGNvO9LXBFPVkkbbpc2W4Q=; b=WoKopggyynbmPol5+ctcmU+L5OkgRM4kVCm/+Ee8x/zcUcAUzb8scINkl8XsVw6q6JE/5R g1eJwks38ry0sp5s8SGyormYIpt6+JnvaccT76X9yAmEP7jHv2aOO48C2OPmOyOeJJWvYP gsHiY+UUPAH6974LmTUx+utEtGWjQsU= Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-167-6nCNZ5bvNoqMTsQKcd8yMQ-1; Mon, 06 Nov 2023 13:15:10 -0500 X-MC-Unique: 6nCNZ5bvNoqMTsQKcd8yMQ-1 Received: by mail-qv1-f69.google.com with SMTP id 6a1803df08f44-66d0b251a6aso58304126d6.2 for ; Mon, 06 Nov 2023 10:15:10 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699294508; x=1699899308; h=subject:from:to:content-language:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=rVtjmFjhNUNRrmqYQxUynD8n2FvWMnALSUJjGkgm16c=; b=BSjd5gR6O3zbfC3DqsDMD5InzAllUqpKcA0RdGVc8nFNmny+PpoLwoORHgb68UmUJo /Ca3zzJCuYfmIQR/3C09QXzP7CjtpA4Z1zQdniIhaqFp13tVrs1zFmP1A1P0J0WqFaTy x+Hcy+4pTd4BfSN5lWAb6K++Uq7Vtk/B1aGpPVbhPscteDq4/Rey5+ejaMx0nONG+SE3 k/6BFVYgRkSyxAugfsGa/RpGEwzy6gD5zgmToHqGpUFc2tVjU1aoKXhOoGWZbwU+kE2M Nvsrd8XDT8sZEugxXMHjE6BwHN7y4V9UgC/0kzBhJBxmt3zh+TQAJ3QtbdQlfF+9VuKC XbWg== X-Gm-Message-State: AOJu0YweGSjZQFuBUcf1A+8a57iG667QMX397JICkYiv464Y23DyHmOc VrUpPPTtKniP8+gWCSOnN2bRCtE5YBJ0EM0dmPnoDkvN1KjK54VIqrnEPPp4b0sMJRNSGKXAUiF P8BOo3s5SKS5xALcgxSqhbLIAlwbgohJdffJOtl9tpz4rxe79xTO7MwMzKxM1qKaxyak+OUi3xu RHDw== X-Received: by 2002:a05:6214:cae:b0:66d:23e4:2ce8 with SMTP id s14-20020a0562140cae00b0066d23e42ce8mr34908247qvs.7.1699294508643; Mon, 06 Nov 2023 10:15:08 -0800 (PST) X-Received: by 2002:a05:6214:cae:b0:66d:23e4:2ce8 with SMTP id s14-20020a0562140cae00b0066d23e42ce8mr34908229qvs.7.1699294508367; Mon, 06 Nov 2023 10:15:08 -0800 (PST) Received: from ?IPV6:2607:fea8:51dd:2b00::18c7? ([2607:fea8:51dd:2b00::18c7]) by smtp.gmail.com with ESMTPSA id gb7-20020a05622a598700b00418189b689csm3658510qtb.10.2023.11.06.10.15.07 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 06 Nov 2023 10:15:07 -0800 (PST) Message-ID: Date: Mon, 6 Nov 2023 13:15:06 -0500 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird To: gcc-patches From: Andrew MacLeod Subject: [PATCH][GCC13] PR tree-optimization/105834 - Choose better initial values for ranger. X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US X-Spam-Status: No, score=-12.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_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1781839467698339363 X-GMAIL-MSGID: 1781839467698339363 As requested porting this patch from trunk resolves this PR in GCC 13. Bootstraps on x86_64-pc-linux-gnu with no regressions.  OK for the gcc 13 branch? Andrew From 0182a25607fa353274c27ec57ca497c00f1d1b76 Mon Sep 17 00:00:00 2001 From: Andrew MacLeod Date: Mon, 6 Nov 2023 11:33:32 -0500 Subject: [PATCH] Choose better initial values for ranger. Instead of defaulting to VARYING, fold the stmt using just global ranges. PR tree-optimization/105834 gcc/ * gimple-range-cache.cc (ranger_cache::get_global_range): Call fold_range with global query to choose an initial value. gcc/testsuite/ * gcc.dg/pr105834.c --- gcc/gimple-range-cache.cc | 17 ++++++++++++++++- gcc/testsuite/gcc.dg/pr105834.c | 17 +++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/pr105834.c diff --git a/gcc/gimple-range-cache.cc b/gcc/gimple-range-cache.cc index e4e75943632..b09df6c81bf 100644 --- a/gcc/gimple-range-cache.cc +++ b/gcc/gimple-range-cache.cc @@ -846,7 +846,22 @@ ranger_cache::get_global_range (vrange &r, tree name, bool ¤t_p) || m_temporal->current_p (name, m_gori.depend1 (name), m_gori.depend2 (name)); else - m_globals.set_global_range (name, r); + { + // If no global value has been set and value is VARYING, fold the stmt + // using just global ranges to get a better initial value. + // After inlining we tend to decide some things are constant, so + // do not do this evaluation after inlining. + if (r.varying_p () && !cfun->after_inlining) + { + gimple *s = SSA_NAME_DEF_STMT (name); + if (gimple_get_lhs (s) == name) + { + if (!fold_range (r, s, get_global_range_query ())) + gimple_range_global (r, name); + } + } + m_globals.set_global_range (name, r); + } // If the existing value was not current, mark it as always current. if (!current_p) diff --git a/gcc/testsuite/gcc.dg/pr105834.c b/gcc/testsuite/gcc.dg/pr105834.c new file mode 100644 index 00000000000..d0eda03ef8b --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr105834.c @@ -0,0 +1,17 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-optimized" } */ + +static int a, b; + +void foo(); + +int main() { + for (int c = 0; c < 2; c = c + (unsigned)3) + if (a) + for (;;) + if (c > 0) + b = 0; + if (b) + foo(); +} +/* { dg-final { scan-tree-dump-not "foo" "optimized" } } */ -- 2.41.0