From patchwork Mon Feb 28 09:03:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Martin_Li=C5=A1ka?= X-Patchwork-Id: 1598559 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=suse.cz header.i=@suse.cz header.a=rsa-sha256 header.s=susede2_rsa header.b=2XRtm4Hk; dkim=pass header.d=suse.cz header.i=@suse.cz header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=ae7/TztE; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4K6ZD75NJgz9sFN for ; Mon, 28 Feb 2022 20:03:19 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D67133858426 for ; Mon, 28 Feb 2022 09:03:16 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by sourceware.org (Postfix) with ESMTPS id E12D93858C83 for ; Mon, 28 Feb 2022 09:03:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E12D93858C83 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.cz Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id E81DE1F39B for ; Mon, 28 Feb 2022 09:03:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1646038984; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=05sic2tFgY0B8OJcgYSiEOBBg4nvwl3iqnlnMEm63Ss=; b=2XRtm4HkMWzCnF8oYoDnypMk/EDrwgl3jIP0QlsOz95A+5ONIjamvVKs2OWfVhseQrF+VG BHqOWnXCvnTUAOAkhQ2DPeI7QFKlX+GhTgVNJrKmMQXy14aVz8PP0lEaBv3yhnwwLW6BH5 7ACb6enms86d4DVUthhXjpEbnSAoip4= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1646038984; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=05sic2tFgY0B8OJcgYSiEOBBg4nvwl3iqnlnMEm63Ss=; b=ae7/TztE8vlBAtfIe+M17kyXhONPQTnGhXuqY1dDBO3ryiE13bqFRbc7f040QMKltzm8+o KWeB47RgAFnclJBA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id DA37F12FC5 for ; Mon, 28 Feb 2022 09:03:04 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id iTBONMiPHGIOSgAAMHmgww (envelope-from ) for ; Mon, 28 Feb 2022 09:03:04 +0000 Message-ID: <65d104c2-eef6-fa92-7e6d-a42387c7526a@suse.cz> Date: Mon, 28 Feb 2022 10:03:04 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.6.1 From: =?utf-8?q?Martin_Li=C5=A1ka?= Subject: [PATCH] opts: fix -gtoggle + optimize attribute To: gcc-patches@gcc.gnu.org Content-Language: en-US X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 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 Sender: "Gcc-patches" Note -fvar-tracking is enabled automatically with OPT_LEVELS_1_PLUS and so we need to drop it if we are called from optimize attribute and the option is unset. Patch can bootstrap on x86_64-linux-gnu and survives regression tests. Ready to be installed? Thanks, Martin PR middle-end/104381 gcc/ChangeLog: * opts.cc (finish_options): If debug info is disabled (debug_info_level) and -fvar-tracking is unset, disable it. gcc/testsuite/ChangeLog: * gcc.dg/pr104381.c: New test. --- gcc/opts.cc | 49 +++++++++++++++++++-------------- gcc/testsuite/gcc.dg/pr104381.c | 20 ++++++++++++++ 2 files changed, 48 insertions(+), 21 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/pr104381.c diff --git a/gcc/opts.cc b/gcc/opts.cc index 19c68aed065..2370bb0aafe 100644 --- a/gcc/opts.cc +++ b/gcc/opts.cc @@ -1302,6 +1302,34 @@ finish_options (struct gcc_options *opts, struct gcc_options *opts_set, SET_OPTION_IF_UNSET (opts, opts_set, flag_vect_cost_model, VECT_COST_MODEL_CHEAP); + if (flag_gtoggle) + { + /* Make sure to process -gtoggle only once. */ + flag_gtoggle = false; + if (debug_info_level == DINFO_LEVEL_NONE) + { + debug_info_level = DINFO_LEVEL_NORMAL; + + if (write_symbols == NO_DEBUG) + write_symbols = PREFERRED_DEBUGGING_TYPE; + } + else + debug_info_level = DINFO_LEVEL_NONE; + } + + if (!OPTION_SET_P (debug_nonbind_markers_p)) + debug_nonbind_markers_p + = (optimize + && debug_info_level >= DINFO_LEVEL_NORMAL + && dwarf_debuginfo_p () + && !(flag_selective_scheduling || flag_selective_scheduling2)); + + /* Note -fvar-tracking is enabled automatically with OPT_LEVELS_1_PLUS and + so we need to drop it if we are called from optimize attribute. */ + if (debug_info_level < DINFO_LEVEL_NORMAL + && !OPTION_SET_P (flag_var_tracking)) + flag_var_tracking = false; + /* One could use EnabledBy, but it would lead to a circular dependency. */ if (!OPTION_SET_P (flag_var_tracking_uninit)) flag_var_tracking_uninit = flag_var_tracking; @@ -1328,27 +1356,6 @@ finish_options (struct gcc_options *opts, struct gcc_options *opts_set, profile_flag = 0; } - if (flag_gtoggle) - { - /* Make sure to process -gtoggle only once. */ - flag_gtoggle = false; - if (debug_info_level == DINFO_LEVEL_NONE) - { - debug_info_level = DINFO_LEVEL_NORMAL; - - if (write_symbols == NO_DEBUG) - write_symbols = PREFERRED_DEBUGGING_TYPE; - } - else - debug_info_level = DINFO_LEVEL_NONE; - } - - if (!OPTION_SET_P (debug_nonbind_markers_p)) - debug_nonbind_markers_p - = (optimize - && debug_info_level >= DINFO_LEVEL_NORMAL - && dwarf_debuginfo_p () - && !(flag_selective_scheduling || flag_selective_scheduling2)); diagnose_options (opts, opts_set, loc); } diff --git a/gcc/testsuite/gcc.dg/pr104381.c b/gcc/testsuite/gcc.dg/pr104381.c new file mode 100644 index 00000000000..a3aec919bee --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr104381.c @@ -0,0 +1,20 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -g -gtoggle -fdump-tree-optimized" } */ + +int foo (int x) +{ + int tem = x + 1; + int tem2 = tem - 1; + return tem2; +} + +int +__attribute__((optimize("no-tree-pre"))) +bar (int x) +{ + int tem = x + 1; + int tem2 = tem - 1; + return tem2; +} + +// { dg-final { scan-tree-dump-not "DEBUG " "optimized" } }