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: 1860307 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=WoKopggy; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4SPKJt0PGnz1yQL for ; Tue, 7 Nov 2023 05:15:25 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 55C3F3857835 for ; Mon, 6 Nov 2023 18:15:23 +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-Google-Smtp-Source: AGHT+IEa33Yy38aSWD2MH2eTedgS02CtvuEYFmk3wv51Om4wpSg9AC/qAS097YMdk9120Wp4U22LYg== 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+incoming=patchwork.ozlabs.org@gcc.gnu.org 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