llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
27.83k stars 11.46k forks source link

LTO default target CPU should be "pentium4" for 32-bit Linux #23089

Open llvmbot opened 9 years ago

llvmbot commented 9 years ago
Bugzilla Link 22715
Version 3.6
OS Linux
Attachments lto cpu patch
Reporter LLVM Bugzilla Contributor
CC @echristo

Extended Description

... otherwise codegening bitcode files may fail:

For explanation: bc2obj is a tool I wrote to convert bitcode libraries into native ones, now feeding it with Linux 32-bit LLVM libraries I came accross the following problem:

$ bc2obj [...]libclangBasic.a [...] codegen'ing [...]libclangBasic.a(SourceManager.o) to /tmp/-9b1d81/SourceManager.o LLVM ERROR: Do not know how to split this operator's operand!

Inspecting the compilation command reveals that the default 32-bit target cpu is "pentium4":

$ clang++ -m32 [...] -fPIC -fvisibility-inlines-hidden [...] -fdata-sections -O3 -DNDEBUG [...] SourceManager.cpp -flto -c -v "/opt/compiler/llvm-3.6/bin/clang-3.6" -cc1 -triple i386-unknown-linux-gnu -emit-llvm-bc [...] -target-cpu pentium4 [...]

Now either setting the target cpu to pentium4 or enabling sse2 gets rid of the problem:

$ bc2obj SourceManager.o -cpu=pentium4 codegen'ing SourceManager.o to native/SourceManager.o

$ file native/SourceManager.o native/SourceManager.o: ELF 32-bit LSB relocatable, Intel 80386, version 1 (GNU/Linux), not stripped

$ bc2obj SourceManager.o -attrs=+sse2 codegen'ing SourceManager.o to native/SourceManager.o

$ file native/SourceManager.o native/SourceManager.o: ELF 32-bit LSB relocatable, Intel 80386, version 1 (GNU/Linux), not stripped

A possible fix is attached (but totally untested besides the pentium4 part).

llvmbot commented 9 years ago

Oh, I see, clang is passing the cpu name via -plugin-opt=mcpu. So I am actually no longer sure if this is really a bug, but the "isOSDarwin()" code there makes me think so.

No, what I mean is that if a file is compiled with avx and another one with sse2, that information is to be recorded and used when outputting functions from each file.

I think you got me wrong there. What I mean with "I am no longer sure if this is a bug or not", is, if it's considered a bug that clang's and LLVM's default target cpus do not match on non-Darwin systems (for <= 3.6 - as the per function recording won't land there).

echristo commented 9 years ago

Rafael's comments are correct.

llvmbot commented 9 years ago

Oh, I see, clang is passing the cpu name via -plugin-opt=mcpu. So I am actually no longer sure if this is really a bug, but the "isOSDarwin()" code there makes me think so.

No, what I mean is that if a file is compiled with avx and another one with sse2, that information is to be recorded and used when outputting functions from each file.

llvmbot commented 9 years ago

Eric is working on recording this information per function.

Good to know.

It should be whatever was passed to clang.

Oh, I see, clang is passing the cpu name via -plugin-opt=mcpu. So I am actually no longer sure if this is really a bug, but the "isOSDarwin()" code there makes me think so.

llvmbot commented 9 years ago

It should be whatever was passed to clang.

Eric is working on recording this information per function.