Wrong encoding/decoding for POPC instruction of Sparc

Hello,

There is an issue in the latest Sparc code: while we can encode POPC, decode results in crash in llvm-mc

$ echo “popc %g1, %g2” | ./Release+Asserts/bin/llvm-mc -assemble -triple=sparcv9 -show-encoding
.text
popc %g1, %g2 ! encoding: [0x85,0x70,0x00,0x01]

$ echo “0x85,0x70,0x00,0x01”|./Release+Asserts/bin/llvm-mc -disassemble -triple=sparcv9
.text
popc Assertion failed: (idx < size()), function operator, file /Users/jun/projects/llvm/sparc-2.git/include/llvm/ADT/SmallVector.h, line 143.
0 llvm-mc 0x00000001096a5099 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 57
1 llvm-mc 0x00000001096a45c6 llvm::sys::RunSignalHandlers() + 102
2 llvm-mc 0x00000001096a5b95 SignalHandler(int) + 693
3 libsystem_platform.dylib 0x00007fff86d78f1a _sigtramp + 26
4 libsystem_platform.dylib 0x0000000000000002 _sigtramp + 2032693506
5 llvm-mc 0x00000001096a5836 abort + 22
6 llvm-mc 0x00000001096a5811 __assert_rtn + 81
7 llvm-mc 0x000000010963f4e8 llvm::SparcInstPrinter::printOperand(llvm::MCInst const*, int, llvm::MCSubtargetInfo const&, llvm::raw_ostream&) + 136
8 llvm-mc 0x000000010963eae0 llvm::SparcInstPrinter::printInstruction(llvm::MCInst const*, llvm::MCSubtargetInfo const&, llvm::raw_ostream&) + 256
9 llvm-mc 0x000000010964f5e6 llvm::SparcInstPrinter::printInst(llvm::MCInst const*, llvm::raw_ostream&, llvm::StringRef, llvm::MCSubtargetInfo const&) + 86
10 llvm-mc 0x000000010965f90f (anonymous namespace)::MCAsmStreamer::EmitInstruction(llvm::MCInst const&, llvm::MCSubtargetInfo const&) + 2879
11 llvm-mc 0x00000001096043b3 llvm::Disassembler::disassemble(llvm::Target const&, std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator > const&, llvm::MCSubtargetInfo&, llvm::MCStreamer&, llvm::MemoryBuffer&, llvm::SourceMgr&, llvm::raw_ostream&) + 2147
12 llvm-mc 0x0000000109607460 main + 9760
13 libdyld.dylib 0x00007fff8f34d5c9 start + 1
14 libdyld.dylib 0x0000000000000003 start + 1892362811
Stack dump:
0. Program arguments: ./Release+Asserts/bin/llvm-mc -disassemble -triple=sparcv9
Illegal instruction: 4

Any ideas on what is wrong, and how to fix this?

Thank you.

Any ideas on this bug?

Thanks.

I’ll look into it, thanks for the report.

Hi James,

Not sure if you’ve already found the problem but I’ve been looking at this issue a bit as a way to learn. What I’ve seen is that the wrong operand names are used for the instruction which causes the decoder emitter to fail to recognize the operands.

The attached patch changes the names of the operands and adds a test for the disassembly of the instruction. I haven’t checked if there are more instructions which lack test cases. I have no commit access, if you think the patch is correct I would appreciate your help in committing it.

Regards

David

SparcPopcDecoding.patch (1.01 KB)

James, is the fix of David accepted?

Thanks.

Hi,

James made some improvements and committed it in r244064.

Best regards
David

Excellent, thanks!!