compiler-explorer / compiler-explorer

Run compilers interactively from your web browser and interact with the assembly
https://godbolt.org/
BSD 2-Clause "Simplified" License
16.02k stars 1.72k forks source link

[BUG]: ICX Assembly comments for AVX2 Intrinsics are missing when using cmake #6550

Open petrock99 opened 3 months ago

petrock99 commented 3 months ago

Describe the bug

If I set up source editor to use icx-2023.1.0 with some C code that uses AVX2 Intrinsics there will be comments next to some of the corresponding assembly instructions. i.e. # AlignMOV convert to UnAlignMOV, # ymm0 = (ymm1 * ymm0) + mem or the ever important # 32-byte Spill.

But if I build the same exact code with cmake these comments are missing. Maybe I'm missing a flag in the CMakeLists.txt to enable this feature in Compiler Explorer?

Steps to reproduce

Expected behavior

Both compiler sections should show identical content, including the assembly comments.

square:
  vmovupd ymm1, ymmword ptr [rdi] # AlignMOV convert to UnAlignMOV   vmovupd ymm0, ymmword ptr [rdi + 8] # AlignMOV convert to UnAlignMOV   vfmadd213pd ymm0, ymm1, ymmword ptr [rdi + 16] *# ymm0 = (ymm1 ymm0) + mem**

Reproduction link

https://godbolt.org/z/v7zqfv9vd

Screenshots

Screenshot 2024-06-01 at 8 38 59 PM

Operating System

macOS 14.5

Browser version

Safari 17.5

petrock99 commented 3 months ago

When I click the Green Checkmark to see the compilation options used the compiler on the left shows: -gdwarf-4 -g -o output.s -masm=intel -S --gcc-toolchain=/opt/compiler-explorer/gcc-13.1.0 -fcolor-diagnostics -fno-crash-diagnostics -std=c11 -O3 -g -march=alderlake -mtune=alderlake example.c

and the compiler on the right shows: -fcolor-diagnostics -fno-crash-diagnostics

Sadly, if I add -gdwarf-4, -masm=intel and --gcc-toolchain=/opt/compiler-explorer/gcc-13.1.0 to the add_compile_options section in the CMakeLists.txt the problem still reproduces.

Another thing that is interesting is the compiler section on the left has slightly different assembly for the vfmadd213pd instruction: left: [rdi + 16] right: [rdi+0x10]

It's decimal vs hex. I'm not sure if that is related to this bug or not, or if I somehow enabled some formatting feature.

partouf commented 3 months ago

ASM shown when using CMake, is equivalent to using 'Link to binary' when compiling a file directly. (It is compiled and then the executable is disassembled with objdump)

There is no equivalent to -S when using CMake and this is also not possible to implement, sorry.

petrock99 commented 3 months ago

Sure you can.

unzip TestCMakeASM.zip
cd TestCMakeASM
cmake . -DCMAKE_C_COMPILER=icx -DCMAKE_BUILD_TYPE=Release
make
less test.s

Hope that helps.

Should I file a new bug or can this one be re-opened? Thanks.

TestCMakeASM.zip

partouf commented 3 months ago

You're free to send a PR

petrock99 commented 3 months ago

Sadly, due to my job I'm not allowed to contribute to open source projects. I wish I could.

Could the 'wont-fix' flag be removed? Thanks.