[llvm] [DebugInfo][LICM] Fix missing debug location updates (PR #91729)

Orlando Cazalet-Hyams via llvm-commits llvm-commits at lists.llvm.org
Fri May 10 07:44:56 PDT 2024


================
@@ -0,0 +1,78 @@
+; RUN: opt -passes=licm -verify-memoryssa -S < %s | FileCheck %s
+
+; Test that LICM's hoistRegin() 
+
+define zeroext i1 @invariant_denom(double %v) !dbg !5 {
+; CHECK:  loop:
+; CHECK:    [[TMP1:%.*]] = fmul fast double {{.*}}, !dbg [[DBG29:![0-9]+]]
+; CHECK:  [[DBG29]] = !DILocation(line: 5,
+;
+entry:
+  br label %loop, !dbg !25
+
+loop:                                             ; preds = %loop, %entry
+  %v3 = phi i32 [ 0, %entry ], [ %v11, %loop ], !dbg !26
+  %v4 = phi i32 [ 0, %entry ], [ %v12, %loop ], !dbg !27
+  %v5 = uitofp i32 %v4 to double, !dbg !28
+  %v6 = fdiv fast double %v5, %v, !dbg !29
+  %v7 = fptoui double %v6 to i64, !dbg !30
+  %v8 = and i64 %v7, 1, !dbg !31
+  %v9 = xor i64 %v8, 1, !dbg !32
+  %v10 = trunc i64 %v9 to i32, !dbg !33
+  %v11 = add i32 %v10, %v3, !dbg !34
+  %v12 = add nuw i32 %v4, 1, !dbg !35
+  %v13 = icmp eq i32 %v12, -1, !dbg !36
+  br i1 %v13, label %end, label %loop, !dbg !37
+
+end:                                              ; preds = %loop
+  %v15 = phi i32 [ %v11, %loop ], !dbg !38
+  %v16 = icmp ne i32 %v15, 0, !dbg !39
+  ret i1 %v16, !dbg !40
+}
+
+
+!llvm.dbg.cu = !{!0}
+!llvm.debugify = !{!2, !3}
+!llvm.module.flags = !{!4}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: "debugify", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug)
+!1 = !DIFile(filename: "preserving-debugloc.ll", directory: "/")
+!2 = !{i32 16}
+!3 = !{i32 13}
+!4 = !{i32 2, !"Debug Info Version", i32 3}
+!5 = distinct !DISubprogram(name: "invariant_denom", linkageName: "invariant_denom", scope: null, file: !1, line: 1, type: !6, scopeLine: 1, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !8)
+!6 = !DISubroutineType(types: !7)
+!7 = !{}
+!8 = !{!9, !11, !12, !14, !15, !16, !17, !18, !19, !20, !21, !23, !24}
+!9 = !DILocalVariable(name: "1", scope: !5, file: !1, line: 2, type: !10)
+!10 = !DIBasicType(name: "ty32", size: 32, encoding: DW_ATE_unsigned)
+!11 = !DILocalVariable(name: "2", scope: !5, file: !1, line: 3, type: !10)
+!12 = !DILocalVariable(name: "3", scope: !5, file: !1, line: 4, type: !13)
+!13 = !DIBasicType(name: "ty64", size: 64, encoding: DW_ATE_unsigned)
+!14 = !DILocalVariable(name: "4", scope: !5, file: !1, line: 5, type: !13)
+!15 = !DILocalVariable(name: "5", scope: !5, file: !1, line: 6, type: !13)
+!16 = !DILocalVariable(name: "6", scope: !5, file: !1, line: 7, type: !13)
+!17 = !DILocalVariable(name: "7", scope: !5, file: !1, line: 8, type: !13)
+!18 = !DILocalVariable(name: "8", scope: !5, file: !1, line: 9, type: !10)
+!19 = !DILocalVariable(name: "9", scope: !5, file: !1, line: 10, type: !10)
+!20 = !DILocalVariable(name: "10", scope: !5, file: !1, line: 11, type: !10)
+!21 = !DILocalVariable(name: "11", scope: !5, file: !1, line: 12, type: !22)
----------------
OCHyams wrote:

if you give opt the option `--debugify-level=locations` then the debugify pass only adds `!dbg` metadata and doesn't insert `dbg.value`s or create DILocalVariables.

In any case, please can you remove these unused variables?

You could also remove remove `!dbg` attachments and the `!DILocations` other than the one for `line: 5`, as that's the only one used in the test, but this isn't super important (feel free to ignore). 


https://github.com/llvm/llvm-project/pull/91729


More information about the llvm-commits mailing list