From patchwork Fri May 22 20:42:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Hubicka X-Patchwork-Id: 1296454 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ucw.cz Received: from 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 RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49TJN120Mzz9sPF for ; Sat, 23 May 2020 06:42:55 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id ABEC038708F9; Fri, 22 May 2020 20:42:52 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from nikam.ms.mff.cuni.cz (nikam.ms.mff.cuni.cz [195.113.20.16]) by sourceware.org (Postfix) with ESMTPS id 8D2603851C0C for ; Fri, 22 May 2020 20:42:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 8D2603851C0C Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=ucw.cz Authentication-Results: sourceware.org; spf=none smtp.mailfrom=hubicka@kam.mff.cuni.cz Received: by nikam.ms.mff.cuni.cz (Postfix, from userid 16202) id 2F5E1280950; Fri, 22 May 2020 22:42:49 +0200 (CEST) Date: Fri, 22 May 2020 22:42:49 +0200 From: Jan Hubicka To: gcc-patches@gcc.gnu.org Subject: Teach free_lang_data to simplify types of TYPE_VALUES in enumeral types Message-ID: <20200522204249.GH59676@kam.mff.cuni.cz> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) X-Spam-Status: No, score=-24.6 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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@gcc.gnu.org Sender: "Gcc-patches" Hi, streaming code assumes that INTEGER_CST never appears in non-trivial component. This is not true and we sometimes stream such components which sort of silently works but breaks our IL invariant about tree sharing. This patch fixes one instance of this problem where ENUMERAL_TYPE lists all its valids in TYPE_VALUES that with some FEs (like Ada and C++) are having the enumeral type as a type while in other FEs (like C) are simple integer types. I convert them all to integers which also increases chance that they will be shared with other integer constants at stream time. lto-bootstrapped/regtested x86_64-linux. I plan to commit this shortly. * tree.c (free_lang_data_in_type): Simpify types of TYPE_VALUES in enumeral types. diff --git a/gcc/tree.c b/gcc/tree.c index 54e471acc89..ea6692476e7 100644 --- a/gcc/tree.c +++ b/gcc/tree.c @@ -5556,6 +5556,7 @@ free_lang_data_in_type (tree type, class free_lang_data_d *fld) { if (TREE_CODE (type) == ENUMERAL_TYPE) { + tree it = NULL_TREE; ENUM_IS_OPAQUE (type) = 0; ENUM_IS_SCOPED (type) = 0; /* Type values are used only for C++ ODR checking. Drop them @@ -5568,8 +5569,27 @@ free_lang_data_in_type (tree type, class free_lang_data_d *fld) /* Simplify representation by recording only values rather than const decls. */ for (tree e = TYPE_VALUES (type); e; e = TREE_CHAIN (e)) - if (TREE_CODE (TREE_VALUE (e)) == CONST_DECL) - TREE_VALUE (e) = DECL_INITIAL (TREE_VALUE (e)); + { + if (TREE_CODE (TREE_VALUE (e)) == CONST_DECL) + { + TREE_VALUE (e) = DECL_INITIAL (TREE_VALUE (e)); + /* We can not stream values whose TREE_TYPE is type itself + because that would create non-trivial CSS. Canonicalize + them to integer types. */ + } + /* Some frontends use ENUMERAL_TYPE to represent the constants. + This leads to nontrivial SCC components containing + INTEGER_CST which is not good for streaming. Convert them + all to corresponding integer type. */ + if (TREE_CODE (TREE_TYPE (TREE_VALUE (e))) != INTEGER_TYPE) + { + if (!it) + it = lang_hooks.types.type_for_size + (TYPE_PRECISION (TREE_TYPE (TREE_VALUE (e))), + TYPE_UNSIGNED (TREE_TYPE (TREE_VALUE (e)))); + TREE_VALUE (e) = fold_convert (it, TREE_VALUE (e)); + } + } } free_lang_data_in_one_sizepos (&TYPE_MIN_VALUE (type)); free_lang_data_in_one_sizepos (&TYPE_MAX_VALUE (type));