Macro-op fusion experiment

Hi all,

x86 processors use macro-op fusion to merge together two instructions and execute them as one. So it’s beneficial for the compiler to emit them as a pair.

Currently only compare and jump instructions get fused though. And I was wondering whether it also makes sense to fuse move and arithmetic instructions together, to form non-destructive instructions (which x86 lacks for regular instructions). For instance:

8B C3 mov eax, ebx

03 C1 add eax, ecx


8B C3 03 C1 add eax, ebx, ecx

There’s no difference in the binary encoding; it’s just considered one instruction at a logical level and inside the hardware (I’m assuming x86’s RISC internals actually use non-destructive micro-operations).

So my question is, how do I define these fused instructions in LLVM? And how would I be able to estimate the potential speedup?