This is an archive of the discontinued LLVM Phabricator instance.

RegisterCoalescer: Fix iterating through use operands.
ClosedPublic

Authored by hgreving on Jun 18 2021, 3:21 PM.

Details

Summary

Fixes a minor bug when trying to iterate through use operands when
updating debug use operands.

Extends a test to include above.

Diff Detail

Event Timeline

hgreving created this revision.Jun 18 2021, 3:21 PM
hgreving requested review of this revision.Jun 18 2021, 3:21 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 18 2021, 3:21 PM
klausler resigned from this revision.Jun 18 2021, 3:27 PM
arsenm added a subscriber: arsenm.Jun 18 2021, 3:39 PM
arsenm added inline comments.
llvm/lib/CodeGen/RegisterCoalescer.cpp
1560

Can you just use the explicit iterators and preincrement instead of saving all the operands?

hgreving updated this revision to Diff 353136.Jun 18 2021, 6:29 PM

Use iterator preincrement instead.

hgreving marked an inline comment as done.Jun 18 2021, 6:30 PM
arsenm accepted this revision.Jun 18 2021, 6:37 PM
This revision is now accepted and ready to land.Jun 18 2021, 6:37 PM

Just so that I understand clearly, the fault here was modifying operands while using range-iteration over the same collection? Was the symptom a crash, or missing output? (Thanks for the catch).

llvm/test/DebugInfo/MIR/X86/regcoalescer.mir
45

Should this not lead to an additional DBG_VALUE in output, and an additional CHECK line for it?

hgreving updated this revision to Diff 353259.Jun 20 2021, 6:30 PM

Second CHECK line.
clang-format.

hgreving marked an inline comment as done.Jun 20 2021, 6:33 PM

Just so that I understand clearly, the fault here was modifying operands while using range-iteration over the same collection? Was the symptom a crash, or missing output? (Thanks for the catch).

Yes, the iterator was invalidated while updating it. I am not familiar with this particular part of the register coalescer, but stumbled over it when debugging. I think it's a common mistake, thanks for reviewing.

jmorse accepted this revision.Jun 21 2021, 1:33 AM

Cheers, LGTM.

This revision was automatically updated to reflect the committed changes.