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][Dexter] Loop strength reduction preserves little debug info #38163

Closed
jmorse opened this issue Sep 3, 2018 · 9 comments
Closed
Labels
bugzilla Issues migrated from bugzilla debuginfo

Comments

@jmorse
Copy link
Member

jmorse commented Sep 3, 2018

Bugzilla Link 38815
Version trunk
OS Linux
Blocks #38116
CC @chrisjbris,@gregbedwell,@CarlosAlbertoEnciso,@elavkje,@pogo59

Extended Description

It seems the loop-strength-reduction pass doesn't preserve debug information, for any transformation it makes. Compiling the example below with llvm/clang @ r340912 and options "-O2 -g -fno-inline" for x86_64, using both gdb and lldb, both the value of "i" and "blah" are reported as being optimised out, after being rewritten by LSR:

-------->8--------
int
foo(int blah)
{
int i;
for (i = blah; i < blah + 10; i++) {
if (i < 3)
return 0;
}
return 1;
}

int
main()
{
return foo(3);
}
--------8<--------

Which would be fairly frustrating if one landed in the loop and were unable to determine either the loop bound or which iteration it was on. (The example is contrived, but LSR still knackers more complicated loops).

This isn't a bug per se, and the DebugInfo doesn't mislead anyone, it's just a poor debug experience that will annoy developers. Particularly galling is that the values of "i" and "blah" remain in registers for the whole loop, but are still not available to the debugger.

@CarlosAlbertoEnciso
Copy link
Member

For a better understanding:

-------->8--------
int foo(int blah) {
int bob;
for (bob = blah; bob < blah + 10; ++bob) {
if (bob < 3)
return 0;
}
return 1;
}
-------->8--------

*** IR Dump Before Loop Strength Reduction ***

; Preheader:
entry:
[..]
%cmp1 = icmp slt i32 %blah, 3, !dbg !​16
%0 = add nsw i32 %blah, 9, !dbg !​21
br label %for.body, !dbg !​22

; Loop:
for.body:
%bob.06 = phi i32 [ %blah, %entry ], [ %inc, %for.cond ]
call void @​llvm.dbg.value(metadata i32 %bob.06, metadata !​14, ...), !dbg !​15
call void @​llvm.dbg.value(metadata i32 %bob.06, metadata !​14, ...), !dbg !​15
br i1 %cmp1, label %cleanup, label %for.cond, !dbg !​26

for.cond:
%inc = add nsw i32 %bob.06, 1, !dbg !​23
call void @​llvm.dbg.value(metadata i32 %inc, metadata !​14, ...), !dbg !​15
call void @​llvm.dbg.value(metadata i32 %inc, metadata !​14, ...), !dbg !​15
%cmp = icmp slt i32 %bob.06, %0, !dbg !​23
br i1 %cmp, label %for.body, label %cleanup, !dbg !​22, !llvm.loop !​24

; Exit blocks
cleanup:
[..]

*** IR Dump After Loop Strength Reduction ***

; Preheader:
entry:
[..]
%cmp1 = icmp slt i32 %blah, 3, !dbg !​16
%0 = add nsw i32 %blah, 9, !dbg !​21
%1 = add i32 %blah, -1, !dbg !​22
br label %for.body, !dbg !​22

; Loop:
for.body:
%lsr.iv = phi i32 [ %lsr.iv.next, %for.cond ], [ %1, %entry ]
call void @​llvm.dbg.value(metadata i32 undef, metadata !​14, ...), !dbg !​15
call void @​llvm.dbg.value(metadata i32 undef, metadata !​14, ...), !dbg !​15
br i1 %cmp1, label %cleanup, label %for.cond, !dbg !​26

for.cond:
call void @​llvm.dbg.value(metadata i32 undef, metadata !​14, ...), !dbg !​15
call void @​llvm.dbg.value(metadata i32 undef, metadata !​14, ...), !dbg !​15
%lsr.iv.next = add i32 %lsr.iv, 1, !dbg !​23
%cmp = icmp slt i32 %lsr.iv.next, %0, !dbg !​23
br i1 %cmp, label %for.body, label %cleanup, !dbg !​22, !llvm.loop !​24

; Exit blocks
cleanup:
[..]

@CarlosAlbertoEnciso
Copy link
Member

'bob' and 'blah' have been optimized out.

'bob' replaced by: '%lsr.iv' and '%lsr.iv.next'
'blah' replaced by: '%1'

@jmorse
Copy link
Member Author

jmorse commented Oct 1, 2019

NB, Alexey made a start on this here: https://reviews.llvm.org/D67770

@markuslavin
Copy link
Contributor

This issue is being addressed in https://reviews.llvm.org/D87494

@markuslavin
Copy link
Contributor

This particular issue is resolved in commit 06758c6

@chrisjbris
Copy link

Please see https://reviews.llvm.org/D105207 for some more recent work in this area.

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 10, 2021
@chrisjbris
Copy link

Suggest this issue is closed as the above patch has been present since 13.0.0 and there is also D120168 to add further salvaging.

@llvmbot
Copy link
Member

llvmbot commented Feb 23, 2022

@llvm/issue-subscribers-debuginfo

@jryans
Copy link
Member

jryans commented May 27, 2022

As @chrisjbris suggested above, I'll go ahead and close this issue since LSR debug info salvaging has landed. We can track further refinements with new issues as needed.

@jryans jryans closed this as completed May 27, 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 debuginfo
Projects
None yet
Development

No branches or pull requests

7 participants