From c9c77c6b76f7cff3bc6afbf9d3ef2200e3fdbb91 Mon Sep 17 00:00:00 2001 From: Krzysztof Parzyszek Date: Fri, 10 Jul 2020 17:36:17 -0500 Subject: [PATCH] [LLVM/CPU] Terminate basic block after "ret" instruction (#6036) * [LLVM/CPU] Terminate basic block after "ret" instruction "Ret" is a terminator in LLVM IR and there should be no instructions in the basic block following it. When generating a "ret", end the current block and start a new one. --- src/target/llvm/codegen_cpu.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/target/llvm/codegen_cpu.cc b/src/target/llvm/codegen_cpu.cc index f855dd5b83b2..41fa3c5a3fc1 100644 --- a/src/target/llvm/codegen_cpu.cc +++ b/src/target/llvm/codegen_cpu.cc @@ -781,6 +781,9 @@ llvm::Value* CodeGenCPU::CreateIntrinsic(const CallNode* op) { return CreateStaticHandle(); } else if (op->op.same_as(builtin::tvm_throw_last_error())) { builder_->CreateRet(ConstInt32(-1)); + auto next_block = std::next(builder_->GetInsertBlock()->getIterator()); + llvm::BasicBlock* new_bb = llvm::BasicBlock::Create(*ctx_, "cont", function_, &*next_block); + builder_->SetInsertPoint(new_bb); return ConstInt32(-1); } else if (op->op.same_as(builtin::tvm_struct_get())) { CHECK_EQ(op->args.size(), 3U);