mblaze backend: unreachable executed

Hello,

I am working on a backend for a custom ISA that is somewhat similar to the MicroBlaze ISA so I've decided to use that as a starting point. I am trying to compile a custom ray tracer (lots of floating point) and the llvm-g++ frontend generates an fneg instruction which is not supported by the MBlaze backend in the 2.8 release. I added code to emit an fneg assembly instruction and now I'm getting "UNREACHABLE executed!" when trying to compile the code. The only change I made was to add the following two lines next to the square root lines in the code (FPU and sqrt are enabled in llc):

  def FSQRT : ArithF2<0x16, 0x300, "fsqrt ", IIAlu>;
  def FNEG : ArithF2<0x16, 0x300, "fneg ", IIAlu>; // added for fneg

and

  def : Pat<(fsqrt FGR32:$V), (FSQRT FGR32:$V)>;
  def : Pat<(fneg FGR32:$V), (FNEG FGR32:$V)>; // added for fneg

Does anyone know what common causes of "UNREACHABLE executed!" messages are and what this message in particular means? The full error message is the following:

UNREACHABLE executed!
0 llc 0x0000000100936ae2 PrintStackTrace(void*) + 34
1 llc 0x0000000100937603 SignalHandler(int) + 531
2 libSystem.B.dylib 0x00007fff82adf67a _sigtramp + 26
3 libSystem.B.dylib 000000000000000000 _sigtramp + 2102528416
4 llc 0x0000000100936aa6 abort + 22
5 llc 0x000000010091551d llvm::llvm_unreachable_internal(char const*, char const*, unsigned int) + 381
6 llc 0x000000010058100e llvm::CCState::AnalyzeCallResult(llvm::SmallVectorImpl<llvm::ISD::InputArg> const&, bool (*)(unsigned int, llvm::EVT, llvm::EVT, llvm::CCValAssign::LocInfo, llvm::ISD::ArgFlagsTy, llvm::CCState&)) + 158
7 llc 0x000000010007319c llvm::TraxTargetLowering::LowerCallResult(llvm::SDValue, llvm::SDValue, llvm::CallingConv::ID, bool, llvm::SmallVectorImpl<llvm::ISD::InputArg> const&, llvm::DebugLoc, llvm::SelectionDAG&, llvm::SmallVectorImpl<llvm::SDValue>&) const + 172
8 llc 0x0000000100075353 llvm::TraxTargetLowering::LowerCall(llvm::SDValue, llvm::SDValue, llvm::CallingConv::ID, bool, bool&, llvm::SmallVectorImpl<llvm::ISD::OutputArg> const&, llvm::SmallVectorImpl<llvm::SDValue> const&, llvm::SmallVectorImpl<llvm::ISD::InputArg> const&, llvm::DebugLoc, llvm::SelectionDAG&, llvm::SmallVectorImpl<llvm::SDValue>&) const + 4179
9 llc 0x00000001004c3dcd llvm::TargetLowering::LowerCallTo(llvm::SDValue, llvm::Type const*, bool, bool, bool, bool, unsigned int, llvm::CallingConv::ID, bool, bool, llvm::SDValue, std::vector<llvm::TargetLowering::ArgListEntry, std::allocator<llvm::TargetLowering::ArgListEntry> >&, llvm::SelectionDAG&, llvm::DebugLoc) const + 4269
10 llc 0x00000001004d1c0b llvm::SelectionDAGBuilder::LowerCallTo(llvm::ImmutableCallSite, llvm::SDValue, bool, llvm::MachineBasicBlock*) + 2363
11 llc 0x00000001004e6dc9 llvm::SelectionDAGBuilder::visitCall(llvm::CallInst const&) + 185
12 llc 0x00000001004c8828 llvm::SelectionDAGBuilder::visit(unsigned int, llvm::User const&) + 600
13 llc 0x00000001004fdef3 llvm::SelectionDAGBuilder::visit(llvm::Instruction const&) + 51
14 llc 0x000000010050a558 llvm::SelectionDAGISel::SelectBasicBlock(llvm::ilist_iterator<llvm::Instruction const>, llvm::ilist_iterator<llvm::Instruction const>, bool&) + 56
15 llc 0x000000010050abe2 llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) + 1506
16 llc 0x000000010050b4a8 llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) + 392
17 llc 0x00000001005d4cbd llvm::MachineFunctionPass::runOnFunction(llvm::Function&) + 125
18 llc 0x00000001008809b0 llvm::FPPassManager::runOnFunction(llvm::Function&) + 656
19 llc 0x0000000100880a6b llvm::FPPassManager::runOnModule(llvm::Module&) + 139
20 llc 0x0000000100882122 llvm::MPPassManager::runOnModule(llvm::Module&) + 562
21 llc 0x0000000100882423 llvm::PassManagerImpl::run(llvm::Module&) + 243
22 llc 0x00000001008824bd llvm::PassManager::run(llvm::Module&) + 13
23 llc 0x0000000100023c8a main + 3754
24 llc 0x0000000100022848 start + 52
Stack dump:
0. Program arguments: ./Release/bin/llc rt-rot.bc -o rt-rot.s -march=trax
1. Running pass 'Function Pass Manager' on module 'rt-rot.bc'.
2. Running pass 'Trax DAG->DAG Pattern Instruction Selection' on function '@main'

Note that Trax is the name of my custom back end and the only changes other than the ones above are changing the names to Trax from MBlaze.

Thanks for any help.

Josef Spjut

Hello

Does anyone know what common causes of "UNREACHABLE executed!" messages are and what this message in particular means? The full error message is the following:

Looks like you have not implemented the calling convention bits for
your backend.

Hello,

Thanks for the suggestion. I recompiled with Debug+Asserts and it shows that the unreachable is in CallingConvLower.cpp:162. Here is the error message:

Call result #2 has unhandled type f32UNREACHABLE executed at CallingConvLower.cpp:162!

I don’t think my backend is modified enough from the MBlaze backend that is in the release to be causing this error. I am however looking through the various files of the backend to try to find where the calling convention might be causing problems with f32 data types.

Josef

I don't think my backend is modified enough from the MBlaze backend that is
in the release to be causing this error. I am however looking through the
various files of the backend to try to find where the calling convention
might be causing problems with f32 data types.

Form the backtrace it seems like you haven't defined how to return f32
stuff out of the function.

I don't think my backend is modified enough from the MBlaze backend that is
in the release to be causing this error. I am however looking through the
various files of the backend to try to find where the calling convention
might be causing problems with f32 data types.

Form the backtrace it seems like you haven't defined how to return f32
stuff out of the function.

Could it be that the microblaze backend only has 2 return registers and we've written a function call that wants 3? If that could be the problem I'd guess it is highly likely because a lot of our code if 3 element vectors being passed around.

Josef

Could it be that the microblaze backend only has 2 return registers and we've written a function call that wants 3? If that could be the problem I'd guess it is highly likely because a lot of our code if 3 element vectors being passed around.

Maybe

Okay, I've done a lot more testing and I now have a .bc file that compiles for x86, sparc, mips but refuses to compile for the mblaze and powerPC backends because of the calling convention. Is there anyone that would know how to fix the microblaze calling convention or point me in the right direction on how to fix it?

The lines in the .bc that I believe to be causing the problem are the following:

%196 = call %0 @_Z13gatherDiffuseRK3vecS_S1_RKfS3_Pii(%struct.vec* %normal, double %tmp629, float %174, %struct.vec* %light_position, float* %nohit, float* %epsilon, i32* %66, i32 %5) nounwind

and

define linkonce_odr %0 @_Z13gatherDiffuseRK3vecS_S1_RKfS3_Pii(%struct.vec* nocapture %normal, double %hit_point.0, float %hit_point.1, %struct.vec* nocapture %light_position, float* nocapture %nohit, float* nocapture %epsilon, i32* nocapture %stack, i32 %start_bvh) nounwind inlinehint ssp {

which then goes into the body of the function.

Josef

Hi Josef,

Okay, I've done a lot more testing and I now have a .bc file that compiles for x86, sparc, mips but refuses to compile for the mblaze and powerPC backends because of the calling convention. Is there anyone that would know how to fix the microblaze calling convention or point me in the right direction on how to fix it?

what does "refuses to compile" mean? I.e. what error do you get?

Ciao, Duncan.

what does "refuses to compile" mean? I.e. what error do you get?

Specifically I get this message when compiling with the default -mattr:

Call result #2 has unhandled type i32
UNREACHABLE executed at CallingConvLower.cpp:162!
0 llc 0x0000000100a1e115 PrintStackTrace(void*) + 38
1 llc 0x0000000100a1e6d0 SignalHandler(int) + 254
2 libSystem.B.dylib 0x00007fff82adf67a _sigtramp + 26
3 llc 0x000000010053233c llvm::SmallVectorImpl<unsigned int>::push_back(unsigned int const&) + 104
4 llc 0x000000010002d3d3 raise + 27
5 llc 0x000000010002d3e3 abort + 14
6 llc 0x0000000100a0a9e3 llvm::report_fatal_error(llvm::Twine const&) + 0
7 llc 0x00000001005df5f3 llvm::CCState::AnalyzeCallResult(llvm::SmallVectorImpl<llvm::ISD::InputArg> const&, bool (*)(unsigned int, llvm::MVT, llvm::MVT, llvm::CCValAssign::LocInfo, llvm::ISD::ArgFlagsTy, llvm::CCState&)) + 261
8 llc 0x00000001000b62ac llvm::MBlazeTargetLowering::LowerCallResult(llvm::SDValue, llvm::SDValue, llvm::CallingConv::ID, bool, llvm::SmallVectorImpl<llvm::ISD::InputArg> const&, llvm::DebugLoc, llvm::SelectionDAG&, llvm::SmallVectorImpl<llvm::SDValue>&) const + 166
9 llc 0x00000001000b72c6 llvm::MBlazeTargetLowering::LowerCall(llvm::SDValue, llvm::SDValue, llvm::CallingConv::ID, bool, bool&, llvm::SmallVectorImpl<llvm::ISD::OutputArg> const&, llvm::SmallVectorImpl<llvm::SDValue> const&, llvm::SmallVectorImpl<llvm::ISD::InputArg> const&, llvm::DebugLoc, llvm::SelectionDAG&, llvm::SmallVectorImpl<llvm::SDValue>&) const + 3640
10 llc 0x00000001004fffe8 llvm::TargetLowering::LowerCallTo(llvm::SDValue, llvm::Type const*, bool, bool, bool, bool, unsigned int, llvm::CallingConv::ID, bool, bool, llvm::SDValue, std::vector<llvm::TargetLowering::ArgListEntry, std::allocator<llvm::TargetLowering::ArgListEntry> >&, llvm::SelectionDAG&, llvm::DebugLoc) const + 2058
11 llc 0x000000010050733a llvm::SelectionDAGBuilder::LowerCallTo(llvm::ImmutableCallSite, llvm::SDValue, bool, llvm::MachineBasicBlock*) + 2470
12 llc 0x0000000100519d01 llvm::SelectionDAGBuilder::visitCall(llvm::CallInst const&) + 4381
13 llc 0x0000000100522bc4 llvm::SelectionDAGBuilder::visit(unsigned int, llvm::User const&) + 1220
14 llc 0x00000001005286c9 llvm::SelectionDAGBuilder::visit(llvm::Instruction const&) + 105
15 llc 0x000000010054067f llvm::SelectionDAGISel::SelectBasicBlock(llvm::ilist_iterator<llvm::Instruction const>, llvm::ilist_iterator<llvm::Instruction const>, bool&) + 59
16 llc 0x0000000100541088 llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) + 2396
17 llc 0x0000000100541730 llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) + 762
18 llc 0x000000010064e051 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) + 85
19 llc 0x000000010095f6ea llvm::FPPassManager::runOnFunction(llvm::Function&) + 350
20 llc 0x000000010095f8bd llvm::FPPassManager::runOnModule(llvm::Module&) + 81
21 llc 0x000000010095f3ba llvm::MPPassManager::runOnModule(llvm::Module&) + 384
22 llc 0x0000000100960b6b llvm::PassManagerImpl::run(llvm::Module&) + 111
23 llc 0x0000000100960bcd llvm::PassManager::run(llvm::Module&) + 33
24 llc 0x000000010003073f main + 2305
25 llc 0x000000010002f824 start + 52

and Illegal Instruction returned to my shell.

When I enable FPU the type changes to f32 but the rest of the error is the same.

Josef

what does "refuses to compile" mean? I.e. what error do you get?

Specifically I get this message when compiling with the default -mattr:

Call result #2 has unhandled type i32
UNREACHABLE executed at CallingConvLower.cpp:162!
0 llc 0x0000000100a1e115 PrintStackTrace(void*) + 38
1 llc 0x0000000100a1e6d0 SignalHandler(int) + 254
2 libSystem.B.dylib 0x00007fff82adf67a _sigtramp + 26
3 llc 0x000000010053233c llvm::SmallVectorImpl<unsigned int>::push_back(unsigned int const&) + 104
4 llc 0x000000010002d3d3 raise + 27
5 llc 0x000000010002d3e3 abort + 14
6 llc 0x0000000100a0a9e3 llvm::report_fatal_error(llvm::Twine const&) + 0
7 llc 0x00000001005df5f3 llvm::CCState::AnalyzeCallResult(llvm::SmallVectorImpl<llvm::ISD::InputArg> const&, bool (*)(unsigned int, llvm::MVT, llvm::MVT, llvm::CCValAssign::LocInfo, llvm::ISD::ArgFlagsTy, llvm::CCState&)) + 261
8 llc 0x00000001000b62ac llvm::MBlazeTargetLowering::LowerCallResult(llvm::SDValue, llvm::SDValue, llvm::CallingConv::ID, bool, llvm::SmallVectorImpl<llvm::ISD::InputArg> const&, llvm::DebugLoc, llvm::SelectionDAG&, llvm::SmallVectorImpl<llvm::SDValue>&) const + 166
9 llc 0x00000001000b72c6 llvm::MBlazeTargetLowering::LowerCall(llvm::SDValue, llvm::SDValue, llvm::CallingConv::ID, bool, bool&, llvm::SmallVectorImpl<llvm::ISD::OutputArg> const&, llvm::SmallVectorImpl<llvm::SDValue> const&, llvm::SmallVectorImpl<llvm::ISD::InputArg> const&, llvm::DebugLoc, llvm::SelectionDAG&, llvm::SmallVectorImpl<llvm::SDValue>&) const + 3640
10 llc 0x00000001004fffe8 llvm::TargetLowering::LowerCallTo(llvm::SDValue, llvm::Type const*, bool, bool, bool, bool, unsigned int, llvm::CallingConv::ID, bool, bool, llvm::SDValue, std::vector<llvm::TargetLowering::ArgListEntry, std::allocator<llvm::TargetLowering::ArgListEntry> >&, llvm::SelectionDAG&, llvm::DebugLoc) const + 2058
11 llc 0x000000010050733a llvm::SelectionDAGBuilder::LowerCallTo(llvm::ImmutableCallSite, llvm::SDValue, bool, llvm::MachineBasicBlock*) + 2470
12 llc 0x0000000100519d01 llvm::SelectionDAGBuilder::visitCall(llvm::CallInst const&) + 4381
13 llc 0x0000000100522bc4 llvm::SelectionDAGBuilder::visit(unsigned int, llvm::User const&) + 1220
14 llc 0x00000001005286c9 llvm::SelectionDAGBuilder::visit(llvm::Instruction const&) + 105
15 llc 0x000000010054067f llvm::SelectionDAGISel::SelectBasicBlock(llvm::ilist_iterator<llvm::Instruction const>, llvm::ilist_iterator<llvm::Instruction const>, bool&) + 59
16 llc 0x0000000100541088 llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) + 2396
17 llc 0x0000000100541730 llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) + 762
18 llc 0x000000010064e051 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) + 85
19 llc 0x000000010095f6ea llvm::FPPassManager::runOnFunction(llvm::Function&) + 350
20 llc 0x000000010095f8bd llvm::FPPassManager::runOnModule(llvm::Module&) + 81
21 llc 0x000000010095f3ba llvm::MPPassManager::runOnModule(llvm::Module&) + 384
22 llc 0x0000000100960b6b llvm::PassManagerImpl::run(llvm::Module&) + 111
23 llc 0x0000000100960bcd llvm::PassManager::run(llvm::Module&) + 33
24 llc 0x000000010003073f main + 2305
25 llc 0x000000010002f824 start + 52

and Illegal Instruction returned to my shell.

When I enable FPU the type changes to f32 but the rest of the error is the same.

Josef