Skip to content

Commit c453da7

Browse files
authored
1 parent 41aa674 commit c453da7

File tree

3 files changed

+127
-1
lines changed

3 files changed

+127
-1
lines changed

llvm/lib/Transforms/Utils/LoopUnroll.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -752,6 +752,14 @@ llvm::UnrollLoop(Loop *L, UnrollLoopOptions ULO, LoopInfo *LI,
752752
}
753753
}
754754

755+
// Remap source location atom instance. Do this now, rather than
756+
// when we remap instructions, because remap is called once we've
757+
// cloned all blocks (all the clones would get the same atom
758+
// number).
759+
if (!VMap.AtomMap.empty())
760+
for (Instruction &I : *New)
761+
RemapSourceAtom(&I, VMap);
762+
755763
// Update our running map of newest clones
756764
LastValueMap[*BB] = New;
757765
for (ValueToValueMapTy::iterator VI = VMap.begin(), VE = VMap.end();
@@ -802,7 +810,8 @@ llvm::UnrollLoop(Loop *L, UnrollLoopOptions ULO, LoopInfo *LI,
802810
}
803811
}
804812

805-
// Remap all instructions in the most recent iteration
813+
// Remap all instructions in the most recent iteration.
814+
// Key Instructions: Nothing to do - we've already remapped the atoms.
806815
remapInstructionsInBlocks(NewBlocks, LastValueMap);
807816
for (BasicBlock *NewBlock : NewBlocks)
808817
for (Instruction &I : *NewBlock)
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
2+
; RUN: opt %s -S --passes=loop-unroll -unroll-runtime=true -unroll-count=4 -unroll-remainder -o - \
3+
; RUN: | FileCheck %s
4+
5+
;; Check atoms are remapped for runtime unrolling.
6+
7+
; CHECK: for.body.epil:
8+
; CHECK-NEXT: store i64 %indvars.iv.unr, ptr %p, align 4, !dbg [[G2R1:!.*]]
9+
10+
; CHECK: for.body.epil.1:
11+
; CHECK-NEXT: store i64 %indvars.iv.next.epil, ptr %p, align 4, !dbg [[G3R1:!.*]]
12+
13+
; CHECK: for.body.epil.2:
14+
; CHECK-NEXT: store i64 %indvars.iv.next.epil.1, ptr %p, align 4, !dbg [[G4R1:!.*]]
15+
16+
; CHECK: for.body:
17+
; CHECK-NEXT: %indvars.iv = phi i64 [ 0, %for.body.lr.ph.new ], [ %indvars.iv.next.3, %for.body ]
18+
; CHECK-NEXT: %niter = phi i64 [ 0, %for.body.lr.ph.new ], [ %niter.next.3, %for.body ]
19+
; CHECK-NEXT: store i64 %indvars.iv, ptr %p, align 4, !dbg [[G1R1:!.*]]
20+
; CHECK-NEXT: %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
21+
; CHECK-NEXT: store i64 %indvars.iv.next, ptr %p, align 4, !dbg [[G5R1:!.*]]
22+
; CHECK-NEXT: %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
23+
; CHECK-NEXT: store i64 %indvars.iv.next.1, ptr %p, align 4, !dbg [[G6R1:!.*]]
24+
; CHECK-NEXT: %indvars.iv.next.2 = add nuw nsw i64 %indvars.iv, 3
25+
; CHECK-NEXT: store i64 %indvars.iv.next.2, ptr %p, align 4, !dbg [[G7R1:!.*]]
26+
; CHECK-NEXT: %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
27+
28+
; CHECK: [[G2R1]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 1)
29+
; CHECK: [[G3R1]] = !DILocation({{.*}}, atomGroup: 3, atomRank: 1)
30+
; CHECK: [[G4R1]] = !DILocation({{.*}}, atomGroup: 4, atomRank: 1)
31+
; CHECK: [[G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1)
32+
; CHECK: [[G5R1]] = !DILocation({{.*}}, atomGroup: 5, atomRank: 1)
33+
; CHECK: [[G6R1]] = !DILocation({{.*}}, atomGroup: 6, atomRank: 1)
34+
; CHECK: [[G7R1]] = !DILocation({{.*}}, atomGroup: 7, atomRank: 1)
35+
36+
define i32 @unroll(ptr %p, i32 %N) local_unnamed_addr !dbg !5 {
37+
entry:
38+
%cmp9 = icmp eq i32 %N, 0
39+
br i1 %cmp9, label %for.cond.cleanup, label %for.body.lr.ph
40+
41+
for.body.lr.ph: ; preds = %entry
42+
%wide.trip.count = zext i32 %N to i64
43+
br label %for.body
44+
45+
for.cond.cleanup: ; preds = %for.body, %entry
46+
%r = phi i32 [ 0, %entry ], [ 1, %for.body ]
47+
ret i32 %r
48+
49+
for.body: ; preds = %for.body, %for.body.lr.ph
50+
%indvars.iv = phi i64 [ 0, %for.body.lr.ph ], [ %indvars.iv.next, %for.body ]
51+
store i64 %indvars.iv, ptr %p, !dbg !8
52+
%indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
53+
%exitcond = icmp eq i64 %indvars.iv.next, %wide.trip.count
54+
br i1 %exitcond, label %for.cond.cleanup, label %for.body
55+
}
56+
57+
!llvm.dbg.cu = !{!0}
58+
!llvm.debugify = !{!2, !3}
59+
!llvm.module.flags = !{!4}
60+
61+
!0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: "debugify", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug)
62+
!1 = !DIFile(filename: "test.ll", directory: "/")
63+
!2 = !{i32 17}
64+
!3 = !{i32 0}
65+
!4 = !{i32 2, !"Debug Info Version", i32 3}
66+
!5 = distinct !DISubprogram(name: "unroll", linkageName: "unroll", scope: null, file: !1, line: 1, type: !6, scopeLine: 1, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0)
67+
!6 = !DISubroutineType(types: !7)
68+
!7 = !{}
69+
!8 = !DILocation(line: 1, column: 1, scope: !5, atomGroup: 1, atomRank: 1)
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
; RUN: opt %s --passes=loop-unroll -S -o - -S | FileCheck %s
2+
3+
; CHECK: store i32 %a, ptr %p, align 4, !dbg [[G1R1:!.*]]
4+
; CHECK: %v.1 = add i32 1, %a, !dbg [[G2R2:!.*]]
5+
; CHECK: store i32 %v.1, ptr %p, align 4, !dbg [[G2R1:!.*]]
6+
; CHECK: %v.2 = add i32 2, %a, !dbg [[G3R2:!.*]]
7+
; CHECK: store i32 %v.2, ptr %p, align 4, !dbg [[G3R1:!.*]]
8+
9+
; CHECK: [[G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1)
10+
; CHECK: [[G2R2]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 2)
11+
; CHECK: [[G2R1]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 1)
12+
; CHECK: [[G3R2]] = !DILocation({{.*}}, atomGroup: 3, atomRank: 2)
13+
; CHECK: [[G3R1]] = !DILocation({{.*}}, atomGroup: 3, atomRank: 1)
14+
15+
define void @f(ptr %p, i32 %a) local_unnamed_addr #0 !dbg !5 {
16+
entry:
17+
br label %for.body
18+
19+
for.cond.cleanup: ; preds = %for.body
20+
ret void
21+
22+
for.body: ; preds = %for.body, %entry
23+
%i = phi i32 [ 0, %entry ], [ %inc, %for.body ]
24+
%v = add i32 %i, %a, !dbg !11
25+
store i32 %v, ptr %p, align 4, !dbg !12
26+
%inc = add i32 %i, 1
27+
%cmp = icmp slt i32 %inc, 3
28+
br i1 %cmp, label %for.body, label %for.cond.cleanup
29+
}
30+
31+
declare i32 @bar(...) local_unnamed_addr
32+
33+
attributes #0 = { nounwind ssp uwtable }
34+
35+
!llvm.dbg.cu = !{!0}
36+
!llvm.debugify = !{!2, !3}
37+
!llvm.module.flags = !{!4}
38+
39+
!0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: "debugify", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug)
40+
!1 = !DIFile(filename: "/home/och/scratch/test.ll", directory: "/")
41+
!2 = !{i32 8}
42+
!3 = !{i32 0}
43+
!4 = !{i32 2, !"Debug Info Version", i32 3}
44+
!5 = distinct !DISubprogram(name: "f", linkageName: "f", scope: null, file: !1, line: 1, type: !6, scopeLine: 1, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0)
45+
!6 = !DISubroutineType(types: !7)
46+
!7 = !{}
47+
!11 = !DILocation(line: 4, column: 1, scope: !5, atomGroup: 1, atomRank: 2)
48+
!12 = !DILocation(line: 5, column: 1, scope: !5, atomGroup: 1, atomRank: 1)

0 commit comments

Comments
 (0)