This is an archive of the discontinued LLVM Phabricator instance.

[DebugInfo] Keep DBG_VALUE undef in LiveDebugVariables
ClosedPublic

Authored by uabelho on Jun 18 2018, 5:27 AM.

Details

Summary

[DebugInfo] Keep DBG_VALUE undef in LiveDebugVariables

Fixes PR36579.

For cases where we had e.g.

DBG_VALUE 42
[...]
DBG_VALUE undef

LiveDebugVariables would discard all undef DBG_VALUEs and then it would
look like the variable had the value 42 throughout the rest of the
function, which is incorrect.

With this patch we don't remove all undef DBG_VALUEs in LiveDebugVariables
so they will be kept after register allocation just like other DBG_VALUEs
which will yield more correct debug information.

Diff Detail

Repository
rL LLVM

Event Timeline

uabelho created this revision.Jun 18 2018, 5:27 AM

I don't know this code very well so I did an attempt to remove the undef removal, and then I ran a bunch of tests to see what
would go wrong. I then ended up in failed assertions when trying to find the undef value in "locations" and "LocNoMap" so
I gurded that with !isUndef() checks.

Does this make sense? Any other obvious cases where we need to do something special with undef?

We could perhaps change the "getLocationNo" method so it inserts an undef value in "locations" as well, but I've no idea
if that would make anything better.

Ka-Ka added a subscriber: Ka-Ka.Jun 18 2018, 5:42 AM
aprantl added inline comments.Jun 18 2018, 8:37 AM
lib/CodeGen/LiveDebugVariables.cpp
1097 ↗(On Diff #151694)

Just for my understanding: What is preventing you from adding the undef location into the map?

bjope added a subscriber: bjope.Jun 18 2018, 10:43 AM
bjope added inline comments.
lib/CodeGen/LiveDebugVariables.cpp
1097 ↗(On Diff #151694)

The reason afaik: locNo() is ~0U for isUndef() (that is actually how undef is identified). So adding it to the LocNoMap, which actually is implemented as a vector and not a map, would make that vector very long.

Maybe that can be solved somehow :

  • chopping off another bit in DbgValueLocation to describe IsUndef similar to WasIndirect
  • or by reserving locNo 0 for isUndef instead of using ~0U)
  • or is it possible to use a map instead of a vector to implement the LocNoMap
aprantl accepted this revision.Jun 18 2018, 11:25 AM

Looks good after adding an additional comment explaining why the undef values have to be treated differently. Thanks!

lib/CodeGen/LiveDebugVariables.cpp
1095 ↗(On Diff #151694)

Please add a comment explaining why they aren't placed in the LocNoMap so future readers understand this.

1097 ↗(On Diff #151694)

Got it. The current patch doesn't look to bad either.

This revision is now accepted and ready to land.Jun 18 2018, 11:25 AM
uabelho updated this revision to Diff 151898.Jun 19 2018, 5:42 AM

Added some comments about why undef values are not added to "locations".

Also added an isUndef() check in UserValue::rewriteLocations so we don't try to update the locNo
of undef locNo (which should always be the same, ~0).

Thanks aprantl and bjope!

I think I addressed the comments. I ran tests on the patch all night and found another case where we need to special case isUndef(),
I fixed that too in the updated patch.

Do you still think this looks ok?

I think I'll submit this tomorrow morning when I get to the office unless something new pops up in my tests tonight.

aprantl added inline comments.Jun 20 2018, 9:15 AM
lib/CodeGen/LiveDebugVariables.cpp
227 ↗(On Diff #151898)

Can you delete the getLocationNo - part?

992 ↗(On Diff #151898)

I think with the comment this is fine.

uabelho updated this revision to Diff 152226.Jun 20 2018, 11:52 PM
uabelho marked an inline comment as done.
This revision was automatically updated to reflect the committed changes.