Node emitted out of order - late

Hi All,

I am porting an embedded 32bit RISC processor to LLVM-8.
I was able to compile few basic applications successfully but for a
particular application I am seeing below error:

llvm-project/llvm/lib/CodeGen/SelectionDAG/InstrEmitter.cpp:317:
unsigned int llvm::InstrEmitter::getVR(llvm::SDValue,
llvm::DenseMap<llvm::SDValue, unsigned int>&): Assertion `I !=
VRBaseMap.end() && "Node emitted out of order - late"' failed

I tried debugging it and found that CopyToReg is trying to use virtual
register and somehow matching with "VRBaseMap.end()" as a result it is
crashing.

Can someone please help me out from this?
I am really struck on this.

Thanks in advance
Nagaraju

Here is the simple testcase which is reproducing the error

#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
#include <ctype.h>

#include "aes.h"

int encfile(FILE *fin, FILE *fout, aes *ctx, char* fn)
{ char inbuf[16], outbuf[16];
    unsigned long flen;
    unsigned long i=0, l=0;

    fillrand(outbuf, 16);
    fseek(fin, 0, SEEK_END);
    fgetpos(fin, &flen);
    fseek(fin, 0, SEEK_SET);
    fwrite(outbuf, 1, 16, fout);
    return 0;
}

t9: i32 = FrameIndex<0>
clang-8: llvm/lib/CodeGen/SelectionDAG/InstrEmitter.cpp:317: unsigned
int llvm::InstrEmitter::getVR(llvm::SDValue,
llvm::DenseMap<llvm::SDValue, unsigned int>&): Assertion `I !=
VRBaseMap.end() && "Node emitted out of order - late"' failed.

Thanks,
Nagaraju