Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

[DebugInfo@O2][Dexter] Loop strength reduction preserves little debug info #37788

Open Quuxplusone opened 6 years ago

Quuxplusone commented 6 years ago
Bugzilla Link PR38815
Status NEW
Importance P normal
Reported by Jeremy Morse (jeremy.morse.llvm@gmail.com)
Reported on 2018-09-03 09:49:07 -0700
Last modified on 2021-08-05 11:36:20 -0700
Version trunk
Hardware PC Linux
CC chackz0x12@gmail.com, chris.jackson@sony.com, greg.bedwell@sony.com, international.phantom@gmail.com, llvm-bugs@lists.llvm.org, markus.lavin@ericsson.com, paul_robinson@playstation.sony.com
Fixed by commit(s)
Attachments
Blocks PR38768
Blocked by
See also
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.
Quuxplusone commented 5 years ago
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:
[..]
Quuxplusone commented 5 years ago
'bob' and 'blah' have been optimized out.

'bob' replaced by: '%lsr.iv' and '%lsr.iv.next'
'blah' replaced by: '%1'
Quuxplusone commented 5 years ago

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

Quuxplusone commented 4 years ago

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

Quuxplusone commented 4 years ago

This particular issue is resolved in commit 06758c6a6135f59deec8e73d4fcb69946ab47f54

Quuxplusone commented 3 years ago

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