From patchwork Mon Jul 22 14:47:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Law X-Patchwork-Id: 1963279 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=UyiArLPA; 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 4WSNRQ27d6z1yZ7 for ; Tue, 23 Jul 2024 00:47:29 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0B59D385DDDE for ; Mon, 22 Jul 2024 14:47:27 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-oo1-xc2f.google.com (mail-oo1-xc2f.google.com [IPv6:2607:f8b0:4864:20::c2f]) by sourceware.org (Postfix) with ESMTPS id 8D137385DDDE for ; Mon, 22 Jul 2024 14:47:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8D137385DDDE 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 8D137385DDDE Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::c2f ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1721659629; cv=none; b=UisT+2fEQ4jzcKCvHHc1KHQO1az7ipmyy6bxVe59SRp7bMY2W0ci4croJ2TpwulbUAAlWFVKIA1+fN3jLC6wEVoraIVvjIqDlUJD823RND4ftjluwq8TH6NUUBJwEUHxfsmIA3utvEDKeZx9hp0xaMsExMoX//B9dbm0jW1BYqE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1721659629; c=relaxed/simple; bh=TGGGDO8ELwpTnAnefNvpI0BGXWJUq1evpX5DuVjIdDg=; h=DKIM-Signature:Message-ID:Date:MIME-Version:From:Subject:To; b=B4UrV1beyz8/IdluP9OQgY8V0JJtCfzI/L33Nx20mlsHgZ3nwzA6/ZxQb5/F/haLSXVbS2/s4k7Jg6niiFc6GgHDp72OC0F9yQZrfnToogo4FLGae2u+/9x4UPmvFdtVRFhPKlRjfg/JvK/R1fiqfpVPypDa7Ah/CI9uUgaE5Co= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-oo1-xc2f.google.com with SMTP id 006d021491bc7-5d5846f797aso272574eaf.0 for ; Mon, 22 Jul 2024 07:47:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721659625; x=1722264425; 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=yP4gXKqK71xAQajn2+B3DHd7bERNRSfP7T/0tJxGKgU=; b=UyiArLPA+QGOAUZgJuUCTmsU7t/IOei8b0F7mewDwDyAbYuHfct+uOJSNHgBW7dYBK UyZ5UYP5hFNS/0CjoCQeszcEhW8+gLV45518g5dRStF9akL9bW7NFoLTcp8OI/slnAYh mDfPVLAEzQyjBdI49vGiVQdaXs56Ipzvo+qMjHzTn51UhdnqNZ6q5My5beqyUUaxjdgq WFi/SLQx6GjyX3gOV6VD7VwExvIYsyakWwesTTnaJlXe55fAHl9xVKtHI5soyZsGwPbR RjriM2eucaGYF+hjK1HheWqTYoKciTkhD5CFPS51XfQD9UIrubdswrJCU4y2XDkr+CHm AANQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721659625; x=1722264425; 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=yP4gXKqK71xAQajn2+B3DHd7bERNRSfP7T/0tJxGKgU=; b=qUMTRpdHbV/WYnFrnjoS2rn7iDzQ0wN4k9K6Yn1v1UbptlUIvy+lNm0JxEX/UkX+kq sY5PgF7o43aQ/UDAaN8MBqHWqtNS7DPdp3NvHOq/6qwpbgWGDcb1JSfRTbizccpZQDCp aIz7ivvUYLUZ4RRjsnI3+hX+gk0nEeeK14b2zwVIjN/afP2kEkoujaCzbkz+HoBwbxsI BWvCCNcKWpPmYsNRvSFGN/WrP3fUIib1wJRey0zVbjGA7/M1PUv6KL1MsxBbmJqNqoFt BcORlT4zwcbXqOeGH827X1RY9SwJYwLaU7qs28FZsyZYqQq0n0vILtS+FGnO3+Vjl6am vjYw== X-Gm-Message-State: AOJu0Yz9qGnqhOAQFzG2U2pUgz4e5mEj6arUhFLpVwxCcALMtiO6Ptyp 3dXAmmB1g1WOLWhSZUVbCqpt2+PMLfGG0JSRzQFvshoQUkKh+pqW6FO1Dg== X-Google-Smtp-Source: AGHT+IGtpbcNaG2kGu5cDJsWjFvcMoqMEIV+YTDm1sQyoGy0eyeEuoSPbbTDCu7FBWVDf0WrHUEiIQ== X-Received: by 2002:a05:6870:d1c4:b0:261:228d:6d82 with SMTP id 586e51a60fabf-2638df37c06mr6420772fac.19.1721659625041; Mon, 22 Jul 2024 07:47:05 -0700 (PDT) Received: from [172.31.0.109] ([136.36.72.243]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-708f61949b9sm1537822a34.73.2024.07.22.07.47.04 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 22 Jul 2024 07:47:04 -0700 (PDT) Message-ID: <939e5803-8d4e-4a42-a153-4fa09a930c79@gmail.com> Date: Mon, 22 Jul 2024 08:47:03 -0600 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Beta Content-Language: en-US From: Jeff Law Subject: [committed][NFC][PR rtl-optimization/115877] Avoid setting irrelevant bit groups as live in ext-dce 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 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 Another patch to refine liveness computations. This should be NFC and is designed to help debugging. In simplest terms the patch avoids setting bit groups outside the size of a pseudo as live. Consider a HImode pseudo, bits 16..63 for such a pseudo don't really have meaning, yet we often set bit groups related to bits 16.63 on in the liveness bitmaps. This makes debugging harder than it needs to be by simply having larger bitmaps to verify when walking through the code in a debugger. This has been bootstrapped and regression tested on x86_64. It's also been tested on the crosses in my tester without regressions. Pushing to the trunk, Jeff commit 88d16194d0c8a6bdc2896c8944bfbf3e6038c9d2 Author: Jeff Law Date: Mon Jul 22 08:45:10 2024 -0600 [NFC][PR rtl-optimization/115877] Avoid setting irrelevant bit groups as live in ext-dce Another patch to refine liveness computations. This should be NFC and is designed to help debugging. In simplest terms the patch avoids setting bit groups outside the size of a pseudo as live. Consider a HImode pseudo, bits 16..63 for such a pseudo don't really have meaning, yet we often set bit groups related to bits 16.63 on in the liveness bitmaps. This makes debugging harder than it needs to be by simply having larger bitmaps to verify when walking through the code in a debugger. This has been bootstrapped and regression tested on x86_64. It's also been tested on the crosses in my tester without regressions. Pushing to the trunk, PR rtl-optimization/115877 gcc/ * ext-dce.cc (group_limit): New function. (mark_reg_live): Likewise. (ext_dce_process_sets): Use new functions. (ext_dce_process_uses): Likewise. (ext_dce_init): Likewise. diff --git a/gcc/ext-dce.cc b/gcc/ext-dce.cc index cbecfc53dba..44f64e2d18c 100644 --- a/gcc/ext-dce.cc +++ b/gcc/ext-dce.cc @@ -48,6 +48,57 @@ static bool modify; bit 16..31 bit 32..BITS_PER_WORD-1 */ +/* For the given REG, return the number of bit groups implied by the + size of the REG's mode, up to a maximum of 4 (number of bit groups + tracked by this pass). + + For partial integer and variable sized modes also return 4. This + could possibly be refined for something like PSI mode, but it + does not seem worth the effort. */ + +static int +group_limit (const_rtx reg) +{ + machine_mode mode = GET_MODE (reg); + + if (!GET_MODE_BITSIZE (mode).is_constant ()) + return 4; + + int size = GET_MODE_SIZE (mode).to_constant (); + + size = exact_log2 (size); + + if (size < 0) + return 4; + + size++; + return (size > 4 ? 4 : size); +} + +/* Make all bit groups live for REGNO in bitmap BMAP. For hard regs, + we assume all groups are live. For a pseudo we consider the size + of the pseudo to avoid creating unnecessarily live chunks of data. */ + +static void +make_reg_live (bitmap bmap, int regno) +{ + int limit; + + /* For pseudos we can use the mode to limit how many bit groups + are marked as live since a pseudo only has one mode. Hard + registers have to be handled more conservatively. */ + if (regno > FIRST_PSEUDO_REGISTER) + { + rtx reg = regno_reg_rtx[regno]; + limit = group_limit (reg); + } + else + limit = 4; + + for (int i = 0; i < limit; i++) + bitmap_set_bit (bmap, regno * 4 + i); +} + /* Note this pass could be used to narrow memory loads too. It's not clear if that's profitable or not in general. */ @@ -196,7 +247,8 @@ ext_dce_process_sets (rtx_insn *insn, rtx obj, bitmap live_tmp) /* Transfer all the LIVENOW bits for X into LIVE_TMP. */ HOST_WIDE_INT rn = REGNO (SUBREG_REG (x)); - for (HOST_WIDE_INT i = 4 * rn; i < 4 * rn + 4; i++) + int limit = group_limit (SUBREG_REG (x)); + for (HOST_WIDE_INT i = 4 * rn; i < 4 * rn + limit; i++) if (bitmap_bit_p (livenow, i)) bitmap_set_bit (live_tmp, i); @@ -260,7 +312,8 @@ ext_dce_process_sets (rtx_insn *insn, rtx obj, bitmap live_tmp) /* Transfer the appropriate bits from LIVENOW into LIVE_TMP. */ HOST_WIDE_INT rn = REGNO (x); - for (HOST_WIDE_INT i = 4 * rn; i < 4 * rn + 4; i++) + int limit = group_limit (x); + for (HOST_WIDE_INT i = 4 * rn; i < 4 * rn + limit; i++) if (bitmap_bit_p (livenow, i)) bitmap_set_bit (live_tmp, i); @@ -692,7 +745,7 @@ ext_dce_process_uses (rtx_insn *insn, rtx obj, bitmap live_tmp) /* If we have a register reference that is not otherwise handled, just assume all the chunks are live. */ else if (REG_P (x)) - bitmap_set_range (livenow, REGNO (x) * 4, 4); + bitmap_set_range (livenow, REGNO (x) * 4, group_limit (x)); } } @@ -819,10 +872,7 @@ ext_dce_init (void) unsigned i; bitmap_iterator bi; EXECUTE_IF_SET_IN_BITMAP (refs, 0, i, bi) - { - for (int j = 0; j < 4; j++) - bitmap_set_bit (&livein[EXIT_BLOCK], i * 4 + j); - } + make_reg_live (&livein[EXIT_BLOCK], i); livenow = BITMAP_ALLOC (NULL); all_blocks = BITMAP_ALLOC (NULL);