This is an archive of the discontinued LLVM Phabricator instance.

WIP: [Utils] Salvage debug info of DCE'ed extractvalue instructions
Needs ReviewPublic

Authored by vsk on Feb 14 2018, 3:57 PM.

Details

Summary

Based on a recent ToT, this salvages an additional 1072 debug values in a
stage2 build of clang and preserves an additional 40 source variables (as
counted by llvm-dwarfdump --statistics).

WIP: I have not yet found a small, end-to-end test for this patch (i.e something I can verify in a debugger). I'm waiting on delta to reduce a file in llvm that triggers the new logic.

Diff Detail

Event Timeline

vsk created this revision.Feb 14 2018, 3:57 PM
vsk retitled this revision from [Utils] Salvage debug info of DCE'ed extractvalue instructions to WIP: [Utils] Salvage debug info of DCE'ed extractvalue instructions.Feb 15 2018, 2:32 PM
vsk edited the summary of this revision. (Show Details)
aprantl added inline comments.Feb 15 2018, 2:40 PM
lib/Transforms/Utils/Local.cpp
1601

Can you add a comment explaining why this is safe? I.e., because the size of the variable being described implicitly masks out the upper bits of the value..

1605

Why does this loop go all the way to FieldIndices.size()?

aprantl added inline comments.Feb 15 2018, 5:12 PM
lib/Transforms/Utils/Local.cpp
1605

This is overloading I which makes the code harder to read.

1605

got it.. this is iterating over the field indices of the extract_value instruction, not over the data type! I was confused by this.

test/Transforms/InstCombine/debuginfo-variables.ll
124

Hard-coding the metadata numbering (metadata !92, !dbg !100) seems to be really fragile, and probably doesn't add anything to the test.

vsk updated this revision to Diff 134541.Feb 15 2018, 6:23 PM
vsk marked 4 inline comments as done.
vsk added inline comments.
lib/Transforms/Utils/Local.cpp
1605

I'll add a comment.

test/Transforms/InstCombine/debuginfo-variables.ll
124

It tests that we don't apply debug values to the wrong variables, which seemed worthwhile to me. Can we keep the numbering until it makes test updates harder than they need to be? Or would you rather simply delete them now?

aprantl added inline comments.Feb 16 2018, 8:27 AM
test/Transforms/InstCombine/debuginfo-variables.ll
124

Inevitably in the near future someone will change instcombine or the debug info in a way that changes the relative order of the MDNodes and then they will have a hard time understanding how to update this testcase. For the same reason it will make cherry-picking this patch to a release branch much harder than necessary. Since the numbering here really isn't relevant to the test, I would prefer to not check for it at all. E.g.:

CHECK-NEXT:  call void @llvm.dbg.value(metadata %ty2 %S,
CHECK-SAME:                                             metadata !DIExpression(DW_OP_constu, 8, DW_OP_shr, DW_OP_stack_value))

That's hoping that combining CHECK-NEXT and CHECK-SAME like this actually works.

vsk added a comment.Feb 16 2018, 7:03 PM

I'm having trouble finding an end-to-end test for this because of issues in the register allocator. This may end up depending on https://reviews.llvm.org/D43427 and possibly other follow-ups.

test/Transforms/InstCombine/debuginfo-variables.ll
124

Gotcha, I'll fix this in the next update.

I have not yet found a small, end-to-end test for this patch

I don't think that one is strictly necessary. Testing the result of the pass directly is preferable anyway.

vsk added a comment.Feb 19 2018, 11:37 AM

I have not yet found a small, end-to-end test for this patch

I don't think that one is strictly necessary. Testing the result of the pass directly is preferable anyway.

I wasn't planning on checking in the end-to-end test -- I just wanted to make sure that it's possible to see variables salvaged from extractvalue instructions in the debugger.

I did some more digging and found that FastISel does not emit DBG_VALUE MI's when it sees the sorts of llvm.dbg.value() instructions this patch generates. Concretely, no DBG_VALUE is generated for this instruction:

%s_ev = load %struct.S, %struct.S* %s
%x_ev = extractvalue %struct.S %s_ev, 0
call void @llvm.dbg.value(metadata %struct.S %s_ev, metadata !24, metadata !DIExpression()), !dbg !55
dblaikie added inline comments.
lib/Transforms/Utils/Local.cpp
1625

Maybe this could/should be:

if (auto *StructTy = dyn_cast<StructType(IndexedTy)) {
  ...
} else {
  assert(array type);
  ...
}