<div dir="ltr"><div class="gmail_extra">There are 11 BuildMI() functions in MachineInstrBuilder.h including four using the iterator and one using an instruction. But I just don't think that's it. The creation of the new instruction works fine (works fine with OldMI as well) and the new instruction is present in the assembly output.</div><div class="gmail_extra"><br></div><div class="gmail_extra">The problem is removing the old instruction correctly.<br>
</div><div class="gmail_extra"><br></div><div class="gmail_extra"><span style="font-size:12.8000001907349px">> The loop header needs to be modified, because MBBI will be invalidated when you remove the instruction:</span><br style="font-size:12.8000001907349px"></div><div class="gmail_extra"><br></div><div class="gmail_extra">So if I remove the old instruction with something like:</div><div class="gmail_extra"><br></div><div class="gmail_extra">  MBB->remove_instr(OldMI);<br></div><div class="gmail_extra"><br></div><div class="gmail_extra">I could just start the loop over or is there a more better way to invalidate the MBBI iterator?</div><div class="gmail_extra">Basic blocks aren't that long (on average 4-6 instructions) and this peephole isn't that common either.</div><div class="gmail_extra"><br></div></div>