[llvm] [X86] Fix incorrect NOP insertion between fused instructions that breaks macro fusion (PR #155316)

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 26 21:49:04 PDT 2025


================
@@ -520,7 +520,19 @@ void X86AsmBackend::emitInstructionBegin(MCObjectStreamer &OS,
   if (!canPadInst(Inst, OS))
     return;
 
-  if (PendingBA && PendingBA->getNext() == OS.getCurrentFragment()) {
+  if (PendingBA) {
+    auto *NextFragment = PendingBA->getNext();
+    assert(NextFragment && "NextFragment should not be null");
+
+    if (NextFragment == OS.getCurrentFragment())
+      return;
+
+    // We eagerly create an empty fragment when inserting a fragment
+    // with a variable-size tail.
+    if (NextFragment->getKind() == MCFragment::FT_Relaxable &&
----------------
MaskRay wrote:

Fragment types other than Relaxable (FT_Align)  might have a variable-size tail as well. 
Is the condition `NextFragment->getKind() == MCFragment::FT_Relaxable` required?

https://github.com/llvm/llvm-project/pull/155316


More information about the llvm-commits mailing list