[llvm-branch-commits] [llvm] affc059 - [Hexagon] Fix encoding of packets with fixups followed by alignment (#179168)

Cullen Rhodes via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Wed Feb 18 00:18:14 PST 2026


Author: Brian Cain
Date: 2026-02-18T08:18:05Z
New Revision: affc05915877ec376f003e126c86299fa2e9c32c

URL: https://github.com/llvm/llvm-project/commit/affc05915877ec376f003e126c86299fa2e9c32c
DIFF: https://github.com/llvm/llvm-project/commit/affc05915877ec376f003e126c86299fa2e9c32c.diff

LOG: [Hexagon] Fix encoding of packets with fixups followed by alignment (#179168)

When a packet containing extended immediates and new-value compare-jump
instructions with fixups was followed by a .p2align directive, we would
incorrectly add nops to the packet. After reshuffling, the fixup offsets
would become invalid, causing corrupted encodings.

Fixes round-trip assembly for patterns like:

    {
      r18 = ##65536
      if (!cmp.gtu(r1,r18.new)) jump:t .L1
    }
    .p2align 4

(cherry picked from commit 87d73f74713039cacf9d174a9d74de0db8eccb8b)

Added: 
    llvm/test/MC/Hexagon/newvalue_jump_ext_imm.s

Modified: 
    llvm/lib/Target/Hexagon/MCTargetDesc/HexagonAsmBackend.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonAsmBackend.cpp b/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonAsmBackend.cpp
index 5a187d22d2baa..ad00b9438c8a1 100644
--- a/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonAsmBackend.cpp
+++ b/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonAsmBackend.cpp
@@ -596,6 +596,13 @@ class HexagonAsmBackend : public MCAsmBackend {
               auto &RF = *Frags[K];
               MCInst Inst = RF.getInst();
 
+              // Don't add nops to packets that have fixups, as reshuffling can
+              // invalidate fixup offsets.
+              if (!RF.getVarFixups().empty()) {
+                Size = 0;
+                break;
+              }
+
               const bool WouldTraverseLabel = llvm::any_of(
                   Asm->symbols(), [&RF, &Inst, Asm = Asm](MCSymbol const &sym) {
                     uint64_t Offset = 0;

diff  --git a/llvm/test/MC/Hexagon/newvalue_jump_ext_imm.s b/llvm/test/MC/Hexagon/newvalue_jump_ext_imm.s
new file mode 100644
index 0000000000000..b0faf64f4cf42
--- /dev/null
+++ b/llvm/test/MC/Hexagon/newvalue_jump_ext_imm.s
@@ -0,0 +1,49 @@
+# RUN: llvm-mc -triple=hexagon -filetype=obj %s | llvm-objdump -d - | FileCheck %s
+# Test that packets with extended immediates and new-value compare-jumps
+# followed by alignment directives are encoded and decoded correctly.
+
+# CHECK-LABEL: <test1>:
+# CHECK: immext(#0x10000)
+# CHECK-NEXT: r18 = ##0x10000
+# CHECK-NEXT: if (!cmp.gtu(r1,r18.new)) jump:t
+test1:
+  .p2align 4
+  {
+    r18 = ##65536
+    if (!cmp.gtu(r1,r18.new)) jump:t .L1
+  }
+  .p2align 4
+.L1:
+  nop
+
+# CHECK-LABEL: <test2>:
+# CHECK: immext(#0x20000)
+# CHECK-NEXT: r19 = ##0x20000
+# CHECK-NEXT: if (cmp.eq(r19.new,r2)) jump:nt
+test2:
+  .p2align 4
+  {
+    r19 = ##131072
+    if (cmp.eq(r19.new,r2)) jump:nt .L2
+  }
+  .p2align 4
+.L2:
+  nop
+
+# CHECK-LABEL: <test3>:
+# CHECK: allocframe(#0x10)
+# CHECK-NEXT: memd(r29+#0x0) = r19:18
+# CHECK: immext(#0x10000)
+# CHECK-NEXT: r18 = ##0x10000
+# CHECK-NEXT: if (!cmp.gtu(r1,r18.new)) jump:t
+test3:
+  .p2align 4
+  allocframe(#16)
+  memd(r29+#0) = r19:18
+  {
+    r18 = ##65536
+    if (!cmp.gtu(r1,r18.new)) jump:t .L3
+  }
+  .p2align 4
+.L3:
+  nop


        


More information about the llvm-branch-commits mailing list