From patchwork Sun Mar 10 02:39:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Law X-Patchwork-Id: 1910168 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=ventanamicro.com header.i=@ventanamicro.com header.a=rsa-sha256 header.s=google header.b=AePj8pco; 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 4TskfK6ztxz1yWy for ; Sun, 10 Mar 2024 13:40:23 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 44BDD3860768 for ; Sun, 10 Mar 2024 02:40:21 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-oo1-xc2b.google.com (mail-oo1-xc2b.google.com [IPv6:2607:f8b0:4864:20::c2b]) by sourceware.org (Postfix) with ESMTPS id D3A28385E44C for ; Sun, 10 Mar 2024 02:39:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D3A28385E44C Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=ventanamicro.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org D3A28385E44C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::c2b ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1710038401; cv=none; b=q8CR9GWcqAX0EeCkMnnmmXMHiBc5cVSSKxK6NB0FU7RpwpBrO8tI0RHf6tQS4ilojuib+uhufWmsjM5K70ny+wOVuMUCv0wxp54SIOsI7SLAIwi4oRYXCqHAugWlACzN6vzvW5sqeKp5NjOxZfIWiqmT0JzJJ/opSriyrBNd2IY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1710038401; c=relaxed/simple; bh=T8Ao2tYcYGa9yrZIVWxFfAmK0fiDONQdbTIltkAEvcA=; h=DKIM-Signature:Message-ID:Date:MIME-Version:From:Subject:To; b=UCYaDwcLAvKDBsw8UbZnocNNwGYR4B0XvOEepN+H5D83CMnUN8jB/8bucUU1b2I79SY3R8DSfOOdc88REu7abrhdCZHPY579xegPavWf/tCC9ADhITOPbDp8MfS5MsCYcL31sFb5FQPJNwhvvL7C7VSoKAx2dZrpuv3zMMrZ5rA= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-oo1-xc2b.google.com with SMTP id 006d021491bc7-5a1ec7cb878so335260eaf.1 for ; Sat, 09 Mar 2024 18:39:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1710038398; x=1710643198; 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=li2PqX/zvWAjoru+9GCxV02O6HxDSEBcMKrqfV31ufU=; b=AePj8pcoZJqQ9b4cfs8bA1o4qBA6u8TogrgAo7XktSjW3k+MmXLyjZlOlB6vR2wxlp qLMByq7EREwcj1A2MlvWBLB1VxLRwYv9FsNP+4m7dSnhK+9Ml6X8FNCP+FzRdXlqO+kT R06vnQ6ksFLeXjTT9n1PgI6QWiVhhgPsKvO7L0FIaJ6RFniPZOO7raQxBPeZpVHddJ9r BZ7vvlWRFpa08w33Uk3KakGjurDzZIYyeBB7ygYmqsw36Nh9YZwcoXDr6UJb3+GQA9ax NBiy175s9V+og25Yevu3jQp9By8GonlLgs7EMe46etc/f6v1N33t+84jqpsw8gaX0ovW WtOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710038398; x=1710643198; 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=li2PqX/zvWAjoru+9GCxV02O6HxDSEBcMKrqfV31ufU=; b=uEwoi0u8iLn+ACQ6962fYpfRlATDqb+WIzt1W6IXMdg9OUD4+p2yyASkWuBSR/sTXJ FlUn+vLEh7IAz/BeiGfj8/sAi94GBz3airjp7SWue30UhmriwsetC0FGpLEPwenAP2l2 y7deQAcvvYz1DmyqUtZtnVGvdn53zdN6dzKbm/acpSXiJDyTckFHeNcn+SStAAkKssu2 MwFSLCmgqyVvhqK/hmbiHjzSzE6IjgPp2a/zQjTU/sMz0va3/oY6snVz2kBfsZKuE5oD M9OOuQaGxJOXEiFmARVy3JV8+FIp5NBFPpTjT0MXUXdR/RyXdoRsi2JVsaoAWLEMxgHO 2l/w== X-Gm-Message-State: AOJu0YwKaKzD5krEvqSTGmp/aCR1aB6cqZCyK3s+UT4IpxNeq5AhUIF4 bOzeodxS6x53NJmWUHzV5dQMrYhxyjO14th41nLx3q28TP+5lE1Y4kshIAbo/nuIABFq0zAkmW2 k X-Google-Smtp-Source: AGHT+IE7t5eK8SAheQa2cOyCrdF9cX83HzV6K6Yrm1HeC5DYDTi9khV/rwa8oGlCRW2eWcUehtgZvw== X-Received: by 2002:a4a:6c52:0:b0:5a1:c2ad:a3ee with SMTP id u18-20020a4a6c52000000b005a1c2ada3eemr2352740oof.4.1710038398221; Sat, 09 Mar 2024 18:39:58 -0800 (PST) Received: from [172.31.1.103] ([172.56.168.149]) by smtp.gmail.com with ESMTPSA id cn7-20020a056820230700b005a11b933473sm448751oob.6.2024.03.09.18.39.56 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 09 Mar 2024 18:39:57 -0800 (PST) Message-ID: Date: Sat, 9 Mar 2024 19:39:52 -0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Beta Content-Language: en-US From: Jeff Law Subject: [committed] [PR target/111362] Fix compare-debug issue with mode switching To: "gcc-patches@gcc.gnu.org" X-Spam-Status: No, score=-8.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_ABUSEAT, RCVD_IN_DNSWL_NONE, RCVD_IN_SBL_CSS, 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 issue here is the code we emit for mode-switching can change when -g is added to the command line. This is caused by processing debug notes occurring after a call which is the last real statement in a basic block. Without -g the CALL_INSN is literally the last insn in the block and the loop exits. If mode switching after the call is needed, it'll be handled as we process outgoing edges. With -g the loop iterates again and in the processing of the node the backend signals that a mode switch is necessary. I pondered fixing this in the target, but the better fix is to ignore the debug notes in the insn stream. I did a cursory review of some of the other compare-debug failures, but did not immediately see others which would likely be fixed by this change. Sigh. Anyway, bootstrapped and regression tested on x86. Regression tested on rv64 as well. Pushing to the trunk. Jeff commit 50531b6d400945793a1d549e6ee941d989319d42 Author: jlaw Date: Sat Mar 9 19:27:32 2024 -0700 [committed] [PR target/111362] Fix compare-debug issue with mode switching The issue here is the code we emit for mode-switching can change when -g is added to the command line. This is caused by processing debug notes occurring after a call which is the last real statement in a basic block. Without -g the CALL_INSN is literally the last insn in the block and the loop exits. If mode switching after the call is needed, it'll be handled as we process outgoing edges. With -g the loop iterates again and in the processing of the node the backend signals that a mode switch is necessary. I pondered fixing this in the target, but the better fix is to ignore the debug notes in the insn stream. I did a cursory review of some of the other compare-debug failures, but did not immediately see others which would likely be fixed by this change. Sigh. Anyway, bootstrapped and regression tested on x86. Regression tested on rv64 as well. PR target/111362 gcc/ * mode-switching.cc (optimize_mode_switching): Only process NONDEBUG insns. gcc/testsuite * gcc.target/riscv/compare-debug-1.c: New test. * gcc.target/riscv/compare-debug-2.c: New test. diff --git a/gcc/mode-switching.cc b/gcc/mode-switching.cc index 583929184ce..a145b77397d 100644 --- a/gcc/mode-switching.cc +++ b/gcc/mode-switching.cc @@ -959,7 +959,7 @@ optimize_mode_switching (void) FOR_BB_INSNS (bb, insn) { - if (INSN_P (insn)) + if (NONDEBUG_INSN_P (insn)) { int mode = targetm.mode_switching.needed (e, insn, live_now); rtx link; diff --git a/gcc/testsuite/gcc.target/riscv/compare-debug-1.c b/gcc/testsuite/gcc.target/riscv/compare-debug-1.c new file mode 100644 index 00000000000..d65bb287b9a --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/compare-debug-1.c @@ -0,0 +1,9 @@ +/* { dg-do compile } */ +/* { dg-options "-O -fno-tree-ch --param=max-completely-peel-times=0 -march=rv64iv -mabi=lp64d -fcompare-debug" } */ + + +void +foo(void) { + for (unsigned i = 0; i < sizeof(foo); i++) + __builtin_printf("%d", i); +} diff --git a/gcc/testsuite/gcc.target/riscv/compare-debug-2.c b/gcc/testsuite/gcc.target/riscv/compare-debug-2.c new file mode 100644 index 00000000000..d87758475e4 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/compare-debug-2.c @@ -0,0 +1,3 @@ +/* { dg-do compile } */ +/* { dg-options "-O -fno-tree-ch --param=max-completely-peel-times=0 -march=rv64iv -mabi=lp64d -fno-dce -fschedule-insns -fcompare-debug" } */ +#include "compare-debug-1.c"