From patchwork Fri May 28 09:48:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Martin_Li=C5=A1ka?= X-Patchwork-Id: 1485173 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; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=suse.cz header.i=@suse.cz header.a=rsa-sha256 header.s=susede2_rsa header.b=zINuMEXh; dkim=fail reason="signature verification failed" header.d=suse.cz header.i=@suse.cz header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=Zek6hYip; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 4Fs0HN633cz9sVb for ; Fri, 28 May 2021 19:48:15 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2FFED383D02D; Fri, 28 May 2021 09:48:12 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by sourceware.org (Postfix) with ESMTPS id 483A9385381B for ; Fri, 28 May 2021 09:48:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 483A9385381B Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mliska@suse.cz Received: from imap.suse.de (imap-alt.suse-dmz.suse.de [192.168.254.47]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 11019218B3; Fri, 28 May 2021 09:48:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1622195287; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ayZFvKv3kd1wy1+eAd7n1OA2NpGzUZLoR4Hme7BNy00=; b=zINuMEXhzFIKUX+G3QVEwUPeyYjCwA/coB2VtpS4I1Vc2q0sxsD0Tf7P9XGZXJknEIbG13 dl3Qy3Le6s3AyuSdI3mcaLffvSo8aMY8T6n4UvRR/gso8uyUblLhs8YeXAp2OZiOkci3hy FstrcB9gkf5t4RYJKc+QwIK+lJL8+cw= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1622195287; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ayZFvKv3kd1wy1+eAd7n1OA2NpGzUZLoR4Hme7BNy00=; b=Zek6hYipmTeo3kJAEYtv8kaZjzFIcgeVo72ssmogUGQ4RPstleGSGjI7L7ECUsW6pl4Dpo M7LI1kULOZXYftCA== Received: from director2.suse.de (director2.suse-dmz.suse.de [192.168.254.72]) by imap.suse.de (Postfix) with ESMTPSA id E344411A98; Fri, 28 May 2021 09:48:06 +0000 (UTC) From: =?utf-8?q?Martin_Li=C5=A1ka?= Subject: Fallout: save/restore target options in handle_optimize_attribute To: Joseph Myers References: <5a57f45d-4c6c-ee18-e242-061c61ff8d5b@riscy-ip.com> <3c12c7fc-d80a-ecd9-e951-fb14e965e66d@suse.cz> Message-ID: <74b71e01-ea81-9506-6756-6a1160878d45@suse.cz> Date: Fri, 28 May 2021 11:48:06 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.10.2 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US X-Spam-Status: No, score=-11.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, SPF_HELO_NONE, SPF_PASS, 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: , Cc: Segher Boessenkool , Joern Wolfgang Rennecke , GCC Patches , Jeff Law Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" Hi. There's a fallout after my revision ebd5e86c0f41dc1d692f9b2b68a510b1f6835a3e. I would like to analyze all case and discuss possible solution. To be honest it's a can of worms and reverting the commit is an option on the table. So the cases: 1) PR100759 - ppc64le $ cat pr.C #pragma GCC optimize 0 void main(); $ ./xgcc -B. -Os pr.C pr.C:2:11: internal compiler error: ‘global_options’ are modified in local context 2 | void main(); What happens: we change from -Os to -O0 and rs6000_isa_flags differ in cl_optimization_compare. Problem is that OPTION_MASK_SAVE_TOC_INDIRECT is set based on optimize flag: /* If we can shrink-wrap the TOC register save separately, then use -msave-toc-indirect unless explicitly disabled. */ if ((rs6000_isa_flags_explicit & OPTION_MASK_SAVE_TOC_INDIRECT) == 0 && flag_shrink_wrap_separate && optimize_function_for_speed_p (cfun)) rs6000_isa_flags |= OPTION_MASK_SAVE_TOC_INDIRECT; Suggested solution is doing: if ((rs6000_isa_flags_explicit & OPTION_MASK_SAVE_TOC_INDIRECT) == 0 && flag_shrink_wrap_separate rs6000_isa_flags |= OPTION_MASK_SAVE_TOC_INDIRECT; and add '&& optimize_function_for_speed_p (cfun)' to the place where the option mask is used. 2) Joseph's case: $ cat ~/Programming/testcases/opts-bug.i extern unsigned long int x; extern float f (float); extern __typeof (f) f_power8; extern __typeof (f) f_power9; extern __typeof (f) f __attribute__ ((ifunc ("f_ifunc"))); static __attribute__ ((optimize ("-fno-stack-protector"))) __typeof (f) * f_ifunc (void) { __typeof (f) *res = x ? f_power9 : f_power8; return res; } $ ./xgcc -B. ~/Programming/testcases/opts-bug.i -c -S -O2 -mlong-double-128 -mabi=ibmlongdouble /home/marxin/Programming/testcases/opts-bug.i:8:1: error: ‘-mabi=ibmlongdouble’ requires ‘-mlong-double-128’ This is caused by a weird option override: else if (rs6000_long_double_type_size == 128) rs6000_long_double_type_size = FLOAT_PRECISION_TFmode; (it's 127) later when rs6000_option_override_internal is called for saved target flags (127), it complains. Possible fix: else if (rs6000_long_double_type_size == 128 || rs6000_long_double_type_size == FLOAT_PRECISION_TFmode) 3) ARM issue reported here: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98636#c20 arm_fp16_inst = bitmap_bit_p (arm_active_target.isa, isa_bit_fp16); if (arm_fp16_inst) { if (arm_fp16_format == ARM_FP16_FORMAT_ALTERNATIVE) error ("selected fp16 options are incompatible"); arm_fp16_format = ARM_FP16_FORMAT_IEEE; } there's likely missing else branch which would reset when arm_fp16_inst is null. Anyway, can be moved again to the ignored list 4) Jeff reported the following for v850-elf: $ cat ~/Programming/testcases/j.c typedef __SIZE_TYPE__ size_t; extern inline __attribute__ ((__always_inline__, __gnu_inline__, __artificial__, __nothrow__, __leaf__)) void * memcpy (void *__restrict __dest, const void *__restrict __src, size_t __len) { return __builtin___memcpy_chk (__dest, __src, __len, __builtin_object_size (__dest, 0)); } __attribute__((optimize ("Ofast"))) void bar (void *d, void *s, size_t l) { memcpy (d, s, l); } $ ./xgcc -B. ~/Programming/testcases/j.c -S /home/marxin/Programming/testcases/j.c: In function ‘bar’: /home/marxin/Programming/testcases/j.c:4:1: error: inlining failed in call to ‘always_inline’ ‘memcpy’: target specific option mismatch 4 | memcpy (void *__restrict __dest, const void *__restrict __src, size_t __len) | ^~~~~~ /home/marxin/Programming/testcases/j.c:12:3: note: called from here 12 | memcpy (d, s, l); | ^~~~~~~~~~~~~~~~ This one is pretty clear. The target does: { OPT_LEVELS_1_PLUS, OPT_mprolog_function, NULL, 1 }, So it sets a target option based on optimize level. This one will need: caller does not have it set, while callee has. What target maintainers thing about it? Martin diff --git a/gcc/config/v850/v850.c b/gcc/config/v850/v850.c index e0e5005d865..49f91f12766 100644 --- a/gcc/config/v850/v850.c +++ b/gcc/config/v850/v850.c @@ -3140,6 +3140,11 @@ v850_option_override (void) /* The RH850 ABI does not (currently) support the use of the CALLT instruction. */ if (! TARGET_GCC_ABI) target_flags |= MASK_DISABLE_CALLT; + + /* Save the initial options in case the user does function specific + options. */ + target_option_default_node = target_option_current_node + = build_target_option_node (&global_options, &global_options_set); } plus a custom can_inline_p target hook where the MASK_PROLOG_FUNCTION is ignored because