From patchwork Wed Oct 26 13:46:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Thomas Schwinge X-Patchwork-Id: 11271 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp277560wru; Wed, 26 Oct 2022 06:48:21 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7tFIBIQCy9Wge0AMcShYXdIPyb3f5agnfxMLAA5TI7VvC6Ul4HM8gH6v/G/zXb1OUz/fdW X-Received: by 2002:a05:6402:268f:b0:462:7cbe:953a with SMTP id w15-20020a056402268f00b004627cbe953amr692231edd.385.1666792101433; Wed, 26 Oct 2022 06:48:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666792101; cv=none; d=google.com; s=arc-20160816; b=K1tbynVyxVUlOtF9XIvCOValFA6HH8WomDVm3vT6bwZ2pEVgsxQIGVlA5ylQ+rQSmt EGm7z7WmIivD1aOPenKRr+K6f4aN77+eKvrqdhcjt2vzC6w2FenSqMKR7YI3NwoHoDJg H0evygdlMzWqM/I5SMChKN2/nzGQaNQsgrC6/ikgoSaORYl4AZ9MLM9ZIUQ7dOtr96Yl xCrYvXMEdnQmmXPycW9QfBzO/L3Zckc02J8Zuaj+gvHOqMf8YrZb8JKjPHIE0dhjAAQm jd+XNHzUAd/mLPq3vazqB7DAvEprfDbS+TWMmkxwLHPgDWV+v+Kqm5N3F3/uSFaCLnSu FVdg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:mime-version:message-id:date :user-agent:references:in-reply-to:subject:to:from:ironport-sdr :dmarc-filter:delivered-to; bh=urki7AtYy6KhBxVNfsMl1fdKp2aAD/GY1MeSrk2SkHQ=; b=Tr3ui8uFJwnxJzqAGIaL4AfIG5bFa9S8L2zYAGsJ9QzEwl0NckeGQf+a3C2EcJLg6D TBaa1RK5IiCs6MCOaYzgV4IvHMxmu3b5KmCN+urw7AZZcLvmIvk9qp2yD29rbDjYB+ez nRuMHZKxFc+iAB0NJjAPZtxLQZNATNP6xP+nuqzpMDVkryx96vAxkPWnI1HG9z+Q4SBS WsunaILj8djGg6Jglc5Olq3q5hp36luz5rK9iNl7v6GExIf4ye7c/g8zNJKHmTpdWZaS 68JE/oyOoFIy4ni2mN7hjuDkhzFdRKD0rZIaizaFP/Pi0UTc8H7AFoHAxQjn53zl7xFS poaQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id l7-20020aa7d947000000b00447d567a77dsi5087147eds.207.2022.10.26.06.48.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Oct 2022 06:48:21 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E6CE9385D0E6 for ; Wed, 26 Oct 2022 13:48:18 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from esa2.mentor.iphmx.com (esa2.mentor.iphmx.com [68.232.141.98]) by sourceware.org (Postfix) with ESMTPS id 222D9385D0E1 for ; Wed, 26 Oct 2022 13:46:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 222D9385D0E1 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mentor.com X-IronPort-AV: E=Sophos;i="5.95,214,1661846400"; d="scan'208,223";a="85579638" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa2.mentor.iphmx.com with ESMTP; 26 Oct 2022 05:46:54 -0800 IronPort-SDR: M8tBLWnaArScD6DyqI3I3pVvrXg5EnY9MCuFmuILv1vhBy6+wyp4IUP+cxttWYz9SoyVF1bX7H nP7ePhUdYyQ1o+1Iyaf2J/0uECp03j6Md7FACXXlnr3elmtK2yfvSh7NCB0ebany7wTN4cBW8n voItINuAwd202E9Bn/chn4IIaHKlTOTcsobHVHzjGyVKW7zhHFYEMRARhsJNI97Ro5Vhk5yT2O KJ0ny+gnJ5f59GdG7Tmx6apr7q+krOIK/qCov6XbLki3ROh5ngE2aWReN6KMBPD1dNCayubRlp fhs= From: Thomas Schwinge To: Jakub Jelinek , Subject: [PING] options: Clarify 'Init' option property usage for streaming optimization (was: [PATCH] options, lto: Optimize streaming of optimization nodes) In-Reply-To: <87zgl66yto.fsf@euler.schwinge.homeip.net> References: <20201005092125.GN2176@tucnak> <20201118093635.GI3788@tucnak> <87zgl66yto.fsf@euler.schwinge.homeip.net> User-Agent: Notmuch/0.29.1+93~g67ed7df (https://notmuchmail.org) Emacs/26.3 (x86_64-pc-linux-gnu) Date: Wed, 26 Oct 2022 15:46:47 +0200 Message-ID: <87eduud7eg.fsf@dem-tschwing-1.ger.mentorg.com> MIME-Version: 1.0 X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: svr-ies-mbx-13.mgc.mentorg.com (139.181.222.13) To svr-ies-mbx-10.mgc.mentorg.com (139.181.222.10) X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, 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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jan Hubicka , Joseph Myers Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747758194891439766?= X-GMAIL-MSGID: =?utf-8?q?1747758194891439766?= Hi! Ping. For convenience, I've re-attached "options: Clarify 'Init' option property usage for streaming optimization". (I've re-verified: "No functional change; no change in generated files.") Grüße Thomas On 2022-03-31T15:22:59+0200, I wrote: > Hi! > > On 2020-11-18T10:36:35+0100, Jakub Jelinek via Gcc-patches wrote: >> Honza mentioned that especially for the new param machinery, most of >> streamed values are probably going to be the default values. Perhaps >> somehow we could stream them more effectively. >> >> This patch implements it and brings further savings, the size >> goes down from 574 bytes to 273 bytes, i.e. less than half. > > Neat idea about the XOR-encoding! > >> Not trying to handle enums because the code doesn't know if (enum ...) 10 >> is even valid, similarly non-parameters because those really generally >> don't have large initializers, and params without Init (those are 0 >> initialized and thus don't need to be handled). > > Given this only looks at 'Init', I understand this may actually > mis-optimize in the case that there is an 'Init' present, but that value > is then "by default" overridden via 'LANG_HOOKS_INIT_OPTIONS_STRUCT', or > 'TARGET_OPTION_OVERRIDE', for example. (I'm however not claiming that's > an actual problem to be worried about -- just for my understanding.) > > Either way: > >> * optc-save-gen.awk: Initialize var_opt_init. In >> cl_optimization_stream_out for params with default values larger than >> 10, xor the default value with the actual parameter value. In >> cl_optimization_stream_in repeat the above xor. > >> --- gcc/optc-save-gen.awk.jj 2020-09-14 10:51:54.493740942 +0200 >> +++ gcc/optc-save-gen.awk 2020-09-14 11:39:39.441602594 +0200 >> @@ -1186,6 +1186,7 @@ for (i = 0; i < n_opts; i++) { >> var_opt_val_type[n_opt_val] = otype; >> var_opt_val[n_opt_val] = "x_" name; >> var_opt_hash[n_opt_val] = flag_set_p("Optimization", flags[i]); >> + var_opt_init[n_opt_val] = opt_args("Init", flags[i]); >> n_opt_val++; >> } >> } > > Reading through the options handling, I was confused why 'Init' needs to > be handled in 'gcc/optc-save-gen.awk'. To help the next person -- like, > me in a few weeks ;-) -- wondering about this, OK to push the attached > "options: Clarify 'Init' option property usage for streaming > optimization"? > > > Grüße > Thomas > > >> @@ -1257,10 +1258,21 @@ for (i = 0; i < n_opt_val; i++) { >> otype = var_opt_val_type[i]; >> if (otype ~ "^const char \\**$") >> print " bp_pack_string (ob, bp, ptr->" name", true);"; >> - else if (otype ~ "^unsigned") >> - print " bp_pack_var_len_unsigned (bp, ptr->" name");"; >> - else >> - print " bp_pack_var_len_int (bp, ptr->" name");"; >> + else { >> + if (otype ~ "^unsigned") { >> + sgn = "unsigned"; >> + } else { >> + sgn = "int"; >> + } >> + if (name ~ "^x_param" && !(otype ~ "^enum ") && var_opt_init[i]) { >> + print " if (" var_opt_init[i] " > (" var_opt_val_type[i] ") 10)"; >> + print " bp_pack_var_len_" sgn " (bp, ptr->" name" ^ " var_opt_init[i] ");"; >> + print " else"; >> + print " bp_pack_var_len_" sgn " (bp, ptr->" name");"; >> + } else { >> + print " bp_pack_var_len_" sgn " (bp, ptr->" name");"; >> + } >> + } >> } >> print " for (size_t i = 0; i < sizeof (ptr->explicit_mask) / sizeof (ptr->explicit_mask[0]); i++)"; >> print " bp_pack_value (bp, ptr->explicit_mask[i], 64);"; >> @@ -1281,10 +1293,18 @@ for (i = 0; i < n_opt_val; i++) { >> print " if (ptr->" name")"; >> print " ptr->" name" = xstrdup (ptr->" name");"; >> } >> - else if (otype ~ "^unsigned") >> - print " ptr->" name" = (" var_opt_val_type[i] ") bp_unpack_var_len_unsigned (bp);"; >> - else >> - print " ptr->" name" = (" var_opt_val_type[i] ") bp_unpack_var_len_int (bp);"; >> + else { >> + if (otype ~ "^unsigned") { >> + sgn = "unsigned"; >> + } else { >> + sgn = "int"; >> + } >> + print " ptr->" name" = (" var_opt_val_type[i] ") bp_unpack_var_len_" sgn " (bp);"; >> + if (name ~ "^x_param" && !(otype ~ "^enum ") && var_opt_init[i]) { >> + print " if (" var_opt_init[i] " > (" var_opt_val_type[i] ") 10)"; >> + print " ptr->" name" ^= " var_opt_init[i] ";"; >> + } >> + } >> } >> print " for (size_t i = 0; i < sizeof (ptr->explicit_mask) / sizeof (ptr->explicit_mask[0]); i++)"; >> print " ptr->explicit_mask[i] = bp_unpack_value (bp, 64);"; ----------------- Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955 From c7968fa44b1073dfa7da3a11470a9e76b6faafaf Mon Sep 17 00:00:00 2001 From: Thomas Schwinge Date: Thu, 31 Mar 2022 12:06:29 +0200 Subject: [PATCH] options: Clarify 'Init' option property usage for streaming optimization This clarifies commit 95db7e9afe57ca1c269d46baa2accced004e5c74 "options, lto: Optimize streaming of optimization nodes". No functional change; no change in generated files. gcc/ * optc-save-gen.awk: Clarify 'Init' option property usage for streaming optimization. --- gcc/optc-save-gen.awk | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/gcc/optc-save-gen.awk b/gcc/optc-save-gen.awk index 9911bab6668..c60b300f693 100644 --- a/gcc/optc-save-gen.awk +++ b/gcc/optc-save-gen.awk @@ -1292,7 +1292,22 @@ for (i = 0; i < n_opts; i++) { var_opt_val_type[n_opt_val] = otype; var_opt_val[n_opt_val] = "x_" name; var_opt_hash[n_opt_val] = flag_set_p("Optimization", flags[i]); - var_opt_init[n_opt_val] = opt_args("Init", flags[i]); + + # If applicable, optimize streaming for the common case that + # the current value is unchanged from the 'Init' value: + # XOR-encode it so that we stream value zero. + # Not handling non-parameters as those really generally don't + # have large initializers. + # Not handling enums as we don't know if '(enum ...) 10' is + # even valid (see synthesized 'if' conditionals below). + if (flag_set_p("Param", flags[i]) \ + && !(otype ~ "^enum ")) { + # Those without 'Init' are zero-initialized and thus + # already encoded ideally. + init = opt_args("Init", flags[i]) + var_opt_optimize_init[n_opt_val] = init; + } + n_opt_val++; } } @@ -1370,9 +1385,10 @@ for (i = 0; i < n_opt_val; i++) { } else { sgn = "int"; } - if (name ~ "^x_param" && !(otype ~ "^enum ") && var_opt_init[i]) { - print " if (" var_opt_init[i] " > (" var_opt_val_type[i] ") 10)"; - print " bp_pack_var_len_" sgn " (bp, ptr->" name" ^ " var_opt_init[i] ");"; + # If applicable, encode the streamed value. + if (var_opt_optimize_init[i]) { + print " if (" var_opt_optimize_init[i] " > (" var_opt_val_type[i] ") 10)"; + print " bp_pack_var_len_" sgn " (bp, ptr->" name" ^ " var_opt_optimize_init[i] ");"; print " else"; print " bp_pack_var_len_" sgn " (bp, ptr->" name");"; } else { @@ -1406,9 +1422,10 @@ for (i = 0; i < n_opt_val; i++) { sgn = "int"; } print " ptr->" name" = (" var_opt_val_type[i] ") bp_unpack_var_len_" sgn " (bp);"; - if (name ~ "^x_param" && !(otype ~ "^enum ") && var_opt_init[i]) { - print " if (" var_opt_init[i] " > (" var_opt_val_type[i] ") 10)"; - print " ptr->" name" ^= " var_opt_init[i] ";"; + # If applicable, decode the streamed value. + if (var_opt_optimize_init[i]) { + print " if (" var_opt_optimize_init[i] " > (" var_opt_val_type[i] ") 10)"; + print " ptr->" name" ^= " var_opt_optimize_init[i] ";"; } } } -- 2.35.1