This is an archive of the discontinued LLVM Phabricator instance.

[DebugInfo] Fix crash when updating DBG_VALUE users of an SSA value modified by tail duplication
ClosedPublic

Authored by StephenTozer on Jul 22 2021, 8:19 AM.

Details

Summary

Fixes bug 50441: https://bugs.llvm.org/show_bug.cgi?id=50441

Currently, during the "Update SSA" step of tail duplication, any DBG_VALUE* users of any updated SSA values will be deleted. Currently this is done by iterating the use list of the vreg being updated and erasing instructions as they are seen. This worked previously but may fail if a DBG_VALUE_LIST instruction uses the vreg multiple times, because after erasing the instruction for the first use we will encounter the second use and attempt to erase the same instruction again, causing an error. This is fixed simply by collecting the instructions to be removed into a set, and erasing after completing iteration.

As an open question to anyone vaguely familiar with this code, is there a reason that the debug values are being deleted instead of set as undef in this block? The patch that added this behaviour, e0304d1df, seems to have done so intentionally (the commit says "Avoid creating debug uses of undef, as they become a kill."), but this looks like it will produce incorrect debug information to me - if a debug value is deleted, it may incorrectly lengthen the range of the previous debug value for that variable. Furthermore, it should be a trivial matter to update the debug values - a direct update for the previously used SSA value is available, and I don't know if there's a good reason for not doing so.

I will likely open another review making this change, but it doesn't need to be tied to this fix, and it would also be useful if anyone with more domain knowledge has a good reason for the current behaviour.

Diff Detail

Event Timeline

StephenTozer created this revision.Jul 22 2021, 8:19 AM
StephenTozer requested review of this revision.Jul 22 2021, 8:19 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 22 2021, 8:19 AM
jmorse accepted this revision.Jul 23 2021, 5:44 AM
jmorse added a subscriber: jmorse.

LGTM with some nits.

llvm/lib/CodeGen/TailDuplicator.cpp
238

I'd prefer the auto *MI form just for precision.

llvm/test/CodeGen/X86/tail-dup-debugvalue.mir
4–5

IMO: this should explicitly state that multiple identical operands is what's being tested, lest someone revises it in the future and doesn't know the objective.

87

Most if not all the frameInfo can be deleted, and all the "false" attributes above. Note also the --simplify-mir option to llc.

This revision is now accepted and ready to land.Jul 23 2021, 5:44 AM
StephenTozer added inline comments.Jul 23 2021, 6:27 AM
llvm/test/CodeGen/X86/tail-dup-debugvalue.mir
4–5

In this case it's not actually just testing that - it does explicitly test multiple operands, but it also looks as though the old behaviour wasn't well tested for, so this test covers both.

Address review comments.

This revision was landed with ongoing or failed builds.Jul 26 2021, 9:28 AM
This revision was automatically updated to reflect the committed changes.