From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ej1-f47.google.com (mail-ej1-f47.google.com [209.85.218.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 08CDD2F26 for ; Fri, 4 Feb 2022 00:59:08 +0000 (UTC) Received: by mail-ej1-f47.google.com with SMTP id s5so14116609ejx.2 for ; Thu, 03 Feb 2022 16:59:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=wx9zL515JtmLncGQm93eWQntb/DTkqy+sgfVCpkbAp4=; b=FPro4IaRcta3YpRSuo7Os1sx9brg4nB9U+Ay5jgMt/rH0CTtD4+2q8W5O8PmupD5rP X+ZDD0fbMdszPz+6S4QjxxPMM6QLRmuub03JdPQN9mFtLzP66Xjv+U4ZH4dgJCKwk508 lbEZdqQf0jF79Za06EQzlV27DCn4i5bEzDBAxJQBOvzeGOzzkz+dvTu7HEYP5+OY1ouT 5F/iY6i21ny22utCHBQh+87VywUISYY7iXzye4FUW10DsrNROis1J5vnxdylJ/l7w8xC /TFF65bRaLEqH9PxXnIOv6dSlh2ivxWgzN67uoQiF9J3zENr0wnK5S83if/VqLhEPF6a XxAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=wx9zL515JtmLncGQm93eWQntb/DTkqy+sgfVCpkbAp4=; b=OkFu5g2j8fjrJnysxddS2GJ8UqKxwsxCTCPvYWoixctQrlbHnWaa7whqrYNszAJjl/ JJrCTCanKMs7EG8eBQFs9V4ZrGrxrOPPI3jIpTRqzP/8LCyRXjeNcfT3LCYEhw6QToJn iDtf+1vAnzVr1In7ZS0wlXQSF7dZCWgIC4O6geqiKtBpUihpP0UZFFSJn1WINvLjSvuC 0b6Lcn8jjOQlM3bvJ0LWTjkqsyPf/PL8nk32g9QSgbpdtsh2OKWj9Wk8UIiWYu9yNuzl f1loiW7VuD7h4W2lysIMtHKDfgEQOVJjQ7Ze61AiDKtn2PgA7XoOWVRkJ7J2jKBD5qPl 8low== X-Gm-Message-State: AOAM532Hrk81Hws3zVi9+fh9FrmuGps6JZqWI5LB0/zXTUyr5JVUQZQC RWxeXRTaQswQBELy2CY6nQKkvy/2MOKSFx9i0oT8 X-Google-Smtp-Source: ABdhPJxZm8zlXltXg56zyniqAOvjtYuG3I9y6xBCgyqrjpAnGwwHKWd8QK8IhscrAzso7zlHoLO77uQ1pVrFth2RxPw= X-Received: by 2002:a17:907:9804:: with SMTP id ji4mr433075ejc.232.1643936347092; Thu, 03 Feb 2022 16:59:07 -0800 (PST) Precedence: bulk X-Mailing-List: llvm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20211215211847.206208-1-morbo@google.com> <20211229021258.176670-1-morbo@google.com> <87mtj7cwpa.ffs@tglx> In-Reply-To: <87mtj7cwpa.ffs@tglx> From: Bill Wendling Date: Thu, 3 Feb 2022 16:58:55 -0800 Message-ID: Subject: Re: [PATCH v2] x86: use builtins to read eflags To: Thomas Gleixner Cc: Ingo Molnar , Borislav Petkov , Dave Hansen , "maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)" , "H . Peter Anvin" , Nathan Chancellor , Nick Desaulniers , Juergen Gross , Peter Zijlstra , Andy Lutomirski , llvm@lists.linux.dev, LKML Content-Type: text/plain; charset="UTF-8" On Thu, Feb 3, 2022 at 4:16 PM Thomas Gleixner wrote: > > 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. > I never said you were the one required to validate that. I'm not sure where you got that idea from. There of course is no change to GCC's output. I updated the commit message and sent out v3. PTAL. -bw