Skip to content

Commit 87d73f7

Browse files
authored
[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
1 parent 754fc78 commit 87d73f7

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,13 @@ class HexagonAsmBackend : public MCAsmBackend {
596596
auto &RF = *Frags[K];
597597
MCInst Inst = RF.getInst();
598598

599+
// Don't add nops to packets that have fixups, as reshuffling can
600+
// invalidate fixup offsets.
601+
if (!RF.getVarFixups().empty()) {
602+
Size = 0;
603+
break;
604+
}
605+
599606
const bool WouldTraverseLabel = llvm::any_of(
600607
Asm->symbols(), [&RF, &Inst, Asm = Asm](MCSymbol const &sym) {
601608
uint64_t Offset = 0;
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# RUN: llvm-mc -triple=hexagon -filetype=obj %s | llvm-objdump -d - | FileCheck %s
2+
# Test that packets with extended immediates and new-value compare-jumps
3+
# followed by alignment directives are encoded and decoded correctly.
4+
5+
# CHECK-LABEL: <test1>:
6+
# CHECK: immext(#0x10000)
7+
# CHECK-NEXT: r18 = ##0x10000
8+
# CHECK-NEXT: if (!cmp.gtu(r1,r18.new)) jump:t
9+
test1:
10+
.p2align 4
11+
{
12+
r18 = ##65536
13+
if (!cmp.gtu(r1,r18.new)) jump:t .L1
14+
}
15+
.p2align 4
16+
.L1:
17+
nop
18+
19+
# CHECK-LABEL: <test2>:
20+
# CHECK: immext(#0x20000)
21+
# CHECK-NEXT: r19 = ##0x20000
22+
# CHECK-NEXT: if (cmp.eq(r19.new,r2)) jump:nt
23+
test2:
24+
.p2align 4
25+
{
26+
r19 = ##131072
27+
if (cmp.eq(r19.new,r2)) jump:nt .L2
28+
}
29+
.p2align 4
30+
.L2:
31+
nop
32+
33+
# CHECK-LABEL: <test3>:
34+
# CHECK: allocframe(#0x10)
35+
# CHECK-NEXT: memd(r29+#0x0) = r19:18
36+
# CHECK: immext(#0x10000)
37+
# CHECK-NEXT: r18 = ##0x10000
38+
# CHECK-NEXT: if (!cmp.gtu(r1,r18.new)) jump:t
39+
test3:
40+
.p2align 4
41+
allocframe(#16)
42+
memd(r29+#0) = r19:18
43+
{
44+
r18 = ##65536
45+
if (!cmp.gtu(r1,r18.new)) jump:t .L3
46+
}
47+
.p2align 4
48+
.L3:
49+
nop

0 commit comments

Comments
 (0)