public inbox for llvm@lists.linux.dev
 help / color / mirror / Atom feed
* [PATCH] [RFC] x86: avoid -mtune=atom with clang
@ 2021-10-19 17:11 Arnd Bergmann
  2021-10-19 19:01 ` Miguel Ojeda
  0 siblings, 1 reply; 2+ messages in thread
From: Arnd Bergmann @ 2021-10-19 17:11 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, x86,
	Nathan Chancellor, Nick Desaulniers
  Cc: Arnd Bergmann, H. Peter Anvin, Masahiro Yamada, Andy Lutomirski,
	Miguel Ojeda, linux-kernel, llvm

From: Arnd Bergmann <arnd@arndb.de>

The clang optimization for atom results in a large number of objtool
warnings like

  drivers/video/hdmi.o: warning: objtool: hdmi_infoframe_check()+0x74: unreachable instruction
  lib/crypto/curve25519.o: warning: objtool: init_module()+0x12: unreachable instruction
  drivers/clk/bcm/clk-iproc-armpll.o: warning: objtool: iproc_armpll_setup()+0x10c: unreachable instruction
  drivers/video/fbdev/core/cfbfillrect.o: warning: objtool: cfb_fillrect()+0xa2: unreachable instruction
  drivers/clk/bcm/clk-iproc-pll.o: warning: objtool: iproc_pll_clk_setup()+0x36d: unreachable instruction
  drivers/clk/bcm/clk-iproc-asiu.o: warning: objtool: iproc_asiu_setup()+0x2cf: unreachable instruction

and in rare cases problems with the register allocator:

  arch/x86/crypto/curve25519-x86_64.c:610:3: error: inline assembly requires more registers than available

  error: ran out of registers during register allocation

All of those can be avoided by changing the -mtune= option for
clang, leaving the -march= option unchanged. It's really a bug
that should be fxied in llvm, but it's fairly clear that the
atom optimizations are not well exercised in llvm, so not
using them is probably the safe choice regardless.

Link: https://github.com/ClangBuiltLinux/linux/issues/1483
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 arch/x86/Makefile        | 4 ++++
 arch/x86/Makefile_32.cpu | 4 ++++
 2 files changed, 8 insertions(+)

diff --git a/arch/x86/Makefile b/arch/x86/Makefile
index 7488cfbbd2f6..4c6f92b32385 100644
--- a/arch/x86/Makefile
+++ b/arch/x86/Makefile
@@ -120,7 +120,11 @@ else
         cflags-$(CONFIG_MK8)		+= -march=k8
         cflags-$(CONFIG_MPSC)		+= -march=nocona
         cflags-$(CONFIG_MCORE2)		+= -march=core2
+ifdef CONFIG_CC_IS_CLANG
+        cflags-$(CONFIG_MATOM)		+= -march=atom -mtune=generic
+else
         cflags-$(CONFIG_MATOM)		+= -march=atom
+endif
         cflags-$(CONFIG_GENERIC_CPU)	+= -mtune=generic
         KBUILD_CFLAGS += $(cflags-y)
 
diff --git a/arch/x86/Makefile_32.cpu b/arch/x86/Makefile_32.cpu
index 94834c4b5e5e..a17b089f367c 100644
--- a/arch/x86/Makefile_32.cpu
+++ b/arch/x86/Makefile_32.cpu
@@ -33,8 +33,12 @@ cflags-$(CONFIG_MCYRIXIII)	+= $(call cc-option,-march=c3,-march=i486) $(align)
 cflags-$(CONFIG_MVIAC3_2)	+= $(call cc-option,-march=c3-2,-march=i686)
 cflags-$(CONFIG_MVIAC7)		+= -march=i686
 cflags-$(CONFIG_MCORE2)		+= -march=i686 $(call tune,core2)
+ifdef CONFIG_CC_IS_CLANG
+cflags-$(CONFIG_MATOM)		+= -march=atom -mtune=generic
+else
 cflags-$(CONFIG_MATOM)		+= $(call cc-option,-march=atom,$(call cc-option,-march=core2,-march=i686)) \
 	$(call cc-option,-mtune=atom,$(call cc-option,-mtune=generic))
+endif
 
 # AMD Elan support
 cflags-$(CONFIG_MELAN)		+= -march=i486
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] [RFC] x86: avoid -mtune=atom with clang
  2021-10-19 17:11 [PATCH] [RFC] x86: avoid -mtune=atom with clang Arnd Bergmann
@ 2021-10-19 19:01 ` Miguel Ojeda
  0 siblings, 0 replies; 2+ messages in thread
From: Miguel Ojeda @ 2021-10-19 19:01 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT),
	Nathan Chancellor, Nick Desaulniers, Arnd Bergmann,
	H. Peter Anvin, Masahiro Yamada, Andy Lutomirski, Miguel Ojeda,
	linux-kernel, llvm

On Tue, Oct 19, 2021 at 7:11 PM Arnd Bergmann <arnd@kernel.org> wrote:
>
> +ifdef CONFIG_CC_IS_CLANG
> +        cflags-$(CONFIG_MATOM)         += -march=atom -mtune=generic
> +else
>          cflags-$(CONFIG_MATOM)         += -march=atom
> +endif

Is it possible to factor it out? Also, a comment with the LLVM version
we last checked would be good. Something like...

    cflags-$(CONFIG_MATOM)         += -march=atom

    # Atom optimizations do not seem well exercised in, at least, LLVM <= 13,
    # to the point of getting problems with register allocation.
    ifdef CONFIG_CC_IS_CLANG
            cflags-$(CONFIG_MATOM)         += -mtune=generic
    endif

Cheers,
Miguel

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-10-19 19:01 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-10-19 17:11 [PATCH] [RFC] x86: avoid -mtune=atom with clang Arnd Bergmann
2021-10-19 19:01 ` Miguel Ojeda

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox