From patchwork Mon Jun 26 02:34:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hongyu Wang X-Patchwork-Id: 112703 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp7203955vqr; Sun, 25 Jun 2023 19:36:59 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ45El/Qz/DOLdh1Xe4UyfcC00jS11rON79yAYezortp9tSxP2WKnIvPk2HHzi44MLYZKphM X-Received: by 2002:a17:907:e93:b0:989:1a52:72b0 with SMTP id ho19-20020a1709070e9300b009891a5272b0mr17578518ejc.36.1687747019100; Sun, 25 Jun 2023 19:36:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687747019; cv=none; d=google.com; s=arc-20160816; b=YJ1s13NuW3venD4S+iU/dU54nEKkvun625iYXdvBBO7XYzZ0Ac6mGoE53UiJ+nezH9 QHYe0TbDUOQgEBoUe3volcz0iH1YXGNWd3G34Sg/5gZazjkB9KEsYB0xQ1hJmVg78j1U 0MsFHnKv90P6iX/b+p3gccy1Ix8W5tcrfpJdCoAGGgFnx9ZVNDPaOPDWepbyFVXj5Sjk B2VQqk0bMpkPC17SAQy/zwK6aZJWoY3uli/En7gOo7g0LgbvSMOXWa/4WsFh8a6QeVGw yKPWBSOKDQt1hEccxNHfZTUR9Ff9jZKVAMwtSCKW2N9cJ3ohTCJxKxSJ8kZQOqO4kk7X z1HA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=TBY4Xgn3Kr95SImwwotlrlPhJpFT26GUSsYQJDNEvAk=; fh=n8eNxIWSYJwy/CU3QSXzDvE/zeEoomCGojuOcYEQEyQ=; b=Shh/bYNzFRXY+tlCmJluBIIgy4B/pAYCeOCEr8IZH739K1NyUgqC6NdKfiAUhz5/99 02L1UUwFphIS7/pyQPMquVur+7fa2dOiZJ1oBjybVXja+ltxbm/SxCnN4wqcAKOM3+hk TFHQ2BEDJvMG8/kpuH2utkgr+0ioLjU0fIN0wUrCTjPlnOhzuKHpAx2Y2t7/WQzF4pCR DVGC9QACbChyfwiLkNVXJmNtg+/2uZwh6S+nL2n3tardqqdU0NKQS/28jSGrCanR81p4 ickzAwaA+AZyK6WKO6cvVNawN9tD7urONuQm4gUP8ml2bivYE8yP9tTWBVJ+DZPGyeag smpw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=uvKNlB+c; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id bm6-20020a170906c04600b0098d861faa62si2188512ejb.81.2023.06.25.19.36.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Jun 2023 19:36:59 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=uvKNlB+c; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BAC883858C2D for ; Mon, 26 Jun 2023 02:36:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BAC883858C2D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1687747017; bh=TBY4Xgn3Kr95SImwwotlrlPhJpFT26GUSsYQJDNEvAk=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=uvKNlB+cdviiHmqffAw4yWuJZV+lmIFhPnPr06DWMRovdWbvkKP7TvKD3EsX2SqKh yjXcsapl2pwnmXLgJLp0szaeqTlI4POOKVF0t+kcduUOzMe1hmAq+j76feNxM6/BDr z5QwApMiw/wv7tBQ/8jCSB9opuNiG7Mw1Xx5dteY= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by sourceware.org (Postfix) with ESMTPS id 78FC43858D20 for ; Mon, 26 Jun 2023 02:36:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 78FC43858D20 X-IronPort-AV: E=McAfee;i="6600,9927,10752"; a="340742649" X-IronPort-AV: E=Sophos;i="6.01,158,1684825200"; d="scan'208";a="340742649" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Jun 2023 19:36:10 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10752"; a="890133853" X-IronPort-AV: E=Sophos;i="6.01,158,1684825200"; d="scan'208";a="890133853" Received: from shvmail03.sh.intel.com ([10.239.245.20]) by orsmga005.jf.intel.com with ESMTP; 25 Jun 2023 19:36:08 -0700 Received: from shliclel4217.sh.intel.com (shliclel4217.sh.intel.com [10.239.240.127]) by shvmail03.sh.intel.com (Postfix) with ESMTP id 3651D100568D; Mon, 26 Jun 2023 10:36:08 +0800 (CST) To: gcc-patches@gcc.gnu.org Cc: ubizjak@gmail.com, hongtao.liu@intel.com Subject: [PATCH] i386: Relax inline requirement for functions with different target attrs Date: Mon, 26 Jun 2023 10:34:08 +0800 Message-Id: <20230626023408.33758-1-hongyu.wang@intel.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Spam-Status: No, score=-10.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_SHORT, SPF_HELO_PASS, SPF_SOFTFAIL, 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 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: Hongyu Wang via Gcc-patches From: Hongyu Wang Reply-To: Hongyu Wang Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769731017943291961?= X-GMAIL-MSGID: =?utf-8?q?1769731017943291961?= 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. 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) != (callee_opts->x_target_flags & ~always_inline_safe_mask)) ret = false; - /* See if arch, tune, etc. are the same. */ - else if (caller_opts->arch != callee_opts->arch) - ret = false; - - else if (!always_inline && caller_opts->tune != 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 != PVW_NONE + && caller_opts->x_prefer_vector_width_type != PVW_NONE) + && callee_opts->x_prefer_vector_width_type + != caller_opts->x_prefer_vector_width_type) ret = false; else if (caller_opts->x_ix86_fpmath != callee_opts->x_ix86_fpmath diff --git a/gcc/testsuite/gcc.target/i386/inline-target-attr.c b/gcc/testsuite/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=skylake"))) +int callee (int n) +{ + int sum = 0; + for (int i = 0; i < n; i++) + { + if (i % 2 == 0) + sum +=i; + else + sum += (i - 1); + } + return sum + n; +} + +__attribute__((target("arch=icelake-server"))) +int caller (int n) +{ + return callee (n) + n; +} +