This is an archive of the discontinued LLVM Phabricator instance.

[DebugInfo] Attempt to preserve more information during tail duplication
ClosedPublic

Authored by StephenTozer on Jul 27 2021, 7:24 AM.

Details

Summary

As part of putting together the fix in D106557, I noticed that tail duplication looked to be handling debug info poorly - specifically, debug instructions would be dropped instead of being set undef, potentially extending the lifetimes of prior debug values that should be killed. Furthermore, the deleted debug instructions were not necessarily dead - it looks as though the deletion was added to prevent codegen from being affected by debug instructions, resulting in an overly aggressive dropping of debug info. This patch modifies this step to instead make the best attempt to recover debug info without making any codegen changes.

A function has been added to MachineSSAUpdater, GetExistingValueInMiddleOfBlock, which mimics the current GetValueInMiddleOfBlock function but with the addition that it will never generate any instructions, only fetch a vreg if one already exists. This is used to find valid VRegs for debug values, or else set them undef.

Diff Detail

Event Timeline

StephenTozer created this revision.Jul 27 2021, 7:24 AM
StephenTozer requested review of this revision.Jul 27 2021, 7:24 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 27 2021, 7:24 AM

This sounds really good; I feel bad about a considerable portion of logic being duplicated here though. Annoyingly as "please rewrite" is, could we instead:

  • Give GetValueInMiddleOfBlock a default-false "AllowUnavailable" argument,
  • Lambda-ise picking GetValueAtEndOfBlockInternal or the Existing flavour,
  • Bail out returning $noreg just before creating new values

Or something like that. IMO, future generations will thank us.

llvm/include/llvm/CodeGen/MachineSSAUpdater.h
100

Nit, newline between comments and preceeding method. IMO "Same as the above" is easier to read, explicit being better than implicit.

102
llvm/lib/CodeGen/TailDuplicator.cpp
235–240

Performance opinion: better to store debug uses and re-visit rather than enumerate all the uses again, it'll preserve the same performance characteristics as before this patch.

Also: will not UseMO.setReg invalidate the vreg use list?

StephenTozer added inline comments.Jul 28 2021, 6:15 AM
llvm/lib/CodeGen/TailDuplicator.cpp
235–240

The vreg use list is (as far as I'm aware) a linked list, so calling setReg after iterating to the next use will not cause any issues.

jmorse added inline comments.Jul 28 2021, 6:18 AM
llvm/lib/CodeGen/TailDuplicator.cpp
235–240

Ah, I missed the pre-increment x_x

Reduce code duplication, avoid unnecessary use-list iteration.

Fix incorrect parameter, false -> true

LGTM; however, will the use of isDebugValue cause this to affect variadic variable locations? It's probably fine to only address one form in this patch, and consider DBG_VALUE_LIST some other time.

llvm/lib/CodeGen/TailDuplicator.cpp
226
This revision was not accepted when it landed; it landed in state Needs Review.Dec 3 2021, 7:30 AM
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.