Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp87108pxb; Mon, 7 Feb 2022 06:59:59 -0800 (PST) X-Google-Smtp-Source: ABdhPJwD7BnTfC80JQ+Io4aa5P/c/rmH2uDGGxZIpKjjiNe4YvASbBZ2msicvqcCoYNxaz4oW3ff X-Received: by 2002:a17:90b:4b01:: with SMTP id lx1mr19086250pjb.158.1644245999562; Mon, 07 Feb 2022 06:59:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644245999; cv=none; d=google.com; s=arc-20160816; b=Xf+OlOZjL8OgAnzad/exYOOxIOx4RIkhZCT1BzUiu/2xGWXWeH9N4tKSAiE3/gBvwj uZ5W5rxAeghSz5/t+Y8yV97ePEwN6QVF4PmJ/aBcDyVyK/0Q0sV6ViXLkRCUa+fC/1Qj 2jIXvxk/xeOGLsIIogFKnrvmQOzFhBVt5Fnc4H90zh72CGtlgPbaR7kFVwd+HiGzPGxO iPSLUg6QR6t2tTyqMKLGB5CN0sPxMMz8gjPBtknKeXp3z4BANyt1WIB+Y+Lcjm7O09jb tApEGXQijpQ2V2HPfuRGRseWh9gBO3lYi7on9mtg4xwvIUEJLOGULEo/VxQKLLXVd8Zi NPEw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:references :in-reply-to:subject:cc:to:dkim-signature:dkim-signature:from; bh=Y3pautk4858+TJ9acUt+lAWsSvXk3yXbgosZPH/JGB0=; b=nR3nSABL5MYyIpEoGI85jP05zuy/mDc2rzBTLIngC0sfG/d686O53VkDKt0V+mbERs ZlGlRxi6FfoDnBnIPM+XQCPtTtIMANqjeOgORKAZghogIkB9hVws+R3w8Frxqr/T7htt bUwNcen6HsojYiBi/49Ombebx1rtVe986ULldY3zNkM6MSscydmLk4XsltOL+nG18vKe ZqWoZdzul0CDppyJFa8JLM5Rigr6M6SNUxhxZfk6jv9dyLKnDFfHVC5Er4qjPUR2cKF6 2KN/whd9dWy+buDmsHqgwXlatpEykE2GwgRPxAMEx05bD0yH1GmDh72+Dmw7OVwqVhtD pB+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=lDl+divr; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b="T/pAjUzA"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j22si9161381pll.304.2022.02.07.06.59.48; Mon, 07 Feb 2022 06:59:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=lDl+divr; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b="T/pAjUzA"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1356186AbiBDAQw (ORCPT + 99 others); Thu, 3 Feb 2022 19:16:52 -0500 Received: from Galois.linutronix.de ([193.142.43.55]:56660 "EHLO galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245100AbiBDAQv (ORCPT ); Thu, 3 Feb 2022 19:16:51 -0500 From: Thomas Gleixner DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1643933809; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=Y3pautk4858+TJ9acUt+lAWsSvXk3yXbgosZPH/JGB0=; b=lDl+divrl1HxJj7DuZlTTW/hUAVdkO4dlZVtUM/TjyS9/2dN4ITrrXY/CZSZoBF642Jdgt picK1Dq6DTcF0vGDvxrKQv+spk4SqsvePh2DC8pt3+A2296ub5yrqnOxQGVV/gLVV4bubf wA9GpUDVTkfcyXgpsvk75pR8IATm4Oqt4+7FV8iJ8rRC1SHhci1MY74O3RKqkV1CDq+Emc DgzSvuiCFJft0bxEAUdjfec4IrNKkHVxP5oXs9mdqOBoHvRJBFh9bvQe3zqaE/scPrcanR Q8G2I+2RuPG3k7NoN71n97IL7AoHVKZ3xoA94g273Rq5FFFTlmJtAccUXC97cw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1643933809; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=Y3pautk4858+TJ9acUt+lAWsSvXk3yXbgosZPH/JGB0=; b=T/pAjUzAgPMK6ILlOcLrLAemCTNHEAYYWzD+tdSBMKXaKMFMlfVQj/kK/hA3rtA5NvEHXS rZkMX2SoR/AYssCg== To: Bill Wendling , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H . Peter Anvin" , Nathan Chancellor , Nick Desaulniers , Juergen Gross , Peter Zijlstra , Andy Lutomirski , llvm@lists.linux.dev Cc: linux-kernel@vger.kernel.org, Bill Wendling Subject: Re: [PATCH v2] x86: use builtins to read eflags In-Reply-To: <20211229021258.176670-1-morbo@google.com> References: <20211215211847.206208-1-morbo@google.com> <20211229021258.176670-1-morbo@google.com> Date: Fri, 04 Feb 2022 01:16:49 +0100 Message-ID: <87mtj7cwpa.ffs@tglx> MIME-Version: 1.0 Content-Type: text/plain Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Dec 28 2021 at 18:12, Bill Wendling wrote: > GCC and Clang both have builtins to read and write the EFLAGS register. > This allows the compiler to determine the best way to generate this > code, which can improve code generation. > > This issue arose due to Clang's issue with the "=rm" constraint. Clang > chooses to be conservative in these situations, and so uses memory > instead of registers. This is a known issue, which is currently being > addressed. > > However, using builtins is benefiical in general, because it removes the > burden of determining what's the way to read the flags register from the > programmer and places it on to the compiler, which has the information > needed to make that decision. Indeed, this piece of code has had several > changes over the years, some of which were pinging back and forth to > determine the correct constraints to use. > > With this change, Clang generates better code: > > Original code: > movq $0, -48(%rbp) > #APP > # __raw_save_flags > pushfq > popq -48(%rbp) > #NO_APP > movq -48(%rbp), %rbx > > New code: > pushfq > popq %rbx > #APP > > Note that the stack slot in the original code is no longer needed in the > new code, saving a small amount of stack space. This still lacks any information about the effect on GCC. There is a world outside clang. It's not my job to validate that. Thanks, tglx