From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by sourceware.org (Postfix) with ESMTPS id 669813858D33 for ; Tue, 28 Feb 2023 08:58:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 669813858D33 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 2942821A52; Tue, 28 Feb 2023 08:58:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1677574701; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=4XVsZ+uD97EltCp6gzuNGaCPB2hzrqiy5LREGQE0zWU=; b=Ng8U34+exexP5ZU0bxig5B10jqCx92QUXnU34ra9EtKbEu+c7ujzWHiyuzFsq5IKd7aw1H 5QNDuaa3NSFyKV27VGwZODpAr4Og9ztgEX/5o07iJp/ElQD24UP16dvf09hBVG3GQZHK3t VxdNBle2UdWaTzsBtyXfWN6twKGcZkg= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1677574701; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=4XVsZ+uD97EltCp6gzuNGaCPB2hzrqiy5LREGQE0zWU=; b=06fLjJtgb93GzhiWZh7NJV1u5dMuIQv6BxL2YbVCWiGKcCHGujuRvNfW4p4xOxd1O1yQrF fsTiqYxjXeKPFODQ== Received: from wotan.suse.de (wotan.suse.de [10.160.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id 0D8052C141; Tue, 28 Feb 2023 08:58:20 +0000 (UTC) Date: Tue, 28 Feb 2023 08:58:20 +0000 (UTC) From: Richard Biener To: Jakub Jelinek cc: gcc-patches@gcc.gnu.org Subject: Re: [PATCH] lto: Fix up lto_fixup_prevailing_type [PR108910] In-Reply-To: Message-ID: References: User-Agent: Alpine 2.22 (LSU 394 2020-01-19) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-5.0 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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 List-Id: On Tue, 28 Feb 2023, Jakub Jelinek wrote: > Hi! > > Without LTO, TYPE_POINTER_TO/TYPE_REFERENCE_TO chains are only maintained > inside of build_{pointer,reference}_type_for_mode and those routines > ensure that the pointer/reference type added to the chain is really > unqualified (including address space), without extra user alignment > and has just one entry for each of the TYPE_MODE/TYPE_REF_CAN_ALIAS_ALL > pair (unless something would modify the types in place, but that would > be wrong). Is that so? I can't find any code verifying that (verify_type?). Of course build_{pointer,reference}_type_for_mode will always build unqualified pointers, but then the LTO code does /* The following reconstructs the pointer chains of the new pointed-to type if we are a main variant. We do not stream those so they are broken before fixup. */ if (TREE_CODE (t) == POINTER_TYPE && TYPE_MAIN_VARIANT (t) == t) { TYPE_NEXT_PTR_TO (t) = TYPE_POINTER_TO (TREE_TYPE (t)); TYPE_POINTER_TO (TREE_TYPE (t)) = t; } else if (TREE_CODE (t) == REFERENCE_TYPE && TYPE_MAIN_VARIANT (t) == t) { TYPE_NEXT_REF_TO (t) = TYPE_REFERENCE_TO (TREE_TYPE (t)); TYPE_REFERENCE_TO (TREE_TYPE (t)) = t; } which was supposed to ensure only putting unqualified pointers (not pointed to types!) to the chain. So to me the question is rather why a type with TYPE_USER_ALIGN is a the main variant - that's what looks wrong here? Richard. > Now, LTO adds stuff to these chains in lto_fixup_prevailing_type but > doesn't guarantee that. The testcase in the PR (which I'm not including > for testsuite because when (I hope) the aarch64 backend bug will be fixed, > the testcase would work either way) shows a case where user has > TYPE_USER_ALIGN type with very high alignment, as there aren't enough > pointers to float in the code left that one becomes the prevailing one, > lto_fixup_prevailing_type puts it into the TYPE_POINTER_TO chain of > float and later on during expansion of __builtin_cexpif expander > uses build_pointer_type (float_type_node) to emit a sincosf call and > instead of getting a normal pointer type gets this non-standard one. > > The following patch fixes that by not adding into those chains > qualified or user aligned types and by making sure that some type > for the TYPE_MODE/TYPE_REF_CAN_ALIAS_ALL combination (e.g. from lto1 > initialization) isn't there already before adding a new one. > > Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? > > 2023-02-28 Jakub Jelinek > > PR target/108910 > * lto-common.cc (lto_fixup_prevailing_type): Don't add t to > TYPE_POINTER_TO or TYPE_REFERENCE_TO chain if it has non-zero > TYPE_QUALS, or TYPE_USER_ALIGN or some other type with the > same TYPE_MODE and TYPE_REF_CAN_ALIAS_ALL flag is already > present. > > --- gcc/lto/lto-common.cc.jj 2023-01-16 11:52:16.165732856 +0100 > +++ gcc/lto/lto-common.cc 2023-02-28 01:42:51.006764018 +0100 > @@ -984,21 +984,35 @@ lto_fixup_prevailing_type (tree t) > TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (mv); > TYPE_NEXT_VARIANT (mv) = t; > } > - > - /* The following reconstructs the pointer chains > - of the new pointed-to type if we are a main variant. We do > - not stream those so they are broken before fixup. */ > - if (TREE_CODE (t) == POINTER_TYPE > - && TYPE_MAIN_VARIANT (t) == t) > - { > - TYPE_NEXT_PTR_TO (t) = TYPE_POINTER_TO (TREE_TYPE (t)); > - TYPE_POINTER_TO (TREE_TYPE (t)) = t; > - } > - else if (TREE_CODE (t) == REFERENCE_TYPE > - && TYPE_MAIN_VARIANT (t) == t) > + else if (!TYPE_QUALS (t) && !TYPE_USER_ALIGN (t)) > { > - TYPE_NEXT_REF_TO (t) = TYPE_REFERENCE_TO (TREE_TYPE (t)); > - TYPE_REFERENCE_TO (TREE_TYPE (t)) = t; > + /* The following reconstructs the pointer chains > + of the new pointed-to type if we are a main variant. We do > + not stream those so they are broken before fixup. > + Don't add it if despite being main variant it is > + qualified or user aligned type. Don't add it if there > + is something in the chain already. */ > + tree *p = NULL; > + if (TREE_CODE (t) == POINTER_TYPE) > + p = &TYPE_POINTER_TO (TREE_TYPE (t)); > + else if (TREE_CODE (t) == REFERENCE_TYPE) > + p = &TYPE_REFERENCE_TO (TREE_TYPE (t)); > + if (p) > + { > + tree t2; > + for (t2 = *p; t2; t2 = TYPE_NEXT_PTR_TO (t2)) > + if (TYPE_MODE (t2) == TYPE_MODE (t) > + && TYPE_REF_CAN_ALIAS_ALL (t2) == TYPE_REF_CAN_ALIAS_ALL (t)) > + break; > + if (t2 == NULL_TREE) > + { > + if (TREE_CODE (t) == POINTER_TYPE) > + TYPE_NEXT_PTR_TO (t) = *p; > + else > + TYPE_NEXT_REF_TO (t) = *p; > + *p = t; > + } > + } > } > } > > > Jakub > > -- Richard Biener SUSE Software Solutions Germany GmbH, Frankenstrasse 146, 90461 Nuernberg, Germany; GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman; HRB 36809 (AG Nuernberg)