Hi Quentin,
This patch fixes rematerialization in InlineSpiller so it can handle bundles of MIs properly.
Context:
Before InlineSpiller rematerializes a vreg, it iterates over operands of each MI in a bundle, collecting all (MI, OpNo) pairs that reference that vreg.
Then if it does rematerialize, it goes through the pair list and replaces the operands with the new (rematerialized) vreg. The problem is, it tries to replace all of these operands in the main MI ! This works fine for single MIs. However, if we are processing a bundle of MIs and the list contains multiple pairs - the rematerialization will either crash trying to access a non-existing operand of the main MI, or silently corrupt one of the existing ones. It will also ignore other MIs in the bundle.
The obvious fix is to use the MI pointers saved in collected (MI, OpNo) pairs. This must have been the original intent of the pair list but somehow these pointers got lost.
Please review.
Thanks,
Dmitri
MI is not reused anywhere so just fold the expression here:
MachineOperand &MO = Ops[i].first->getOperand(Ops[i].second);
That way we won’t have the shadow variable.