From patchwork Fri Dec 3 03:46:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Kewen.Lin" X-Patchwork-Id: 1563098 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=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=sPzEGREp; 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 (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 bilbo.ozlabs.org (Postfix) with ESMTPS id 4J4zLG56vRz9t1r for ; Fri, 3 Dec 2021 14:47:49 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 71DEE3857817 for ; Fri, 3 Dec 2021 03:47:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 71DEE3857817 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1638503266; bh=H70xDRT+OimAeVwIAGGnQXqYs/Mscxmm/1MMOdDv5AQ=; h=Subject:To:References:Date:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=sPzEGREpLVMLRu+Kt+odIyDCVbC1Aif8Q429Zg4NYD6xdUPmWIVlsQwNjKCPMrXyh QxZWdYno+O/WL+TyGzftrBGxHtKcSU5HecQcA7XBSsZjENDe6X6k8FQADMeenJZl8C Y/AHPNuvuWL0bkfhgL0ebdc4UMOiYpp1LK34ULNE= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by sourceware.org (Postfix) with ESMTPS id F10FA3857C4E for ; Fri, 3 Dec 2021 03:47:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org F10FA3857C4E Received: from pps.filterd (m0127361.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 1B32sF98036320; Fri, 3 Dec 2021 03:47:03 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 3cqaux0rvq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 03 Dec 2021 03:47:03 +0000 Received: from m0127361.ppops.net (m0127361.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 1B33H438013483; Fri, 3 Dec 2021 03:47:02 GMT Received: from ppma03ams.nl.ibm.com (62.31.33a9.ip4.static.sl-reverse.com [169.51.49.98]) by mx0a-001b2d01.pphosted.com with ESMTP id 3cqaux0rv7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 03 Dec 2021 03:47:02 +0000 Received: from pps.filterd (ppma03ams.nl.ibm.com [127.0.0.1]) by ppma03ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 1B33hW3x018845; Fri, 3 Dec 2021 03:47:00 GMT Received: from b06cxnps4075.portsmouth.uk.ibm.com (d06relay12.portsmouth.uk.ibm.com [9.149.109.197]) by ppma03ams.nl.ibm.com with ESMTP id 3ckcaaa06y-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 03 Dec 2021 03:47:00 +0000 Received: from d06av21.portsmouth.uk.ibm.com (d06av21.portsmouth.uk.ibm.com [9.149.105.232]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 1B33kvVF8847776 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 3 Dec 2021 03:46:57 GMT Received: from d06av21.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 223C852050; Fri, 3 Dec 2021 03:46:57 +0000 (GMT) Received: from KewenLins-MacBook-Pro.local (unknown [9.200.53.118]) by d06av21.portsmouth.uk.ibm.com (Postfix) with ESMTP id A3A6352059; Fri, 3 Dec 2021 03:46:54 +0000 (GMT) Subject: [PATCH v2] rs6000: Fix some issues in rs6000_can_inline_p [PR102059] To: Segher Boessenkool References: <3f2c6df2-e458-483c-facd-148a3cc3aead@linux.ibm.com> <20211129165712.GU614@gate.crashing.org> Message-ID: <57a263ea-4ef3-c57e-ff4c-2e5833532162@linux.ibm.com> Date: Fri, 3 Dec 2021 11:46:53 +0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.10.0 In-Reply-To: <20211129165712.GU614@gate.crashing.org> Content-Language: en-US X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: l4mx5vSsKVwiSsP_8W2LBa5zcdi7dvhv X-Proofpoint-GUID: vw4TRDTji3VfWiJMd77b3T36xfm2jXra X-Proofpoint-UnRewURL: 0 URL was un-rewritten MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.790,Hydra:6.0.425,FMLib:17.11.62.513 definitions=2021-12-03_02,2021-12-02_01,2021-12-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 impostorscore=0 suspectscore=0 spamscore=0 bulkscore=0 mlxlogscore=999 lowpriorityscore=0 clxscore=1015 priorityscore=1501 adultscore=0 malwarescore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2110150000 definitions=main-2112030020 X-Spam-Status: No, score=-8.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, MIME_CHARSET_FARAWAY, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP 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: , X-Patchwork-Original-From: "Kewen.Lin via Gcc-patches" From: "Kewen.Lin" Reply-To: "Kewen.Lin" Cc: Bill Schmidt , GCC Patches , David Edelsohn , Michael Meissner Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Hi Segher, Thanks for the review! on 2021/11/30 上午12:57, Segher Boessenkool wrote: > Hi! > > On Wed, Sep 01, 2021 at 02:55:51PM +0800, Kewen.Lin wrote: >> This patch is to fix the inconsistent behaviors for non-LTO mode >> and LTO mode. As Martin pointed out, currently the function >> rs6000_can_inline_p simply makes it inlinable if callee_tree is >> NULL, but it's wrong, we should use the command line options >> from target_option_default_node as default. > > This is not documented. > Yeah, but according to the document for the target attribute [1], "Multiple target back ends implement the target attribute to specify that a function is to be compiled with different target options than specified on the command line. The original target command-line options are ignored. ", it seems to say the function without any target attribute/pragma will be compiled with target options specified on the command line. I think it's a normal expectation for users. Excepting for the inconsistent behaviors between LTO and non-LTO, it can also make the below case different. // Option: -O2 -mcpu=power8 -mhtm int foo(int *b) { *b += __builtin_ttest(); return *b; } __attribute__((target("no-htm"))) int bar(int *a) { *a = foo(a); return 0; } Without this fix, bar inlines foo but get the error as below: In function ‘foo’, inlined from ‘bar’ at test.c:8:8: test.c:3:9: error: ‘__builtin_ttest’ requires the ‘-mhtm’ option 3 | *b += __builtin_ttest(); | ^~~~~~~~~~~~~~~~~ Since bar doesn't support foo's required HTM feature. With this fix, bar doesn't inline foo and the case gets compiled well. I've added this test case as pr102059-5.c. [1] https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#Common-Function-Attributes >> It also replaces >> rs6000_isa_flags with the one from target_option_default_node >> when caller_tree is NULL as rs6000_isa_flags could probably >> change since initialization. > > Is this enough then? Are there no other places that use > rs6000_isa_flags? Is it correct for us to have that variable at all > anymore? Etc. > Good question, I think the answer is yes. I digged into it and found the current target option save/restore scheme would keep rs6000_isa_flags to be the same as the one saved in target_option_default_node for the context of inlining. So I put one assertion as below: if (!caller_tree) { caller_tree = target_option_default_node; gcc_assert (rs6000_isa_flags == TREE_TARGET_OPTION (caller_tree)->x_rs6000_isa_flags); } And kicked off regression testings on both BE and LE, the result showed only one same failure, which seems to be a latent bug. I've filed PR103515 for it. This bug also indicates it's better to use target_option_default_node rather than rs6000_isa_flags when the caller_tree is NULL. Since the target_option_default_node is straightforward and doesn't rely on the assumption that rs6000_isa_flags would be kept as the default one correctly, it doesn't suffer from bugs like PR103515. >> + bool always_inline = >> + (DECL_DISREGARD_INLINE_LIMITS (callee) >> + && lookup_attribute ("always_inline", DECL_ATTRIBUTES (callee))); > > The "=" should start a line, not end it. And please don't use > unnecessary parens. > >> + /* Some flags such as fusion can be tolerated for always inlines. */ >> + unsigned HOST_WIDE_INT always_inline_safe_mask = >> + (MASK_P8_FUSION | MASK_P10_FUSION | OPTION_MASK_SAVE_TOC_INDIRECT >> + | OPTION_MASK_P8_FUSION_SIGN | OPTION_MASK_P10_FUSION_LD_CMPI >> + | OPTION_MASK_P10_FUSION_2LOGICAL | OPTION_MASK_P10_FUSION_LOGADD >> + | OPTION_MASK_P10_FUSION_ADDLOG | OPTION_MASK_P10_FUSION_2ADD >> + | OPTION_MASK_PCREL_OPT); > > Same. > Both above and here fixed. > The fusion ones are obvious. The other two are not. Please put those > two more obviously separate (not somewhere in the sea of fusion > options), and some comment wouldn't hurt either. You can make it > separate statements even, make it really stand out. > Fixed by splitting it into: fusion_options_mask and optimization_options_mask. I'm not happy for the later name, but poor to get a better in mind. Do you have any suggestions on the name and words? > Why are there OPTION_MASKs for separate P10 fusion types here, as well as > MASK_P10_FUSION? > Mike helped to explain the history, I've updated all of them using OPTION_MASK_ to avoid potential confusion. >> + >> + if (always_inline) { >> + caller_isa &= ~always_inline_safe_mask; >> + callee_isa &= ~always_inline_safe_mask; >> + } > > "{" starts a new line, indented. > Fixed. I refined this part a bit since caller doesn't need to take actions. The new version V2 is attached. Tested as before. BR, Kewen --- gcc/ChangeLog: PR ipa/102059 * config/rs6000/rs6000.c (rs6000_can_inline_p): Adjust with target_option_default_node and consider always_inline_safe flags. gcc/testsuite/ChangeLog: PR ipa/102059 * gcc.target/powerpc/pr102059-1.c: New test. * gcc.target/powerpc/pr102059-2.c: New test. * gcc.target/powerpc/pr102059-3.c: New test. * gcc.target/powerpc/pr102059-4.c: New test. * gcc.target/powerpc/pr102059-5.c: New test. ----- --- gcc/config/rs6000/rs6000.c | 95 +++++++++++++------ gcc/testsuite/gcc.target/powerpc/pr102059-1.c | 24 +++++ gcc/testsuite/gcc.target/powerpc/pr102059-2.c | 20 ++++ gcc/testsuite/gcc.target/powerpc/pr102059-3.c | 95 +++++++++++++++++++ gcc/testsuite/gcc.target/powerpc/pr102059-4.c | 22 +++++ gcc/testsuite/gcc.target/powerpc/pr102059-5.c | 22 +++++ 6 files changed, 250 insertions(+), 28 deletions(-) create mode 100644 gcc/testsuite/gcc.target/powerpc/pr102059-1.c create mode 100644 gcc/testsuite/gcc.target/powerpc/pr102059-2.c create mode 100644 gcc/testsuite/gcc.target/powerpc/pr102059-3.c create mode 100644 gcc/testsuite/gcc.target/powerpc/pr102059-4.c create mode 100644 gcc/testsuite/gcc.target/powerpc/pr102059-5.c diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c index 289c1b3df24..8d4258e58b1 100644 --- a/gcc/config/rs6000/rs6000.c +++ b/gcc/config/rs6000/rs6000.c @@ -25539,45 +25539,84 @@ rs6000_generate_version_dispatcher_body (void *node_p) static bool rs6000_can_inline_p (tree caller, tree callee) { - bool ret = false; tree caller_tree = DECL_FUNCTION_SPECIFIC_TARGET (caller); tree callee_tree = DECL_FUNCTION_SPECIFIC_TARGET (callee); - /* If the callee has no option attributes, then it is ok to inline. */ + /* If the caller/callee has option attributes, then use them. + Otherwise, use the command line options. */ if (!callee_tree) - ret = true; + callee_tree = target_option_default_node; + if (!caller_tree) + caller_tree = target_option_default_node; + + struct cl_target_option *caller_opts = TREE_TARGET_OPTION (caller_tree); + struct cl_target_option *callee_opts = TREE_TARGET_OPTION (callee_tree); + HOST_WIDE_INT caller_isa = caller_opts->x_rs6000_isa_flags; + HOST_WIDE_INT callee_isa = callee_opts->x_rs6000_isa_flags; + + bool always_inline + = DECL_DISREGARD_INLINE_LIMITS (callee) + && lookup_attribute ("always_inline", DECL_ATTRIBUTES (callee)); + + /* Fusion option masks. */ + unsigned HOST_WIDE_INT fusion_options_mask + = OPTION_MASK_P8_FUSION | OPTION_MASK_P10_FUSION | OPTION_MASK_P8_FUSION_SIGN + | OPTION_MASK_P10_FUSION_LD_CMPI | OPTION_MASK_P10_FUSION_2LOGICAL + | OPTION_MASK_P10_FUSION_LOGADD | OPTION_MASK_P10_FUSION_ADDLOG + | OPTION_MASK_P10_FUSION_2ADD; + + /* Like fusion, some option masks which are just for optimization. */ + unsigned HOST_WIDE_INT optimization_options_mask + = OPTION_MASK_SAVE_TOC_INDIRECT | OPTION_MASK_PCREL_OPT; + + /* Some features can be tolerated for always inlines. */ + unsigned HOST_WIDE_INT always_inline_safe_mask + = fusion_options_mask | optimization_options_mask; + + /* To adjust callee is enough since we just check for subset. */ + if (always_inline) + callee_isa &= ~always_inline_safe_mask; + + /* The callee's options must be a subset of the caller's options, i.e. + a vsx function may inline an altivec function, but a no-vsx function + must not inline a vsx function. */ + if ((caller_isa & callee_isa) != callee_isa) + { + if (TARGET_DEBUG_TARGET) + fprintf (stderr, + "rs6000_can_inline_p:, caller %s, callee %s, cannot " + "inline since callee's options set isn't a subset of " + "caller's options set.\n", + get_decl_name (caller), get_decl_name (callee)); + return false; + } - else + /* For those options that the callee has explicitly enabled or disabled, + then we must enforce that the callee's and caller's options match + exactly; see PR70010. */ + HOST_WIDE_INT explicit_isa = callee_opts->x_rs6000_isa_flags_explicit; + if (always_inline) + explicit_isa &= ~always_inline_safe_mask; + if ((caller_isa & explicit_isa) != (callee_isa & explicit_isa)) { - HOST_WIDE_INT caller_isa; - struct cl_target_option *callee_opts = TREE_TARGET_OPTION (callee_tree); - HOST_WIDE_INT callee_isa = callee_opts->x_rs6000_isa_flags; - HOST_WIDE_INT explicit_isa = callee_opts->x_rs6000_isa_flags_explicit; - - /* If the caller has option attributes, then use them. - Otherwise, use the command line options. */ - if (caller_tree) - caller_isa = TREE_TARGET_OPTION (caller_tree)->x_rs6000_isa_flags; - else - caller_isa = rs6000_isa_flags; - - /* The callee's options must be a subset of the caller's options, i.e. - a vsx function may inline an altivec function, but a no-vsx function - must not inline a vsx function. However, for those options that the - callee has explicitly enabled or disabled, then we must enforce that - the callee's and caller's options match exactly; see PR70010. */ - if (((caller_isa & callee_isa) == callee_isa) - && (caller_isa & explicit_isa) == (callee_isa & explicit_isa)) - ret = true; + if (TARGET_DEBUG_TARGET) + fprintf (stderr, + "rs6000_can_inline_p:, caller %s, callee %s, cannot " + "inline since callee's options set isn't a subset of " + "caller's options set by considering callee's " + "explicitly set options.\n", + get_decl_name (caller), get_decl_name (callee)); + return false; } if (TARGET_DEBUG_TARGET) - fprintf (stderr, "rs6000_can_inline_p:, caller %s, callee %s, %s inline\n", - get_decl_name (caller), get_decl_name (callee), - (ret ? "can" : "cannot")); + fprintf (stderr, + "rs6000_can_inline_p:, caller %s, callee %s, can inline.\n", + get_decl_name (caller), get_decl_name (callee)); - return ret; + return true; } + /* Allocate a stack temp and fixup the address so it meets the particular memory requirements (either offetable or REG+REG addressing). */ diff --git a/gcc/testsuite/gcc.target/powerpc/pr102059-1.c b/gcc/testsuite/gcc.target/powerpc/pr102059-1.c new file mode 100644 index 00000000000..d2a002cf141 --- /dev/null +++ b/gcc/testsuite/gcc.target/powerpc/pr102059-1.c @@ -0,0 +1,24 @@ +/* { dg-do compile } */ +/* { dg-require-effective-target powerpc_htm_ok } */ +/* { dg-options "-O2 -mdejagnu-cpu=power8" } */ + +/* Verify it emits inlining error msg at non-LTO mode. */ + +#include + +static inline int __attribute__ ((always_inline)) +foo (int *b) /* { dg-error "inlining failed in call to .* target specific option mismatch" } */ +{ + int res = _HTM_STATE(__builtin_ttest()); + *b += res; + return *b; +} + +#pragma GCC target "cpu=power10" +int +bar (int *a) +{ + *a = foo (a); /* { dg-message "called from here" } */ + return 0; +} + diff --git a/gcc/testsuite/gcc.target/powerpc/pr102059-2.c b/gcc/testsuite/gcc.target/powerpc/pr102059-2.c new file mode 100644 index 00000000000..1d5d6c38bf3 --- /dev/null +++ b/gcc/testsuite/gcc.target/powerpc/pr102059-2.c @@ -0,0 +1,20 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -mno-vsx" } */ + +/* Verify it emits inlining error msg when the callee has explicit + disabling option from command line. */ + +vector int c, a, b; + +static inline void __attribute__ ((__always_inline__)) +foo () /* { dg-error "inlining failed in call to .* target specific option mismatch" } */ +{ + c = a + b; +} + +__attribute__ ((target ("vsx"))) +int main () +{ + foo (); /* { dg-message "called from here" } */ + c = a + b; +} diff --git a/gcc/testsuite/gcc.target/powerpc/pr102059-3.c b/gcc/testsuite/gcc.target/powerpc/pr102059-3.c new file mode 100644 index 00000000000..9684cab986a --- /dev/null +++ b/gcc/testsuite/gcc.target/powerpc/pr102059-3.c @@ -0,0 +1,95 @@ +/* { dg-do compile } */ +/* -Wno-attributes suppresses always_inline warnings. */ +/* { dg-options "-O2 -mdejagnu-cpu=power8 -Wno-attributes" } */ + +/* Verify it doesn't emit inlining error msg since some mismatched + features are considered as safe for always_inline. */ + +/* 1. Callee enables Power8 fusion implicitly, while caller + with Power9 doesn't support power8 fusion at all. */ + +__attribute__ ((always_inline)) +int callee1 (int *b) +{ + *b += 1; + return *b; +} + +#pragma GCC target "cpu=power9" +int caller1 (int *a) +{ + *a = callee1 (a); + return 0; +} + +/* 2. Caller enables indirect toc save feature while callee + disables it explicitly. */ + +#pragma GCC target "save-toc-indirect" +__attribute__ ((always_inline)) +int callee2 (int *b) +{ + *b += 2; + return *b; +} + +#pragma GCC target "no-save-toc-indirect" +int caller2 (int *a) +{ + *a = callee2 (a); + return 0; +} + +/* 3. Caller disables Power10 fusion explicitly, while callee + still supports it as Power10 turns it on by default. */ + +#pragma GCC target "cpu=power10" +__attribute__ ((always_inline)) +int callee3 (int *b) +{ + *b += 3; + return *b; +} + +#pragma GCC target "cpu=power10,no-power10-fusion" +int caller3 (int *a) +{ + *a = callee3 (a); + return 0; +} + +/* 4. Caller enables Power10 fusion implicitly, while callee + disables it explicitly. */ + +#pragma GCC target "no-power10-fusion" +__attribute__ ((always_inline)) +int callee4 (int *b) +{ + *b += 4; + return *b; +} + +#pragma GCC target "cpu=power10" +int caller4 (int *a) +{ + *a = callee4 (a); + return 0; +} + +/* 5. Caller disables pcrel-opt while callee enables it explicitly. */ + +#pragma GCC target "cpu=power10,no-pcrel-opt" +__attribute__ ((always_inline)) +int callee5 (int *b) +{ + *b += 5; + return *b; +} + +#pragma GCC target "cpu=power10,pcrel-opt" +int caller5 (int *a) +{ + *a = callee5 (a); + return 0; +} + diff --git a/gcc/testsuite/gcc.target/powerpc/pr102059-4.c b/gcc/testsuite/gcc.target/powerpc/pr102059-4.c new file mode 100644 index 00000000000..0f27f2ce7d7 --- /dev/null +++ b/gcc/testsuite/gcc.target/powerpc/pr102059-4.c @@ -0,0 +1,22 @@ +/* { dg-do compile } */ +/* -Wno-attributes suppresses always_inline warnings. */ +/* { dg-options "-O2 -mdejagnu-cpu=power8 -mno-power8-fusion -Wno-attributes" } */ + +/* Verify it doesn't emit inlining error msg since the flag power8 + fusion is considered as safe for always_inline, it's still safe + even the flag is set explicitly. */ + +__attribute__ ((always_inline)) +int foo (int *b) +{ + *b += 10; + return *b; +} + +#pragma GCC target "power8-fusion" +int bar (int *a) +{ + *a = foo (a); + return 0; +} + diff --git a/gcc/testsuite/gcc.target/powerpc/pr102059-5.c b/gcc/testsuite/gcc.target/powerpc/pr102059-5.c new file mode 100644 index 00000000000..826ce88025f --- /dev/null +++ b/gcc/testsuite/gcc.target/powerpc/pr102059-5.c @@ -0,0 +1,22 @@ +/* { dg-do compile } */ +/* { dg-require-effective-target powerpc_htm_ok } */ +/* { dg-options "-O2 -mdejagnu-cpu=power8 -mhtm" } */ + +/* Verify the inlining won't perform when the callee requires + some target feature which isn't supported by caller, even + if the callee doesn't have any target attributes or pragmas. + If the inlining performs here, the compilation will fail. */ + +int +foo (int *b) +{ + *b += __builtin_ttest (); + return *b; +} + +__attribute__ ((target ("no-htm"))) int +bar (int *a) +{ + *a = foo (a); + return 0; +}