From patchwork Thu Aug 22 19:15:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Law X-Patchwork-Id: 1975725 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=V0VUJ8Qs; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; 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 [8.43.85.97]) (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 4WqXwQ4DFlz1yYZ for ; Fri, 23 Aug 2024 05:15:30 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1FD8D3871020 for ; Thu, 22 Aug 2024 19:15:29 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by sourceware.org (Postfix) with ESMTPS id B8F6E3871035 for ; Thu, 22 Aug 2024 19:15:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B8F6E3871035 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org B8F6E3871035 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::334 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1724354108; cv=none; b=UGiiiZbnDFnItXIBQ6qJhV5AIv2M2W6rDR1I5qrl0RKzs4AG201B9fb4zuUWGgc2nqiTPqUMEFAO77GTpCjJJpJnS/Qv6DSYe2Y1+SMjjj3C6XUW7weWkp2Q09562tY2DYLz07UIhnlcCtndbnaZk8af7l+KXTFZj1sImVKxRM8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1724354108; c=relaxed/simple; bh=Xrx788gXBQxURBzptVeVmtHoFHW8QFkejJeVU0gpjik=; h=DKIM-Signature:Message-ID:Date:MIME-Version:From:Subject:To; b=McQRKcRYDkW/4Gq/zBiZ9h2T7MKQEDV1346wW9Ts5ZF5E2NGzPpqX/K6hmk9K3BKs6UBUaw/hRIXGxZQ1fZ8VP8tEaQx6STP3GH7v4gDqXoYCWuzYhIazMCJYQ/vjkQf+fbTdR9H18dmKbIOtGxqwShqkwmUh1sw66YkmbmPAnw= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-428fb103724so12259715e9.1 for ; Thu, 22 Aug 2024 12:15:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724354105; x=1724958905; darn=gcc.gnu.org; h=to:subject:from:content-language:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to; bh=CH/FvRjAa6QBjCImSONn+7TvaeAG4diOeB4vfQeWaQg=; b=V0VUJ8QswXXzjQVNI+eUY3cqusYYFzYB4lha2Y3fn8CSwUW/f/uT5iAfNvETVtBsmC DqUAYKIS/MhaidqbPdx5/PnzwoX7IDWoxyPYnCzuIkrKGorszkV8KlLRck5Zep0N0XNL awTJEaWnG70PEAyBIuZ4BmLk6ZdjiWsQJsQ7iCSbC/xH3ME7THhzwe5qB8pkHTYgRhRy 8arkAqc4zJuJrY3C1praI6H/Kb1n7i81df/TIyK/sttOEy+Ymfq3wU2aqUtYw2ogMip/ tHMnopxV9RTYXUn9SSBW7uY5RdjAigOYh1jT+nnChUJp1jvk8MUfJCcMSMysN3O5obi7 rWWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724354105; x=1724958905; h=to:subject:from:content-language:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=CH/FvRjAa6QBjCImSONn+7TvaeAG4diOeB4vfQeWaQg=; b=uSWYTkZrmbR5fdeEf9tOn5sf1S5ZHMdvU5ZYNWPbtAgr0ollRa8GuMwifbmOVRWZnH Opxmm+II3Las2Xwnn44lfADvh4vlq2e9IDk6WwC8wrEz+0aZD3Jav7GXyLlFf1uv/hcm CqWGpxMyHxfn5Zss2MXHVhS6Idc3lcg225Qwg4i+7lSBL+0YpAslAuuzkKwCd/m1HKEu 6F8ynz6EKeuvFI8CPCG4nEjL/1xtwxtBlnZMcGLabKb41QRueJyS4uTgk5thsALsC1zh PNBVYTMhk5C6+BkHqek7uNsXCAJodm4ssLjB4bQab5MDDxihwPQ6B6YrsxuDoUjYeCcG WwSA== X-Gm-Message-State: AOJu0YwxfHHHXPZrdNFs6/priWVNUpGGlu1Da/QOdm7cIP5jSaq28GFo qOp+mOZjsQ0c+AHE2zsBQUBokykjoCV12/4h5iBDmFdKuTcoUFGwb+pMojxY X-Google-Smtp-Source: AGHT+IGu+tpOusTn9/4OJcjKAtJLFkP2jLux+TnVpqo12URUhc22SoVg+SH8nsyYbqNCLWIj7Amcsg== X-Received: by 2002:a05:600c:3b12:b0:426:698b:791f with SMTP id 5b1f17b1804b1-42ac388e543mr20530555e9.3.1724354104768; Thu, 22 Aug 2024 12:15:04 -0700 (PDT) Received: from [172.31.0.109] ([136.36.72.243]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42ac5162322sm33063045e9.24.2024.08.22.12.15.03 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 22 Aug 2024 12:15:04 -0700 (PDT) Message-ID: <7974bac7-b125-40f3-aec1-ce233a216f29@gmail.com> Date: Thu, 22 Aug 2024 13:15:02 -0600 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Beta Content-Language: en-US From: Jeff Law Subject: [committed][PR rtl-optimization/116420] Fix interesting block bitmap DF dataflow To: "gcc-patches@gcc.gnu.org" X-Spam-Status: No, score=-8.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, 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 The DF framework provides us a way to run dataflow problems on sub-graphs. Naturally a bitmap of interesting blocks is passed into those routines. At a confluence point, the DF framework will not mark a block for re-processing if it's not in that set of interesting blocks. When ext-dce sets up that set of interesting blocks it's using the wrong counter. ie, it's using n_basic_blocks rather than last_basic_block. If there are holes in the block indices, some number of blocks won't get marked as interesting. In this case the block needing reprocessing has an index higher than n_basic_blocks. It never gets reprocessed and the newly found live chunks don't propagate further up the CFG -- ultimately resulting in a pseudo appearing to have only the low 8 bits live, when in fact the low 32 bits are actually live. Fixed in the obvious way, by using last_basic_block instead. Bootstrapped and regression tested on x86_64. Pushing to the trunk. jeff commit c9377734b798d8d311dfd3a5618dc49407703b93 Author: Jeff Law Date: Thu Aug 22 12:48:49 2024 -0600 [PR rtl-optimization/116420] Fix interesting block bitmap DF dataflow The DF framework provides us a way to run dataflow problems on sub-graphs. Naturally a bitmap of interesting blocks is passed into those routines. At a confluence point, the DF framework will not mark a block for re-processing if it's not in that set of interesting blocks. When ext-dce sets up that set of interesting blocks it's using the wrong counter. ie, it's using n_basic_blocks rather than last_basic_block. If there are holes in the block indices, some number of blocks won't get marked as interesting. In this case the block needing reprocessing has an index higher than n_basic_blocks. It never gets reprocessed and the newly found live chunks don't propagate further up the CFG -- ultimately resulting in a pseudo appearing to have only the low 8 bits live, when in fact the low 32 bits are actually live. Fixed in the obvious way, by using last_basic_block instead. Bootstrapped and regression tested on x86_64. Pushing to the trunk. PR rtl-optimization/116420 gcc/ * ext-dce.cc (ext_dce_init): Fix loop iteration when setting up the interesting block for DF to analyze. gcc/testsuite * gcc.dg/torture/pr116420.c: New test. diff --git a/gcc/ext-dce.cc b/gcc/ext-dce.cc index 35c06469b82..4a2503f1831 100644 --- a/gcc/ext-dce.cc +++ b/gcc/ext-dce.cc @@ -988,7 +988,7 @@ ext_dce_init (void) all_blocks = BITMAP_ALLOC (NULL); changed_pseudos = BITMAP_ALLOC (NULL); - for (int i = 0; i < n_basic_blocks_for_fn (cfun); i++) + for (int i = 0; i < last_basic_block_for_fn (cfun); i++) if (i != ENTRY_BLOCK && i != EXIT_BLOCK) bitmap_set_bit (all_blocks, i); diff --git a/gcc/testsuite/gcc.dg/torture/pr116420.c b/gcc/testsuite/gcc.dg/torture/pr116420.c new file mode 100644 index 00000000000..9a784f59429 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr116420.c @@ -0,0 +1,17 @@ +/* { dg-do run } */ +/* { dg-additional-options "-fno-forward-propagate -fno-tree-ch" } */ +int a, d, e; +char b = -1, c, f; +int main() { + int g; + for (; d < 1; d++) { + g = b; + for (; c; c = g) + ; + } + f = g; + for (; e < 1; e++) + if (g >= a) + __builtin_abort(); + return 0; +}