diff --git a/llvm/lib/Target/TVM/TVMStack.cpp b/llvm/lib/Target/TVM/TVMStack.cpp index 50197dc6d0b2..ffe2af9bff36 100644 --- a/llvm/lib/Target/TVM/TVMStack.cpp +++ b/llvm/lib/Target/TVM/TVMStack.cpp @@ -284,7 +284,8 @@ void Stack::dump() const { #endif void Stack::printElement(raw_ostream &OS, const StackVreg &Vreg) const { - if (Vreg.VirtReg == TVMFunctionInfo::UnusedReg) { + if (Vreg.VirtReg == TVMFunctionInfo::UnusedReg || + Vreg.VirtReg >= TRI->getNumRegs()) { OS << "x"; return; } diff --git a/llvm/lib/Target/TVM/TVMStackFixup.cpp b/llvm/lib/Target/TVM/TVMStackFixup.cpp index 4a71f9a4b57b..6ac908780fa0 100644 --- a/llvm/lib/Target/TVM/TVMStackFixup.cpp +++ b/llvm/lib/Target/TVM/TVMStackFixup.cpp @@ -95,7 +95,8 @@ StackFixup StackFixup::Diff(const Stack &to, const Stack &from) { // Generate changes to re-order assert(llvm::size(unmaskedTo) == llvm::size(curStack)); - generateVagonXchgs(rv, curStack, unmaskedTo); + if (llvm::size(curStack) > 0) + generateVagonXchgs(rv, curStack, unmaskedTo); rv.optimize(); return rv; } @@ -225,6 +226,7 @@ void StackFixup::generateVagonXchgs(StackFixup &rv, const Stack &from, auto Tr = Train::build(curStack, to); auto restVagons = llvm::make_range(Tr.Vagons.begin(), Tr.Vagons.end()); + assert(restVagons.begin() != restVagons.end()); auto V = *restVagons.begin(); if (V.DeepIdx + 1 == Sz && !V.Inverted) { restVagons = drop_begin(restVagons, 1);