From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ot1-x333.google.com (mail-ot1-x333.google.com [IPv6:2607:f8b0:4864:20::333]) by sourceware.org (Postfix) with ESMTPS id 35C4D385800F for ; Thu, 22 Apr 2021 11:58:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 35C4D385800F Received: by mail-ot1-x333.google.com with SMTP id c8-20020a9d78480000b0290289e9d1b7bcso27802425otm.4 for ; Thu, 22 Apr 2021 04:58:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=YNnjLh5cToLTZOmh/DtJSxrnaqb7bdEjvz5ka2AByVc=; b=Bvmay+NMvI1H0OHi0N6injb7+q9578jdf4+LR2ZA5nxId3btQSuIqlEysOQ4BhyhLI 1r46OUQBN1rUqr07rEx+Q0VGvrsNnB6JnbLxQsgsSn2c+GZ9SJmoLWm99A0kdHZrEGvi BuoUc3OkY1CcmOHRPZZcnrrqux7qzCekOF1GJPnqmmPuz7q0HiWo+2vOin/cG11aOUDk M0Vz0iKkN4uZbXYQZzjVCNtaMsZ/bL73sGOPEZHmvuLw5lWYlDai6QnEe4DQeyvqPknE d1pTSCPucV85ZEM9t1+h8RiMn+YekYPyF9BeB6zGUVhXGLECl9xsecS+H/Zk8Yk+8Xda 4X0g== X-Gm-Message-State: AOAM532uuEasLoPVbrrNZGmvFC3JtnVWxZOegtN6g4K4lkYCDt/VicUJ J/gyJZR0i+T7iSxxRt95G2mLQbcNBWe9ghQhDss= X-Google-Smtp-Source: ABdhPJy0h4r6G4DK3tLeCwpirhXwDf/zOcxpJxUR7WDtXxCGth+09yF+0iayAdM3yUAuYmSNDpDtHOMCQkAJPESGoWk= X-Received: by 2002:a9d:12e:: with SMTP id 43mr2591410otu.90.1619092692614; Thu, 22 Apr 2021 04:58:12 -0700 (PDT) MIME-Version: 1.0 References: <20210414223918.230495-1-hjl.tools@gmail.com> <20210414223918.230495-3-hjl.tools@gmail.com> <20210422090201.GO1179226@tucnak> In-Reply-To: From: "H.J. Lu" Date: Thu, 22 Apr 2021 04:57:36 -0700 Message-ID: Subject: Re: [PATCH v4 2/2] x86: Add general_regs_only function attribute To: Richard Biener Cc: Jakub Jelinek , GCC Patches Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-3028.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, 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: , X-List-Received-Date: Thu, 22 Apr 2021 11:58:14 -0000 On Thu, Apr 22, 2021 at 4:23 AM Richard Biener wrote: > > On Thu, Apr 22, 2021 at 12:30 PM Jakub Jelinek via Gcc-patches > wrote: > > > > On Wed, Apr 21, 2021 at 06:01:07PM -0700, H.J. Lu via Gcc-patches wrote: > > > How about this? > > > > > > @item general_regs_only > > > @cindex @code{general_regs_only} function attribute, x86 > > > The @code{general_regs_only} function attribute informs the compiler > > > that the function uses only general purpose registers. When the > > > compiler inlines a function with the @code{always_inline} attribute, > > > target-specific compilation options may lead to inline failures. > > > The @code{general_regs_only} attribute, if applicable, can be used > > > together with the @code{always_inline} attribute to reduce inlining > > > failure. > > > > I don't really like this attribute. > > It is very specific to what you want to solve and doesn't address the > > general problem, that always_inline means different things in different > > code, and that is a problem for many targets, not just one. > > > > As has been written, in some cases it means inline always, error > > whenever it is called indirectly which can't be optimized into a direct > > call that can be inlined and error whenever the inlining fails for other > > reasons. > > > > Another case, e.g. in the glibc fortify wrappers, is inline always > > when the call is direct or an indirect call can be optimized into a direct > > call and error when the inlining fails, but support indirect calls without > > errors. > > > > Another case, which is most of the x86/aarch64/arm etc. intrinsics, is > > inline always unless there is a target mismatch (roughly what is > > actually implemented). > > > > Because from the always_inline attribute it is impossible to determine which > > one of those it is (for the indirect calls the rule could be > > gnu_inline extern inline means indirect calls are ok, anything else means > > indirect calls are bad), we need new syntax to distinguish those cases. > > > > general_regs_only attribute doesn't seem to be it, e.g. for the glibc > > fortify wrappers cases I don't see why we should forbid using floating point > > in such inlines. > > > > So IMHO we need some new attribute for one of those, or optional parameter > > to always_inline. > > > > For the intrinsic case, ideal would be if we could record which ISA flags > > (or more generally which options) are required and which are not. Either > > have some syntax where those would be explicitly specified in attribute (but > > frankly that would be a maintainance nightmare), or derive those from > > surrounding pragmas. Right now we have those wrapped in > > #ifndef __AVX2__ > > #pragma GCC push_options > > #pragma GCC target("avx2") > > #define __DISABLE_AVX2__ > > #endif /* __AVX2__ */ > > > > ... > > > > #ifdef __DISABLE_AVX2__ > > #undef __DISABLE_AVX2__ > > #pragma GCC pop_options > > #endif /* __DISABLE_AVX2__ */ > > > > The question is if the pragma GCC target right now behaves incrementally > > or not, whether > > #pragma GCC target("avx2") > > adds -mavx2 to options if it was missing before and nothing otherwise, or if > > it switches other options off. If it is incremental, we could e.g. try to > > use the second least significant bit of global_options_set.x_* to mean > > this option has been set explicitly by some surrounding #pragma GCC target. > > The normal tests - global_options_set.x_flag_whatever could still work > > fine because they wouldn't care if the option was explicit from anywhere > > (command line or GCC target or target attribute) and just & 2 would mean > > it was explicit from pragma GCC target; though there is the case of > > bitfields... And then the inlining decision could check the & 2 flags to > > see what is required and what is just from command line. > > Or we can have some other pragma GCC that would be like target but would > > have flags that are explicit (and could e.g. be more restricted, to ISA > > options only, and let those use in addition to #pragma GCC target. > > I'm still curious as to what you think will break if always-inline does what > it is documented to do. No wrong code. But the compiler will generate a different error message at the later stage if the ISA for the intrinsic isn't enabled. -- H.J.