[PATCH] D127195: [CodeEmitter] Fix encoding wide instructions on big-endian hosts

Jay Foad via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 7 03:26:03 PDT 2022


foad created this revision.
Herald added subscribers: kosarev, tpr.
Herald added a project: All.
foad requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

For instructions wider than 64 bits the InstBits table is initialized in
64-bit chunks from APInt::getRawData, but it was being read with
LoadIntFromMemory which is byte-based.

Fix this by reading the table with the APInt constructor that takes an
ArrayRef to the raw data instead.

This is currently NFC for in-tree targets but fixes AMDGPU failures on
big-endian hosts that were caused by D126483 <https://reviews.llvm.org/D126483> until it was reverted.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D127195

Files:
  llvm/utils/TableGen/CodeEmitterGen.cpp


Index: llvm/utils/TableGen/CodeEmitterGen.cpp
===================================================================
--- llvm/utils/TableGen/CodeEmitterGen.cpp
+++ llvm/utils/TableGen/CodeEmitterGen.cpp
@@ -482,14 +482,12 @@
     // Emit initial function code
     if (UseAPInt) {
       int NumWords = APInt::getNumWords(BitWidth);
-      int NumBytes = (BitWidth + 7) / 8;
       o << "  const unsigned opcode = MI.getOpcode();\n"
-        << "  if (Inst.getBitWidth() != " << BitWidth << ")\n"
-        << "    Inst = Inst.zext(" << BitWidth << ");\n"
         << "  if (Scratch.getBitWidth() != " << BitWidth << ")\n"
         << "    Scratch = Scratch.zext(" << BitWidth << ");\n"
-        << "  LoadIntFromMemory(Inst, (const uint8_t *)&InstBits[opcode * "
-        << NumWords << "], " << NumBytes << ");\n"
+        << "  Inst = APInt(" << BitWidth
+        << ", makeArrayRef(InstBits + opcode * " << NumWords << ", " << NumWords
+        << "));\n"
         << "  APInt &Value = Inst;\n"
         << "  APInt &op = Scratch;\n"
         << "  switch (opcode) {\n";


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D127195.434757.patch
Type: text/x-patch
Size: 1071 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220607/4cd59b77/attachment.bin>


More information about the llvm-commits mailing list