This is an archive of the discontinued LLVM Phabricator instance.

[CodeEmitter] Fix encoding wide instructions on big-endian hosts
ClosedPublic

Authored by foad on Jun 7 2022, 3:26 AM.

Details

Summary

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 until it was reverted.

Diff Detail

Event Timeline

foad created this revision.Jun 7 2022, 3:26 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 7 2022, 3:26 AM
Herald added subscribers: kosarev, tpr. · View Herald Transcript
foad requested review of this revision.Jun 7 2022, 3:26 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 7 2022, 3:26 AM
foad added inline comments.
llvm/utils/TableGen/CodeEmitterGen.cpp
488–490

This could conceivably slow things down by constructing a new APInt instead of modifying the existing one in-place, but I think it's more important to make sure it works correctly before addressing that.

foad added a reviewer: Restricted Project.Jun 7 2022, 8:26 AM

This looks reasonable to me, but I think we need someone else to confirm too.

myhsu accepted this revision.Jun 7 2022, 10:32 AM

This is an interesting bug!
I was actually scratching my head wondering why m68k hasn't encountered this issue, before realizing that this problem only happens in fixed length CodeEmitter.

It seems like this patch can be tested by existing test cases, but just curious, do we have any big-endian builtbot for AMDGPU?

llvm/utils/TableGen/CodeEmitterGen.cpp
488–490

I'm fine with the current syntax too, if performance is really a problem, we can always write a simple loop to copy data into the pointer returned by APInt::getRawData, though getRawData returned a constant pointer right now.

This revision is now accepted and ready to land.Jun 7 2022, 10:32 AM
foad added a comment.Jun 7 2022, 11:08 AM

It seems like this patch can be tested by existing test cases, but just curious, do we have any big-endian builtbot for AMDGPU?

Not for AMDGPU specifically, but there are big-endian buildbots that test all targets. These were the ones that started failing when D126483 was pushed.

This revision was landed with ongoing or failed builds.Jun 7 2022, 11:09 AM
This revision was automatically updated to reflect the committed changes.