Open 0xDRRB opened 1 year ago
@llvm/issue-subscribers-backend-x86
I'll take a look at this
The first set is particularly strange because some of those are 64-bit instructions. I thought we rejected 32-bit -mcpu on 64-bit targets
But then again -mcpu
isn't a valid x86 option. It's -march
for X86
I tried with: clang -c -S -m32 -march=pentium-mmx
and the output contained no cmoves
But changing to clang -c -S -m32 -march=pentium4
did contain cmoves
@0xDRRB Please can you try with -march=pentium-mmx (or -march=native)?
Here it is:
$ clang -march=native -S -Wall main.c `pkg-config --cflags libnfc`
$ grep cmovne main.s
[nothing]
Same with -O2
:
$ clang -march=native -O2 -S -Wall main.c `pkg-config --cflags libnfc`
$ grep cmovne main.s
[nothing]
If i drop the -march
:
$ clang -O2 -S -Wall main.c `pkg-config --cflags libnfc`
$ grep cmovne main.s
cmovnel %edx, %eax
cmovnel %edx, %ecx
cmovnel %ecx, %eax
All of this is on the Pentium MMX box.
So the problem appears to be that the default 32-bit CPU has CMOV enabled (and maybe other x86-64 default settings, SSE2 etc.) - but I thought this was true for gcc as well?
So the problem appears to be that the default 32-bit CPU has CMOV enabled (and maybe other x86-64 default settings, SSE2 etc.) - but I thought this was true for gcc as well?
This is because clang defaults to pentium4 when no -march flags are specified for i386. https://github.com/llvm/llvm-project/blob/main/clang/lib/Driver/ToolChains/Arch/X86.cpp#L115
CPU target: i586, Clang
-O2
generates code that is not supported and program crash with illegal instruction. Illegal instruction is:cmovne
Tested on AMD64 with
-mcpu
and on physical box, both running FreeBSD 13.1.This bug was detected with this project: https://gitlab.com/0xDRRB/st25.
On i586 box: