Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
[Hexagon] Fix encoding of packets with fixups followed by alignment
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
  • Loading branch information
androm3da committed Feb 2, 2026
commit 6552458c13c3955c2bb6bc9adb7dc8c420633a25
7 changes: 7 additions & 0 deletions llvm/lib/Target/Hexagon/MCTargetDesc/HexagonAsmBackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
49 changes: 49 additions & 0 deletions llvm/test/MC/Hexagon/newvalue_jump_ext_imm.s
Original file line number Diff line number Diff line change
@@ -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