This is an archive of the discontinued LLVM Phabricator instance.

[SROA] Really remove associated dbg.declare when removing dead alloca
ClosedPublic

Authored by uabelho on Sep 15 2017, 4:51 AM.

Details

Summary

There already was code that tried to remove the dbg.declare, but that code
was placed after we had called
I->replaceAllUsesWith(UndefValue::get(I->getType()));
on the alloca, so when we searched for the relevant dbg.declare, we
couldn't find it.

Now we do the search before we call RAUW so there is a chance to find it.

An existing testcase needed update due to this. Two dbg.declare with undef
were removed and then suddenly one of the two CHECKS failed.

Before this patch we got

call void @llvm.dbg.declare(metadata i24* undef, metadata !14, metadata !DIExpression(DW_OP_LLVM_fragment, 32, 24)), !dbg !15
call void @llvm.dbg.declare(metadata %struct.prog_src_register* undef, metadata !14, metadata !DIExpression()), !dbg !15
call void @llvm.dbg.value(metadata i32 0, metadata !14, metadata !DIExpression(DW_OP_LLVM_fragment, 0, 32)), !dbg !15
call void @llvm.dbg.value(metadata i32 0, metadata !14, metadata !DIExpression(DW_OP_LLVM_fragment, 32, 24)), !dbg !15

and with it we get

call void @llvm.dbg.value(metadata i32 0, metadata !14, metadata !DIExpression(DW_OP_LLVM_fragment, 0, 32)), !dbg !15
call void @llvm.dbg.value(metadata i32 0, metadata !14, metadata !DIExpression(DW_OP_LLVM_fragment, 32, 24)), !dbg !15

However, the CHECKs in the testcase checked things in a silly order, so
they only passed since they found things in the first dbg.declare. Now
we changed the order of the checks and the test passes.

Diff Detail

Repository
rL LLVM

Event Timeline

uabelho created this revision.Sep 15 2017, 4:51 AM
chandlerc edited reviewers, added: rnk; removed: chandlerc.Sep 19 2017, 6:28 PM
chandlerc edited edge metadata.

I suspect Reid is in a much better position to look at debug info changes to SROA than I am, but let me know if I can help...

rnk accepted this revision.Sep 20 2017, 10:07 AM

lgtm, I actually made this change as part of llvm.dbg.addr (D37768) and then reverted it to keep the diff minimal. Thanks!

This revision is now accepted and ready to land.Sep 20 2017, 10:07 AM
uabelho updated this revision to Diff 116166.Sep 21 2017, 3:58 AM

Rebased to top of tree.

This revision was automatically updated to reflect the committed changes.