PEI::replaceFrameIndices() endless loop


My backend (based on version 3.8) was hanging in an infinite loop in the Prolog/Epilog Inserter.

After investigation, it appears that it was looping in the first level loop of the PEI::replaceFrameIndices() method: processing the second instruction of the block again and again…

This loop never exits because the iterator is ‘skipped backward’ under some condition in the middle of the loop (see yellow highlighted line).

I understand the rationale explained in the first comment, but I don’t understand how the condition (“not the first instruction”) is related to this rationale.

I have commented out the iterator decrement and then my back-end behave correctly.

The handling of this loop iterator is quite complex: skipping backward or forward in not so clearly raised conditions.

Could someone review the logic of this iterator to confirm its correctness? Or is it a bug?

// Some instructions (e.g. inline asm instructions) can have

// multiple frame indices and/or cause eliminateFrameIndex

// to insert more than one instruction. We need the register

// scavenger to go through all of these instructions so that

// it can update its register information. We keep the

// iterator at the point before insertion so that we can

// revisit them in full.

bool AtBeginning = (I == BB->begin());

if (!AtBeginning) --I;

// If this instruction has a FrameIndex operand, we need to

// use that target machine register info object to eliminate

// it.

TRI.eliminateFrameIndex(MI, SPAdj, i,

FrameIndexVirtualScavenging ? nullptr : RS);

Regards, Dominique Torette.