[llvm] 2bc36af - [SPARC][IAS] Handle the case of non-4-byte aligned writeNopData

via llvm-commits llvm-commits at lists.llvm.org
Sun Jun 9 08:15:19 PDT 2024


Author: Koakuma
Date: 2024-06-09T22:15:15+07:00
New Revision: 2bc36afcdb282618d3dc08462375fffca32cd7ed

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

LOG: [SPARC][IAS] Handle the case of non-4-byte aligned writeNopData

If the Count passed into writeNopData is not a multiple of four,
add a little amount of zeros before writing the NOP stream.
This makes it match the behavior of GNU binutils.

Reviewers: brad0, rorth, s-barannikov, jrtc27

Reviewed By: s-barannikov

Pull Request: https://github.com/llvm/llvm-project/pull/94251

Added: 
    

Modified: 
    llvm/lib/Target/Sparc/MCTargetDesc/SparcAsmBackend.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/Sparc/MCTargetDesc/SparcAsmBackend.cpp b/llvm/lib/Target/Sparc/MCTargetDesc/SparcAsmBackend.cpp
index 240f5396855c8..cb7414fddd29f 100644
--- a/llvm/lib/Target/Sparc/MCTargetDesc/SparcAsmBackend.cpp
+++ b/llvm/lib/Target/Sparc/MCTargetDesc/SparcAsmBackend.cpp
@@ -323,9 +323,11 @@ namespace {
 
     bool writeNopData(raw_ostream &OS, uint64_t Count,
                       const MCSubtargetInfo *STI) const override {
-      // Cannot emit NOP with size not multiple of 32 bits.
-      if (Count % 4 != 0)
-        return false;
+
+      // If the count is not 4-byte aligned, we must be writing data into the
+      // text section (otherwise we have unaligned instructions, and thus have
+      // far bigger problems), so just write zeros instead.
+      OS.write_zeros(Count % 4);
 
       uint64_t NumNops = Count / 4;
       for (uint64_t i = 0; i != NumNops; ++i)


        


More information about the llvm-commits mailing list