llvm-project/llvm/test/Transforms/Inline/dilocation-loop-metadata-update.ll
Björn Pettersson 0956febc4c
[DebugInfo] Handle followup loop metadata in updateLoopMetadataDebugLocations (#157557)
Inliner/IROutliner/CodeExtractor all uses the
updateLoopMetadataDebugLocations helper in order to modify debug
location related to loop metadata. However, the helper has only
been updating DILocation nodes found as operands to the first level
of the MD_loop metadata. There could however be more DILocations
as part of the various kinds of followup metadata. A typical example
would be llvm.loop metadata like this

  !6 = distinct !{!6, !7, !8, !9, !10, !11}
  !7 = !DILocation(line: 6, column: 3, scope: !3)
  !8 = !DILocation(line: 7, column: 22, scope: !3)
  !11 = !{!"llvm.loop.distribute.followup_all", !7, !8, ..., !14}
  !14 = !{!"llvm.loop.vectorize.followup_all", !7, !8, ...}

Instead of just updating !7 and !8 in !6, this patch make sure that
we now recursively update the DILocations in !11 and !14 as well.

Fixes #141568
2025-09-25 13:20:55 +00:00

84 lines
4.6 KiB
LLVM

; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
; RUN: opt < %s -passes=inline -S | FileCheck %s
; When inlining we need to update DILocation recursively for the followup
; metadata when updating llvm.loop metadata.
define void @a() !dbg !3 {
; CHECK-LABEL: define void @a(
; CHECK-SAME: ) !dbg [[DBG3:![0-9]+]] {
; CHECK-NEXT: [[ENTRY:.*:]]
; CHECK-NEXT: br label %[[FOR_BODY:.*]]
; CHECK: [[FOR_BODY]]:
; CHECK-NEXT: br label %[[FOR_BODY]], !llvm.loop [[LOOP6:![0-9]+]]
;
entry:
br label %for.body
for.body: ; preds = %for.body, %entry
br label %for.body, !llvm.loop !6
}
define void @f() !dbg !17 {
; CHECK-LABEL: define void @f(
; CHECK-SAME: ) !dbg [[DBG17:![0-9]+]] {
; CHECK-NEXT: [[ENTRY:.*:]]
; CHECK-NEXT: br label %[[A_EXIT:.*]]
; CHECK: [[A_EXIT]]:
; CHECK-NEXT: br label %[[A_EXIT]], !llvm.loop [[LOOP18:![0-9]+]]
; CHECK: [[A_EXIT1:.*:]]
; CHECK-NEXT: ret void
;
entry:
call void @a(), !dbg !18
ret void
}
!llvm.dbg.cu = !{!0}
!llvm.module.flags = !{!2}
!0 = distinct !DICompileUnit(language: DW_LANG_C11, file: !1, producer: "clang", isOptimized: true, runtimeVersion: 0, emissionKind: NoDebug, splitDebugInlining: false, nameTableKind: None)
!1 = !DIFile(filename: "foo.c", directory: "/")
!2 = !{i32 2, !"Debug Info Version", i32 3}
!3 = distinct !DISubprogram(name: "a", scope: !1, file: !1, line: 3, type: !4, scopeLine: 3, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0)
!4 = !DISubroutineType(types: !5)
!5 = !{}
!6 = distinct !{!6, !7, !8, !9, !10, !11}
!7 = !DILocation(line: 6, column: 3, scope: !3)
!8 = !DILocation(line: 7, column: 22, scope: !3)
!9 = !{!"llvm.loop.mustprogress"}
!10 = !{!"llvm.loop.distribute.enable", i1 true}
!11 = !{!"llvm.loop.distribute.followup_all", !7, !8, !9, !12, !13, !14}
!12 = !{!"llvm.loop.vectorize.width", i32 8}
!13 = !{!"llvm.loop.vectorize.enable", i1 true}
!14 = !{!"llvm.loop.vectorize.followup_all", !7, !8, !9, !15, !16}
!15 = !{!"llvm.loop.isvectorized"}
!16 = !{!"llvm.loop.unroll.count", i32 1}
!17 = distinct !DISubprogram(name: "f", scope: !1, file: !1, line: 9, type: !4, scopeLine: 9, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0)
!18 = !DILocation(line: 9, column: 12, scope: !17)
;.
; CHECK: [[META0:![0-9]+]] = distinct !DICompileUnit(language: DW_LANG_C11, file: [[META1:![0-9]+]], producer: "clang", isOptimized: true, runtimeVersion: 0, emissionKind: NoDebug, splitDebugInlining: false, nameTableKind: None)
; CHECK: [[META1]] = !DIFile(filename: "{{.*}}foo.c", directory: {{.*}})
; CHECK: [[DBG3]] = distinct !DISubprogram(name: "a", scope: [[META1]], file: [[META1]], line: 3, type: [[META4:![0-9]+]], scopeLine: 3, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: [[META0]])
; CHECK: [[META4]] = !DISubroutineType(types: [[META5:![0-9]+]])
; CHECK: [[META5]] = !{}
; CHECK: [[LOOP6]] = distinct !{[[LOOP6]], [[META7:![0-9]+]], [[META8:![0-9]+]], [[META9:![0-9]+]], [[META10:![0-9]+]], [[META11:![0-9]+]]}
; CHECK: [[META7]] = !DILocation(line: 6, column: 3, scope: [[DBG3]])
; CHECK: [[META8]] = !DILocation(line: 7, column: 22, scope: [[DBG3]])
; CHECK: [[META9]] = !{!"llvm.loop.mustprogress"}
; CHECK: [[META10]] = !{!"llvm.loop.distribute.enable", i1 true}
; CHECK: [[META11]] = !{!"llvm.loop.distribute.followup_all", [[META7]], [[META8]], [[META9]], [[META12:![0-9]+]], [[META13:![0-9]+]], [[META14:![0-9]+]]}
; CHECK: [[META12]] = !{!"llvm.loop.vectorize.width", i32 8}
; CHECK: [[META13]] = !{!"llvm.loop.vectorize.enable", i1 true}
; CHECK: [[META14]] = !{!"llvm.loop.vectorize.followup_all", [[META7]], [[META8]], [[META9]], [[META15:![0-9]+]], [[META16:![0-9]+]]}
; CHECK: [[META15]] = !{!"llvm.loop.isvectorized"}
; CHECK: [[META16]] = !{!"llvm.loop.unroll.count", i32 1}
; CHECK: [[DBG17]] = distinct !DISubprogram(name: "f", scope: [[META1]], file: [[META1]], line: 9, type: [[META4]], scopeLine: 9, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: [[META0]])
; CHECK: [[LOOP18]] = distinct !{[[LOOP18]], [[META19:![0-9]+]], [[META21:![0-9]+]], [[META9]], [[META10]], [[META22:![0-9]+]]}
; CHECK: [[META19]] = !DILocation(line: 6, column: 3, scope: [[DBG3]], inlinedAt: [[META20:![0-9]+]])
; CHECK: [[META20]] = distinct !DILocation(line: 9, column: 12, scope: [[DBG17]])
; CHECK: [[META21]] = !DILocation(line: 7, column: 22, scope: [[DBG3]], inlinedAt: [[META20]])
; CHECK: [[META22]] = !{!"llvm.loop.distribute.followup_all", [[META19]], [[META21]], [[META9]], [[META12]], [[META13]], [[META23:![0-9]+]]}
; CHECK: [[META23]] = !{!"llvm.loop.vectorize.followup_all", [[META19]], [[META21]], [[META9]], [[META15]], [[META16]]}
;.