This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] Drop debug loc in TryToSinkInstruction
ClosedPublic

Authored by vsk on Jun 24 2020, 11:42 AM.

Details

Summary

The advice in HowToUpdateDebugInfo.rst is to "... preserve the debug
location of an instruction if the instruction either remains in its
basic block, or if its basic block is folded into a predecessor that
branches unconditionally".

TryToSinkInstruction doesn't seem to satisfy the criteria as it's
sinking an instruction to some successor block. Preserving the debug loc
can make single-stepping appear to go backwards, or make a breakpoint
hit on that location happen "too late" (since single-stepping from that
breakpoint can cause the function to return unexpectedly).

So, drop the debug location.

Diff Detail

Event Timeline

vsk created this revision.Jun 24 2020, 11:42 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 24 2020, 11:42 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
aprantl accepted this revision.Jun 26 2020, 10:56 AM
aprantl added inline comments.
llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
3358

Should we add anchors to the rst document and refer to the rule by anchor in the comment?

This revision is now accepted and ready to land.Jun 26 2020, 10:56 AM
vsk marked an inline comment as done.Jun 26 2020, 12:39 PM

Thanks!

llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
3358

We tend not to embed links pointing within .rst docs in llvm/lib (I think with good reason, as the source code and the docs can easily get out of sync), but I think it's a good idea to add a pointer to the doc. I'll do this before landing the patch.

This revision was automatically updated to reflect the committed changes.
tbosch added a subscriber: tbosch.Jun 26 2020, 2:54 PM

Hello Vedant,
this broke our internal llvm bootstrap with errors like this:

!dbg attachment points at wrong subprogram for function
!805 = distinct !DISubprogram(name: "terminate", linkageName: "_ZSt9terminatev", scope: !9, file: !798, line: 74, type: !69, scopeLine: 75, flags: DIFlagPrototyped | DIFlagNoReturn | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !797, retainedNodes: !806)
void ()* @_ZSt9terminatev
  call void @llvm.dbg.value(metadata %"struct.__cxxabiv1::__cxa_exception"* %11, metadata !2822, metadata !DIExpression(DW_OP_plus_uconst, 96, DW_OP_stack_value)), !dbg !40889
!40889 = !DILocation(line: 0, scope: !2823)
!2823 = distinct !DISubprogram(name: "__isOurExceptionClass", linkageName: "_ZN10__cxxabiv121__isOurExceptionClassEPK17_Unwind_Exception", scope: !52, file: !2288, line: 105, type: !2824, scopeLine: 105, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2287, retainedNodes: !2828)
!2823 = distinct !DISubprogram(name: "__isOurExceptionClass", linkageName: "_ZN10__cxxabiv121__isOurExceptionClassEPK17_Unwind_Exception", scope: !52, file: !2288, line: 105, type: !2824, scopeLine: 105, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2287, retainedNodes: !2828)
conflicting debug info for argument
  call void @llvm.dbg.value(metadata %struct._Unwind_Exception* %160, metadata !2822, metadata !DIExpression()), !dbg !40889
!42078 = !DILocalVariable(name: "arg", arg: 1, scope: !42076, file: !2499, line: 1198, type: !55)
!2822 = !DILocalVariable(name: "unwind_exception", arg: 1, scope: !2823, file: !2288, line: 105, type: !2826)
conflicting debug info for argument
  call void @llvm.dbg.value(metadata %struct._Unwind_Exception* %160, metadata !2831, metadata !DIExpression()), !dbg !42267
!2822 = !DILocalVariable(name: "unwind_exception", arg: 1, scope: !2823, file: !2288, line: 105, type: !2826)
!2831 = !DILocalVariable(name: "unwind_exception", arg: 1, scope: !2832, file: !2288, line: 95, type: !2826)
LLVM ERROR: Broken module found, compilation aborted!

I wonder whether some of the builders that do a bootstrap see this too.

Is this enough for you to know what is going on?

vsk added a comment.Jun 26 2020, 4:45 PM

@tbosch I've reverted this commit in ee3620643dfc88a178fa4ca116cf83014e4ee547 as it was causing another issue (errors about inlinable instructions without debug locations). After fixing that problem, I could not reproduce the error you reported in a stage2 clang build.