This is an archive of the discontinued LLVM Phabricator instance.

[BranchFolding] Drop location when hoisting
AbandonedPublic

Authored by davide on May 26 2020, 6:01 PM.

Details

Reviewers
jmorse
aprantl
vsk
Summary

Fixes https://bugs.llvm.org/show_bug.cgi?id=46009
See the link for a more detailed analysis

Diff Detail

Event Timeline

davide created this revision.May 26 2020, 6:01 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 26 2020, 6:01 PM
Herald added a subscriber: hiraditya. · View Herald Transcript
davide marked an inline comment as done.May 26 2020, 6:02 PM
davide added inline comments.
llvm/test/DebugInfo/MIR/X86/branch-folder-hoisting-location.mir
1–6

Probably this test can be trimmed, but I wanted to put this online to get a general feeling of the idea.

davide added a comment.EditedMay 26 2020, 6:03 PM

Also, looks like this one exposed a bug in LiveDbgValues. I'll look at it while waiting for the review:

******************** TEST 'LLVM :: CodeGen/X86/dbg-changes-codegen-branch-folding.ll' FAILED ********************
Script:
--
: 'RUN: at line 1';   /Users/davide/work/build/bin/llc -mtriple=x86_64-linux < /Users/davide/work/llvm-project/llvm/test/CodeGen/X86/dbg-changes-codegen-branch-folding.ll | /Users/davide/work/build/bin/FileCheck /Users/davide/work/llvm-project/llvm/test/CodeGen/X86/dbg-changes-codegen-branch-folding.ll
: 'RUN: at line 2';   /Users/davide/work/build/bin/opt -strip-debug < /Users/davide/work/llvm-project/llvm/test/CodeGen/X86/dbg-changes-codegen-branch-folding.ll | /Users/davide/work/build/bin/llc -mtriple=x86_64-linux | /Users/davide/work/build/bin/FileCheck /Users/davide/work/llvm-project/llvm/test/CodeGen/X86/dbg-changes-codegen-branch-folding.ll
--
Exit Code: 2

Command Output (stderr):
--
PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace.
Stack dump:
0.	Program arguments: /Users/davide/work/build/bin/llc -mtriple=x86_64-linux 
1.	Running pass 'Function Pass Manager' on module '<stdin>'.
2.	Running pass 'Live DEBUG_VALUE analysis' on function '@_Z3barii'
0  llc                      0x00000001031bc825 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 37
1  llc                      0x00000001031bb6a8 llvm::sys::RunSignalHandlers() + 248
2  llc                      0x00000001031bce26 SignalHandler(int) + 262
3  libsystem_platform.dylib 0x00007fff7223355d _sigtramp + 29
4  libsystem_platform.dylib 000000000000000000 _sigtramp + 18446603338601253568
5  llc                      0x000000010285958d llvm::MachineFunctionPass::runOnFunction(llvm::Function&) + 285
6  llc                      0x0000000102b82658 llvm::FPPassManager::runOnFunction(llvm::Function&) + 1064
7  llc                      0x0000000102b82933 llvm::FPPassManager::runOnModule(llvm::Module&) + 67
8  llc                      0x0000000102b82dd9 llvm::legacy::PassManagerImpl::run(llvm::Module&) + 937
9  llc                      0x0000000101627b3f compileModule(char**, llvm::LLVMContext&) + 9647
10 llc                      0x000000010162508c main + 1308
11 libdyld.dylib            0x00007fff72026259 start + 1
12 libdyld.dylib            0x0000000000000002 start + 18446603338603404714
FileCheck error: '<stdin>' is empty.
FileCheck command line:  /Users/davide/work/build/bin/FileCheck /Users/davide/work/llvm-project/llvm/test/CodeGen/X86/dbg-changes-codegen-branch-folding.ll

Yes, I captured the MIR before my patch and realized LiveDebugValues crashes without it. It's just the MIR presented to the pass that causes the problem. I'm going to file a separate PR for it.

vsk added inline comments.May 27 2020, 4:04 PM
llvm/lib/CodeGen/BranchFolding.cpp
2028

To summarize some offline discussions:

  • We haven't yet nailed down what should happen to hoisted debug insts, we should discuss (maybe in a follow-up to D80052)
  • D80670 flags the issue here; if we're going to hoist DBG_VALUEs here, they need a location
vsk added inline comments.Jun 4 2020, 3:40 PM
llvm/lib/CodeGen/BranchFolding.cpp
2028

I've drafted some rules for updating debug locs here: https://reviews.llvm.org/D81198. We haven't reached consensus around those rules, but my $0.02 is that HoistCommonCodeInSuccs should: a) clear the debug locs on the instructions it hoists if it found identical instructions in multiple successor blocks, and b) /not/ hoist any DBG_VALUEs. I haven't written up rules for dealing with DBG_VALUEs yet, but I think the guiding principle is going to be 'touch dbg.value/DBG_VALUE as little as possible' to avoid having assignments show up too early.

Back to this. I think what Vedant suggest is the right approach and I'll try implementing it now.

davide abandoned this revision.Sep 3 2020, 12:51 PM

I won't have time to look at this in the future.