[PATCH] D139285: [LoongArch] Allow writing unaligned nop sequences
wanglei via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 8 02:44:52 PST 2022
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG1d3baf21b673: [LoongArch] Allow writing unaligned nop sequences (authored by wangleiat).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D139285/new/
https://reviews.llvm.org/D139285
Files:
llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp
llvm/test/MC/LoongArch/Misc/unaligned-nops.s
Index: llvm/test/MC/LoongArch/Misc/unaligned-nops.s
===================================================================
--- llvm/test/MC/LoongArch/Misc/unaligned-nops.s
+++ llvm/test/MC/LoongArch/Misc/unaligned-nops.s
@@ -1,5 +1,8 @@
-# RUN: not --crash llvm-mc --filetype=obj --triple=loongarch64 %s -o %t
+# RUN: llvm-mc --triple=loongarch64 --filetype=obj %s -o %t
+# RUN: llvm-objdump -d %t | FileCheck %s
+
+# CHECK: 01 00 00 00 <unknown>
+# CHECK-NEXT: 00 00 40 03 nop
.byte 1
-# CHECK: LLVM ERROR: unable to write nop sequence of 3 bytes
-.p2align 2
+.p2align 3
foo:
Index: llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp
===================================================================
--- llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp
+++ llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp
@@ -179,13 +179,14 @@
bool LoongArchAsmBackend::writeNopData(raw_ostream &OS, uint64_t Count,
const MCSubtargetInfo *STI) const {
- // Check for byte count not multiple of instruction word size
- if (Count % 4 != 0)
- return false;
+ // We mostly follow binutils' convention here: align to 4-byte boundary with a
+ // 0-fill padding.
+ OS.write_zeros(Count % 4);
- // The nop on LoongArch is andi r0, r0, 0.
+ // The remainder is now padded with 4-byte nops.
+ // nop: andi r0, r0, 0
for (; Count >= 4; Count -= 4)
- support::endian::write<uint32_t>(OS, 0x03400000, support::little);
+ OS.write("\0\0\x40\x03", 4);
return true;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D139285.481218.patch
Type: text/x-patch
Size: 1558 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221208/08e6d400/attachment.bin>
More information about the llvm-commits
mailing list