Skip to content

Commit 0cc0242

Browse files
committed
[LoopUnroll] Remove redundant debug instructions after blocks have
been merged into the predecessor, It can reduce some compile time in some cases. This change only fixes the situation of loop unrolling, and other situations are not considered. "RemoveRedundantDbgInstrs" seems to be very time-consuming. Thus, we just add here after the "Dest" has been merged into the "Fold". fixes: #89073
1 parent 7b040d0 commit 0cc0242

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

llvm/lib/Transforms/Utils/LoopUnroll.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -974,6 +974,9 @@ llvm::UnrollLoop(Loop *L, UnrollLoopOptions ULO, LoopInfo *LI,
974974
/*MSSAU=*/nullptr, /*MemDep=*/nullptr,
975975
/*PredecessorWithTwoSuccessors=*/false,
976976
DTUToUse ? nullptr : DT)) {
977+
// Remove redundant Dbg instructions for reducing compile time.
978+
if (Fold->getParent()->getSubprogram())
979+
RemoveRedundantDbgInstrs(Fold);
977980
// Dest has been folded into Fold. Update our worklists accordingly.
978981
std::replace(Latches.begin(), Latches.end(), Dest, Fold);
979982
llvm::erase(UnrolledLoopBlocks, Dest);
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
; RUN: opt < %s -S -passes=loop-unroll | FileCheck %s
2+
3+
define i64 @d(i1 %tobool.not, i32 %add, i64 %conv23) !dbg !14{
4+
entry:
5+
br label %for.body
6+
7+
for.body: ; preds = %for.body, %entry
8+
; There should be only one "llvm.dbg.vale" after loop unrolling
9+
; CHECK: call void @llvm.dbg.value
10+
; CHECK-NOT: call void @llvm.dbg.value
11+
12+
%k.045 = phi i64 [ 0, %entry ], [ %k.046, %for.body ]
13+
tail call void @llvm.dbg.value(metadata i32 0, metadata !13, metadata !DIExpression()), !dbg !17
14+
%k.046 = add nuw nsw i64 %k.045, 1
15+
%exitcond = icmp ne i64 %k.046, 5
16+
br i1 %exitcond, label %for.body, label %for.end22
17+
18+
for.end22: ; preds = %for.body
19+
ret i64 %k.046
20+
}
21+
22+
; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
23+
declare void @llvm.dbg.value(metadata, metadata, metadata)
24+
25+
!llvm.dbg.cu = !{!0}
26+
!llvm.module.flags = !{!12}
27+
28+
!0 = distinct !DICompileUnit(language: DW_LANG_C89, file: !1, producer: "clang version 19.0.0git (https://github.com/llvm/llvm-project.git ec062f5b33ed22c61742e3c1486f6cba915801e0)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, globals: !2, splitDebugInlining: false, nameTableKind: None)
29+
!1 = !DIFile(filename: "unroll-remove-redundant-dbg.c", directory: "", checksumkind: CSK_MD5, checksum: "aa30a1d8c04deb9b0f3885c258d2b674")
30+
!2 = !{!3, !8, !10}
31+
!3 = !DIGlobalVariableExpression(var: !4, expr: !DIExpression())
32+
!4 = distinct !DIGlobalVariable(name: "a", scope: !0, file: !1, line: 2, type: !5, isLocal: false, isDefinition: true)
33+
!5 = !DIDerivedType(tag: DW_TAG_typedef, name: "uint32_t", file: !6, line: 198, baseType: !7)
34+
!6 = !DIFile(filename: "/usr/include/stdint.h", directory: "", checksumkind: CSK_MD5, checksum: "da031bcff2d0c1d65aa92e7e68a44ef3")
35+
!7 = !DIBasicType(name: "unsigned int", size: 32, encoding: DW_ATE_unsigned)
36+
!8 = !DIGlobalVariableExpression(var: !9, expr: !DIExpression())
37+
!9 = distinct !DIGlobalVariable(name: "c", scope: !0, file: !1, line: 2, type: !5, isLocal: false, isDefinition: true)
38+
!10 = !DIGlobalVariableExpression(var: !11, expr: !DIExpression())
39+
!11 = distinct !DIGlobalVariable(name: "b", scope: !0, file: !1, line: 2, type: !5, isLocal: false, isDefinition: true)
40+
!12 = !{i32 2, !"Debug Info Version", i32 3}
41+
!13 = !DILocalVariable(name: "f", scope: !14, file: !1, line: 4, type: !5)
42+
!14 = distinct !DISubprogram(name: "d", scope: !1, file: !1, line: 3, type: !15, scopeLine: 3, flags: DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !16)
43+
!15 = !DISubroutineType(types: !16)
44+
!16 = !{}
45+
!17 = !DILocation(line: 0, scope: !14)

0 commit comments

Comments
 (0)