This is an archive of the discontinued LLVM Phabricator instance.

[DebugInfo] LiveDebugValues: locations with different exprs should compare differently
ClosedPublic

Authored by jmorse on Aug 29 2019, 6:54 AM.

Details

Summary

In the attached C test case, when joining variable locations from two parent blocks, the "baz" variable in one parent is located in a register with an empty DIExpression, in the other block it's located in the same register but with a complex expression. LiveDebugValues wrongly decides that this is the same location, and propagates one of the locations for "baz" to the exit block. The correct behaviour would be to propagate no location: the value of "baz" depends on the path taken through the program, and isn't stored in a register or stack slot.

Happily this is a simple as adding a DIExpression field to the "VarLoc" class (which identifies a machine location), and having VarLocs compare unequal if their DIExpressions are different. This relies on the DIExpressions being uniq'd, which I believe metadata guarantees.

On a clang-3.4 build this results in no variable losing all their locations, and a fall in 0.6% scope-bytes-covered. Which is great, because those are probably invalid locations.

Diff Detail

Repository
rL LLVM

Event Timeline

jmorse created this revision.Aug 29 2019, 6:54 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 29 2019, 6:54 AM

This makes sense, I'm kind of shocked that me missed something that obvious. Is there a big drop in variable locations with this (i.e., an improvement in accuracy)?

lib/CodeGen/LiveDebugValues.cpp
196 ↗(On Diff #217864)

Do you need to store this here, or could you derive it from MI below?

jmorse marked an inline comment as done.Aug 30 2019, 6:14 AM

Is there a big drop in variable locations with this (i.e., an improvement in accuracy)?

Zero change in the total number of variables with locations; but the number of bytes they cover falls by 0.6% (from 46.8% of total to 46.2%, IIRC). Not a huge change, but that's a decent number of locations that were presumably wrong.

lib/CodeGen/LiveDebugValues.cpp
196 ↗(On Diff #217864)

It could be either; the comment on line 211 indicates past concern about repeatedly accessing MI when comparing VarLocs. I'll give both options a spin through an asan build of clang-3.4 to see if there's any real difference.

jmorse marked an inline comment as done.Sep 2 2019, 7:14 AM
jmorse added inline comments.
lib/CodeGen/LiveDebugValues.cpp
196 ↗(On Diff #217864)

There are only fractional performance differences between {unpatched, this patch, expr-derived-from-MI} clang-trunk when building clang-3.4 with asan. Typically <0.5%, which is more or less the margin of error on my machines. So, it could be either.

aprantl accepted this revision.Sep 3 2019, 9:14 AM
aprantl added inline comments.
lib/CodeGen/LiveDebugValues.cpp
195 ↗(On Diff #217864)

remove (potentially complex)?

This revision is now accepted and ready to land.Sep 3 2019, 9:14 AM
This revision was automatically updated to reflect the committed changes.