This is an archive of the discontinued LLVM Phabricator instance.

[DebugInfo] Don't skip deletion of dead BasicBlocks because of debug-info instructions
AbandonedPublic

Authored by jmorse on Apr 25 2022, 9:25 AM.

Details

Summary

This patch fixes a debug-info-changes-codegen problem, reported here:

https://github.com/llvm/llvm-project/issues/50525

Where the unreachableblockelim pass wouldn't delete an empty unreachable block due to the presence of debug-info instructions. The solution, as ever, is to ignore the debug-info instructions. This particular function is different, in that it steps through the block backwards, and so existing filter functions aren't suitable as they all expect forward iterators. Thus, a help lambda is required.

The most worry part here is replacing a line that is:

BB->getInsnlist().pop_back()

With Instruction::eraseFromParent on a non-back instruction. I think this is fine: it's just that over time, the set of helper functions that LLVM uses has changed, and this line hasn't been changed since at least 2008: https://github.com/llvm/llvm-project/commit/bcc904a67c2f77b6a619d8ec9370af02e3a5ce02

Diff Detail

Event Timeline

jmorse created this revision.Apr 25 2022, 9:25 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 25 2022, 9:25 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
jmorse requested review of this revision.Apr 25 2022, 9:25 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 25 2022, 9:25 AM
jryans accepted this revision.Apr 25 2022, 9:36 AM
jryans added a subscriber: jryans.

Thanks, this looks good to me. 😄

This revision is now accepted and ready to land.Apr 25 2022, 9:36 AM

I don't spend a lot of time mucking around with IR transforms, so I'm not clear how _preserving_ the debug instructions makes it _possible_ to delete the block. Intuitively that doesn't make sense.

jmorse abandoned this revision.May 3 2022, 2:19 AM

/me squints,

Actually, it turns out the test is sketchy -- because I was using the autogenerated check lines, it wasn't testing for the absence of any other blocks. It doesn't appear that unreachableblockelim is the culprit at all, that's just where a change in CFG happens, which had attracted my attention. More detail on the GH ticket.