[PATCH] D127488: Remove debug info with zero line from constants inserted at entry block

Vladislav Dzhidzhoev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 10 04:30:53 PDT 2022


dzhidzhoev created this revision.
dzhidzhoev added reviewers: echristo, aemerson, arsenm, davide, paquette.
Herald added subscribers: hiraditya, kristof.beyls.
Herald added a project: All.
dzhidzhoev requested review of this revision.
Herald added subscribers: llvm-commits, wdng.
Herald added a project: LLVM.

Emission of constants having DebugLoc with line 0 causes significant increase of debug_line section size for some source files.

To illustrate, we can compare section sizes of several files from llvm test-suite, built with SelectionDAG vs GlobalISel, on Aarch64 (macOS), using -O0 optimization level:

| Source path                                                    | SDAG text sz | GISel text sz | SDAG debug_line sz | GISel debug_line sz |
| -------------------------------------------------------------- | ------------ | ------------- | ------------------ | ------------------- |
| `SingleSource/Regression/C/gcc-c-torture/execute/strlen-2.c`   | 15320        | 660           | 14872              | 6340                |
| `SingleSource/Regression/C/gcc-c-torture/execute/20040629-1.c` | 33640        | 26300         | 2812               | 6693                |
| `SingleSource/Benchmarks/Misc/flops-4.c`                       | 1428         | 1196          | 594                | 1008                |
| `MultiSource/Benchmarks/MiBench/consumer-typeset/z31.c`        | 2716         | 964           | 809                | 903                 |
| `MultiSource/Benchmarks/Prolangs-C/gnugo/showinst.c`           | 2534         | 2502          | 189                | 573                 |
|

For instance, here is a fragment of `flops-4.c.o` debug line section dump

  Address            Line   Column File   ISA Discriminator Flags
  ------------------ ------ ------ ------ --- ------------- -------------
  0x0000000000000000    174      0      1   0             0  is_stmt
  0x0000000000000010      0      0      1   0             0
  0x0000000000000018    185      4      1   0             0  is_stmt prologue_end
  0x000000000000001c      0      0      1   0             0
  0x0000000000000024    186      4      1   0             0  is_stmt
  0x000000000000002c    189     10      1   0             0  is_stmt
  0x0000000000000030      0      0      1   0             0
  0x0000000000000038    207     11      1   0             0  is_stmt
  0x0000000000000044    208     11      1   0             0  is_stmt
  0x0000000000000048      0      0      1   0             0
  0x0000000000000058    210     10      1   0             0  is_stmt
  0x000000000000005c      0      0      1   0             0
  0x0000000000000060    211     10      1   0             0  is_stmt
  0x0000000000000064      0      0      1   0             0
  0x000000000000006c    212     10      1   0             0  is_stmt
  0x0000000000000070      0      0      1   0             0
  0x000000000000007c    213     10      1   0             0  is_stmt
  0x0000000000000080      0      0      1   0             0
  0x0000000000000088    214     10      1   0             0  is_stmt
  0x000000000000008c      0      0      1   0             0
  0x0000000000000094    215     10      1   0             0  is_stmt

Lot of zero lines are produced by constants (global values) having DebugLoc with line 0.
It seems that they're not significant for debugging experience.

With the commit applied, total size of debug_line sections of llvm shared libraries has reduced by 2.5%.
Change of debug line section size of files listed above:

| Source path                                                    | GISel debug_line sz | Patch debug_line sz |
| -------------------------------------------------------------- | ------------------- | ------------------- |
| `SingleSource/Regression/C/gcc-c-torture/execute/strlen-2.c`   | 6340                | 1465                |
| `SingleSource/Regression/C/gcc-c-torture/execute/20040629-1.c` | 6693                | 3782                |
| `SingleSource/Benchmarks/Misc/flops-4.c`                       | 1008                | 609                 |
| `MultiSource/Benchmarks/MiBench/consumer-typeset/z31.c`        | 903                 | 841                 |
| `MultiSource/Benchmarks/Prolangs-C/gnugo/showinst.c`           | 573                 | 190                 |


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D127488

Files:
  llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
  llvm/test/CodeGen/AArch64/GlobalISel/combine-shift-of-shifted-dbg-value-fallback.ll
  llvm/test/CodeGen/AArch64/GlobalISel/constant-dbg-loc.ll


Index: llvm/test/CodeGen/AArch64/GlobalISel/constant-dbg-loc.ll
===================================================================
--- llvm/test/CodeGen/AArch64/GlobalISel/constant-dbg-loc.ll
+++ llvm/test/CodeGen/AArch64/GlobalISel/constant-dbg-loc.ll
@@ -6,16 +6,16 @@
 @var1 = common global i32 0, align 4, !dbg !0
 @var2 = common global i32 0, align 4, !dbg !6
 
-; We check here that the G_GLOBAL_VALUE has a debug loc with line 0.
+; We check here that the G_GLOBAL_VALUE has no debug loc.
 define i32 @main() #0 !dbg !14 {
   ; CHECK-LABEL: name: main
   ; CHECK: bb.1.entry:
   ; CHECK:   successors: %bb.2(0x40000000), %bb.3(0x40000000)
   ; CHECK:   [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 0
-  ; CHECK:   [[GV:%[0-9]+]]:_(p0) = G_GLOBAL_VALUE @var1, debug-location !DILocation(line: 0, scope: !18)
+  ; CHECK:   [[GV:%[0-9]+]]:_(p0) = G_GLOBAL_VALUE @var1
   ; CHECK:   [[C1:%[0-9]+]]:_(s32) = G_CONSTANT i32 1
   ; CHECK:   [[C2:%[0-9]+]]:_(s32) = G_CONSTANT i32 2
-  ; CHECK:   [[GV1:%[0-9]+]]:_(p0) = G_GLOBAL_VALUE @var2, debug-location !DILocation(line: 0, scope: !22)
+  ; CHECK:   [[GV1:%[0-9]+]]:_(p0) = G_GLOBAL_VALUE @var2
   ; CHECK:   [[FRAME_INDEX:%[0-9]+]]:_(p0) = G_FRAME_INDEX %stack.0.retval
   ; CHECK:   G_STORE [[C]](s32), [[FRAME_INDEX]](p0) :: (store (s32) into %ir.retval)
   ; CHECK:   [[LOAD:%[0-9]+]]:_(s32) = G_LOAD [[GV]](p0), debug-location !17 :: (dereferenceable load (s32) from @var1)
Index: llvm/test/CodeGen/AArch64/GlobalISel/combine-shift-of-shifted-dbg-value-fallback.ll
===================================================================
--- llvm/test/CodeGen/AArch64/GlobalISel/combine-shift-of-shifted-dbg-value-fallback.ll
+++ llvm/test/CodeGen/AArch64/GlobalISel/combine-shift-of-shifted-dbg-value-fallback.ll
@@ -54,12 +54,10 @@
 ; CHECK-NEXT:    //DEBUG_VALUE: baz:3 <- undef
 ; CHECK-NEXT:    .loc 1 4 1 prologue_end // tmp.ll:4:1
 ; CHECK-NEXT:    lsl x8, x0, #4
-; CHECK-NEXT:    .loc 1 0 0 is_stmt 0 // tmp.ll:0:0
 ; CHECK-NEXT:    adrp x9, global+202752
 ; CHECK-NEXT:    add x9, x9, :lo12:global+202752
-; CHECK-NEXT:    .loc 1 4 1 // tmp.ll:4:1
 ; CHECK-NEXT:    and x8, x8, #0x1ff0
-; CHECK-NEXT:    .loc 1 5 1 is_stmt 1 // tmp.ll:5:1
+; CHECK-NEXT:    .loc 1 5 1 // tmp.ll:5:1
 ; CHECK-NEXT:    str xzr, [x9, x8]
 ; CHECK-NEXT:    .loc 1 6 1 // tmp.ll:6:1
 ; CHECK-NEXT:    ret
Index: llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
===================================================================
--- llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
+++ llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
@@ -150,11 +150,11 @@
     LLVM_DEBUG(dbgs() << "Checking DILocation from " << *CurrInst
                       << " was copied to " << MI);
 #endif
-    // We allow insts in the entry block to have a debug loc line of 0 because
+    // We allow insts in the entry block to have no debug loc because
     // they could have originated from constants, and we don't want a jumpy
     // debug experience.
     assert((CurrInst->getDebugLoc() == MI.getDebugLoc() ||
-            MI.getDebugLoc().getLine() == 0) &&
+            (MI.getParent()->isEntryBlock() && !MI.getDebugLoc())) &&
            "Line info was not transferred to all instructions");
   }
 };
@@ -2969,11 +2969,9 @@
 
 bool IRTranslator::translate(const Constant &C, Register Reg) {
   // We only emit constants into the entry block from here. To prevent jumpy
-  // debug behaviour set the line to 0.
+  // debug behaviour remove debug line.
   if (auto CurrInstDL = CurBuilder->getDL())
-    EntryBuilder->setDebugLoc(DILocation::get(C.getContext(), 0, 0,
-                                              CurrInstDL.getScope(),
-                                              CurrInstDL.getInlinedAt()));
+    EntryBuilder->setDebugLoc(DebugLoc());
 
   if (auto CI = dyn_cast<ConstantInt>(&C))
     EntryBuilder->buildConstant(Reg, *CI);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D127488.435872.patch
Type: text/x-patch
Size: 3862 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220610/0ac8f569/attachment.bin>


More information about the llvm-commits mailing list