From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qv1-xf2e.google.com (mail-qv1-xf2e.google.com [IPv6:2607:f8b0:4864:20::f2e]) by sourceware.org (Postfix) with ESMTPS id 86A363858D28 for ; Tue, 27 Jun 2023 09:16:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 86A363858D28 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-qv1-xf2e.google.com with SMTP id 6a1803df08f44-635eb5b0320so8166086d6.3 for ; Tue, 27 Jun 2023 02:16:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1687857378; x=1690449378; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=3YOTgPkCpGrtz8ywgOcLZrWukLVc8uEsdACGhwpezDg=; b=VRl7/PezqsbGiOTU31kb1oaQ3H+st0in9ecdilV/FXB6VCOdfJgc0mvq2nAqfH5+bw hTAmCAarKCSPKzuSH5m7AAmGqEbvMlk85bOLRUj+W2w2xtoVv0efxYqudIoMj1YZPZgZ 6gN5tpzccVE8W8FAwMDV5m1CaPWFlFZPHmXJqdjvYBrwduqh3ZPwHgX9Py+zRRNwInBv 6vHRsAK+qXr6U+OU1oZZboXJ5OnXXz/0riZjKs07D32ATik8dDD4FeeEDxCE96qpRdtB 82bCnhyst3ystCcphkqAuF206nGXWzf/olslF8lW4l6y/F8WW2CJi6bMpwapKrkqSKSQ roEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687857378; x=1690449378; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3YOTgPkCpGrtz8ywgOcLZrWukLVc8uEsdACGhwpezDg=; b=E4p475V9xOMNYbWM5abk9+Bxt+xUcqE/S6RWYnDlx13IOTMhb7o1kwxrIB1riLqZme kmbWEEyxRUzwhQA/g5CF/O0p/3lLpPHcfrA/uNQkADA+pSqGkaiBEX1in3fkkYd3kTCe DVVyPGk/Y0IfE4C+N66K5e/tCrWO7d4y5QKbuSo8Ck/nqqoyYFqJQ5Qx+ZT2dMuccrrx IcmrZgC1iLmgUZPpRgdN05mro2sWNBaTCzCFrY8gMy7fkjwpHC+5twGIgnV80f2ff6F/ 9Cr36FkP0o0YljauwSv2p/Uv4gX3wolZcg35qR924fEH4pr79ZfS4mw7VpcamvVtXrTQ gMbg== X-Gm-Message-State: AC+VfDxDqlQ3qUAzQpbT+V80+qpo6OEf2T2SxnGnEZtq7TkWTE4LaH9u clyaOwHG6avI9tRih30XMgW4VQt5Hr3JXo5nyIU= X-Google-Smtp-Source: ACHHUZ6xDrYs5NViS01iGGIFiEJG1dzxI1zmFLRjk2PvGcaEoCzoiwADchvCdQbVkoKwBh7468dMlP8B5qF8ym7q9XY= X-Received: by 2002:a05:6214:2a4f:b0:635:de52:8385 with SMTP id jf15-20020a0562142a4f00b00635de528385mr8746404qvb.65.1687857377849; Tue, 27 Jun 2023 02:16:17 -0700 (PDT) MIME-Version: 1.0 References: <20230626023408.33758-1-hongyu.wang@intel.com> In-Reply-To: <20230626023408.33758-1-hongyu.wang@intel.com> From: Uros Bizjak Date: Tue, 27 Jun 2023 11:16:06 +0200 Message-ID: Subject: Re: [PATCH] i386: Relax inline requirement for functions with different target attrs To: Hongyu Wang Cc: gcc-patches@gcc.gnu.org, hongtao.liu@intel.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-8.4 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,KAM_SHORT,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE 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 Mon, Jun 26, 2023 at 4:36=E2=80=AFAM Hongyu Wang = wrote: > > Hi, > > For function with different target attributes, current logic rejects to > inline the callee when any arch or tune is mismatched. Relax the > condition to honor just prefer_vecotr_width_type and other flags that > may cause safety issue so caller can get more optimization opportunity. I don't think this is desirable. If we inline something with different ISAs, we get some strange mix of ISAs when the function is inlined. OTOH - we already inline with mismatched tune flags if the function is marked with always_inline. Uros. > Bootstrapped/regtested on x86_64-pc-linux-gnu{-m32,} > > Ok for trunk? > > gcc/ChangeLog: > > * config/i386/i386.cc (ix86_can_inline_p): Do not check arch or > tune directly, just check prefer_vector_width_type and make sure > not to inline if they mismatch. > > gcc/testsuite/ChangeLog: > > * gcc.target/i386/inline-target-attr.c: New test. > --- > gcc/config/i386/i386.cc | 11 +++++---- > .../gcc.target/i386/inline-target-attr.c | 24 +++++++++++++++++++ > 2 files changed, 30 insertions(+), 5 deletions(-) > create mode 100644 gcc/testsuite/gcc.target/i386/inline-target-attr.c > > diff --git a/gcc/config/i386/i386.cc b/gcc/config/i386/i386.cc > index 0761965344b..1d86384ac06 100644 > --- a/gcc/config/i386/i386.cc > +++ b/gcc/config/i386/i386.cc > @@ -605,11 +605,12 @@ ix86_can_inline_p (tree caller, tree callee) > !=3D (callee_opts->x_target_flags & ~always_inline_safe_ma= sk)) > ret =3D false; > > - /* See if arch, tune, etc. are the same. */ > - else if (caller_opts->arch !=3D callee_opts->arch) > - ret =3D false; > - > - else if (!always_inline && caller_opts->tune !=3D callee_opts->tune) > + /* Do not inline when specified perfer-vector-width mismatched between > + callee and caller. */ > + else if ((callee_opts->x_prefer_vector_width_type !=3D PVW_NONE > + && caller_opts->x_prefer_vector_width_type !=3D PVW_NONE) > + && callee_opts->x_prefer_vector_width_type > + !=3D caller_opts->x_prefer_vector_width_type) > ret =3D false; > > else if (caller_opts->x_ix86_fpmath !=3D callee_opts->x_ix86_fpmath > diff --git a/gcc/testsuite/gcc.target/i386/inline-target-attr.c b/gcc/tes= tsuite/gcc.target/i386/inline-target-attr.c > new file mode 100644 > index 00000000000..995502165f0 > --- /dev/null > +++ b/gcc/testsuite/gcc.target/i386/inline-target-attr.c > @@ -0,0 +1,24 @@ > +/* { dg-do compile } */ > +/* { dg-options "-O2" } */ > +/* { dg-final { scan-assembler-not "call\[ \t\]callee" } } */ > + > +__attribute__((target("arch=3Dskylake"))) > +int callee (int n) > +{ > + int sum =3D 0; > + for (int i =3D 0; i < n; i++) > + { > + if (i % 2 =3D=3D 0) > + sum +=3Di; > + else > + sum +=3D (i - 1); > + } > + return sum + n; > +} > + > +__attribute__((target("arch=3Dicelake-server"))) > +int caller (int n) > +{ > + return callee (n) + n; > +} > + > -- > 2.31.1 >