https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106743
Bug ID: 106743 Summary: Illegal assembly code with -march=skylake Product: gcc Version: 12.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: stayprivate at gmail dot com Target Milestone: --- #include <stdint.h> #include <iostream> #define swapw(__val) \ ({ \ uint16_t __tmp = __val; \ __asm__("xchgb %b0, %h0" : "=q"(__tmp) : "0"(__tmp)); \ __tmp; \ }) int main() { int value = rand(); int a = swapw(value); std::cout << std::hex << "First value is " << value << " " << a << '\n'; } Compile with gcc (gcc 12 on Ubuntu ), and also with trunk. As shown on https://godbolt.org/z/oGn9WK6GE the assembler will generate the following error: : register type mismatch for `xchg' This is only when using -march=skylake or above and using -O1 or above. The code works in gcc-9/10/11.