Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DebugInfo@O2] icmp-eq-chain to switch optimisation drops dbg.values #39213

Open
jmorse opened this issue Dec 3, 2018 · 0 comments
Open

[DebugInfo@O2] icmp-eq-chain to switch optimisation drops dbg.values #39213

jmorse opened this issue Dec 3, 2018 · 0 comments
Labels
bugzilla Issues migrated from bugzilla confirmed Verified by a second party wrong-debug

Comments

@jmorse
Copy link
Member

jmorse commented Dec 3, 2018

Bugzilla Link 39866
Version 6.0
OS Linux
Blocks #38102
CC @dwblaikie,@gregbedwell,@CarlosAlbertoEnciso,@pogo59

Extended Description

The dbg.value in the code below is dropped when run through simplifycfg:

opt-6.0 < test.ll -simplifycfg -S

in any recent version of LLVM. It's relatively easy to understand: chains of equality comparisons are converted into being a switch statement. However, any debug metadata on the path from the first comparison to any of the leafs gets dropped, because the switch statement point at the leafs and nothing is salvaged from the intermediate blocks. Thus, if you put that dbg.value in any block other than 'cont1' below, it survives to output.

The example is contrived (and the DebugInfo cooked), but IMHO we can easily do better by replicating intervening dbg.value's into the leaf blocks.

Context: this is another bug seen when investigating bug 38754. Conditional code like this [0] (and line 9688) gets converted to being a switch, and the dbg.value's of the casted expression usually get shifted to an earlier block by placeDbgValues. When left in the correct place (in the 'if' condition) a condition similar to the example below occur.

-------->8--------
declare void @​llvm.dbg.value(metadata, metadata, metadata)

define i32 @​lala(i32 *%ptr, i32 *%otherptr) {
%val = load i32, i32 *%ptr
%isone = icmp eq i32 %val, 1
br i1 %isone, label %isoneb, label %cont1

isoneb:
store i32 1, i32 *%otherptr
ret i32 1

cont1:
call void @​llvm.dbg.value(metadata i32 %val, metadata !​1, metadata !DIExpression()), !dbg !​6
%istwo = icmp eq i32 %val, 2
br i1 %istwo, label %istwob, label %cont2

istwob:
store i32 2, i32 *%otherptr
ret i32 2

cont2:
ret i32 3
}

!llvm.module.flags = !{#4}
!​1 = !DILocalVariable(name: "bees", scope: !​5, type: null)
!​2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !​3, producer: "beards", isOptimized: true, runtimeVersion: 4, emissionKind: FullDebug)
!​3 = !DIFile(filename: "bees.cpp", directory: "")
!​4 = !{i32 2, !"Debug Info Version", i32 3}
!​5 = distinct !DISubprogram(name: "nope", scope: !​2, file: !​3, line: 1, unit: !​2)
!​6 = !DILocation(line: 0, scope: !​5)
--------8<--------

[0] https://github.com/llvm-mirror/clang/blob/aa528ab4a083268edddd038d0f251afe792cfa36/lib/Sema/SemaOpenMP.cpp#L9694

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 10, 2021
@llvmbot llvmbot added the confirmed Verified by a second party label Jan 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla confirmed Verified by a second party wrong-debug
Projects
None yet
Development

No branches or pull requests

2 participants