Skip to content

Commit fb161a8

Browse files
committed
[KeyInstr][JumpThreading] Remap atoms after threading
1 parent 328c735 commit fb161a8

File tree

3 files changed

+102
-7
lines changed

3 files changed

+102
-7
lines changed

llvm/lib/Transforms/Scalar/JumpThreading.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2469,6 +2469,7 @@ void JumpThreadingPass::threadEdge(BasicBlock *BB,
24692469
{DominatorTree::Insert, PredBB, NewBB},
24702470
{DominatorTree::Delete, PredBB, BB}});
24712471

2472+
remapSourceAtoms(ValueMapping, NewBB->begin(), NewBB->end());
24722473
updateSSA(BB, NewBB, ValueMapping);
24732474

24742475
// At this point, the IR is fully up to date and consistent. Do a quick scan

llvm/test/DebugInfo/KeyInstructions/Generic/jump-threading-2-bbs.ll

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,41 @@
22

33
;; Modified from llvm/test/Transforms/JumpThreading/thread-two-bbs.ll
44
;;
5-
;; JumpThreading duplicates bb.cond2 to thread through bb.file to bb.f2 or exit.
5+
;; JumpThreading duplicates bb.cond2 to thread through bb.file to bb.file,
6+
;; bb.f2 or exit.
67
;;
78
;; Check the duplicated instructions get remapped atom groups.
89

910
; CHECK: bb.cond2:
1011
; CHECK-NEXT: call void @f1()
1112
; CHECK-NEXT: %tobool1 = icmp eq i32 %cond2, 0, !dbg [[G1R2:!.*]]
12-
; CHECK-NEXT: br i1 %tobool1, label %exit, label %exit, !dbg [[G1R1:!.*]]
13+
; CHECK-NEXT: br i1 %tobool1, label %bb.file, label %exit, !dbg [[G1R1:!.*]]
1314

1415
; CHECK: bb.cond2.thread:
15-
; CHECK-NEXT: %tobool12 = icmp eq i32 %cond2, 0, !dbg [[G2R2:!.*]]
16-
; CHECK-NEXT: br i1 %tobool12, label %bb.f2, label %exit, !dbg [[G2R1:!.*]]
16+
; CHECK-NEXT: %tobool12 = icmp eq i32 %cond2, 0, !dbg [[G3R2:!.*]]
17+
; CHECK-NEXT: br i1 %tobool12, label %bb.f2, label %exit, !dbg [[G3R1:!.*]]
18+
19+
;; After the transform %ptr is null through bb.cond2 and @a through
20+
;; bb.cond2.thread. Thread bb.cond2.thread->bb.f2 through bb.file.
21+
;; Check the duplicated store gets a remapped atom group too.
22+
23+
; CHECK: bb.file:
24+
; CHECK-NEXT: %ptr3 = phi ptr [ null, %bb.cond2 ]
25+
; CHECK-NEXT: store ptr %ptr3, ptr %p, align 4, !dbg [[G2R1:!.*]]
26+
27+
; CHECK: bb.f2:
28+
; CHECK-NEXT: store ptr @a, ptr %p, align 4, !dbg [[G4R1:!.*]]
1729

1830
; CHECK: [[G1R2]] = !DILocation(line: 1, column: 1, scope: ![[#]], atomGroup: 1, atomRank: 2)
1931
; CHECK: [[G1R1]] = !DILocation(line: 1, column: 1, scope: ![[#]], atomGroup: 1, atomRank: 1)
20-
; CHECK: [[G2R2]] = !DILocation(line: 1, column: 1, scope: ![[#]], atomGroup: 2, atomRank: 2)
21-
; CHECK: [[G2R1]] = !DILocation(line: 1, column: 1, scope: ![[#]], atomGroup: 2, atomRank: 1)
32+
; CHECK: [[G3R2]] = !DILocation(line: 1, column: 1, scope: ![[#]], atomGroup: 3, atomRank: 2)
33+
; CHECK: [[G3R1]] = !DILocation(line: 1, column: 1, scope: ![[#]], atomGroup: 3, atomRank: 1)
34+
; CHECK: [[G2R1]] = !DILocation(line: 2, column: 1, scope: ![[#]], atomGroup: 2, atomRank: 1)
35+
; CHECK: [[G4R1]] = !DILocation(line: 2, column: 1, scope: ![[#]], atomGroup: 4, atomRank: 1)
2236

2337
@a = global i32 0, align 4
2438

25-
define void @foo(i32 %cond1, i32 %cond2) !dbg !5 {
39+
define void @foo(i32 %cond1, i32 %cond2, ptr %p) !dbg !5 {
2640
entry:
2741
%tobool = icmp eq i32 %cond1, 0
2842
br i1 %tobool, label %bb.cond2, label %bb.f1
@@ -37,6 +51,7 @@ bb.cond2: ; preds = %bb.f1, %entry
3751
br i1 %tobool1, label %bb.file, label %exit, !dbg !10
3852

3953
bb.file: ; preds = %bb.cond2
54+
store ptr %ptr, ptr %p, align 4, !dbg !11
4055
%cmp = icmp eq ptr %ptr, null
4156
br i1 %cmp, label %exit, label %bb.f2
4257

@@ -66,3 +81,4 @@ declare void @f2()
6681
!7 = !{}
6782
!9 = !DILocation(line: 1, column: 1, scope: !5, atomGroup: 1, atomRank: 2)
6883
!10 = !DILocation(line: 1, column: 1, scope: !5, atomGroup: 1, atomRank: 1)
84+
!11 = !DILocation(line: 2, column: 1, scope: !5, atomGroup: 2, atomRank: 1)
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
; RUN: opt %s --passes=jump-threading -S -o - -S | FileCheck %s
2+
3+
;; +-> T1 -+
4+
;; | v +-> T2
5+
;; Entry -+ Merge -+
6+
;; | ^ +-> F2
7+
;; +-> F1 -+
8+
;;
9+
;; Thread T1 -> T2 and F1 -> F2 through Merge.
10+
;;
11+
;; +-> T1
12+
;; |
13+
;; Entry -+
14+
;; |
15+
;; +-> F1
16+
;;
17+
;; Check the duplicated instructions atoms are remapped.
18+
19+
; CHECK: T2:
20+
; CHECK-NEXT: %v1 = call i32 @f1()
21+
; CHECK-NEXT: %C3 = add i32 %v1, 1, !dbg [[G2R2:!.*]]
22+
; CHECK-NEXT: store i32 %C3, ptr %p, align 4, !dbg [[G2R1:!.*]]
23+
24+
; CHECK: F2:
25+
; CHECK-NEXT: %v2 = call i32 @f2()
26+
; CHECK-NEXT: %C = add i32 %v2, 1, !dbg [[G1R2:!.*]]
27+
; CHECK-NEXT: store i32 %C, ptr %p, align 4, !dbg [[G1R1:!.*]]
28+
29+
; CHECK: [[G2R2]] = !DILocation(line: 8, column: 1, scope: ![[#]], atomGroup: 2, atomRank: 2)
30+
; CHECK: [[G2R1]] = !DILocation(line: 8, column: 1, scope: ![[#]], atomGroup: 2, atomRank: 1)
31+
; CHECK: [[G1R2]] = !DILocation(line: 8, column: 1, scope: ![[#]], atomGroup: 1, atomRank: 2)
32+
; CHECK: [[G1R1]] = !DILocation(line: 8, column: 1, scope: ![[#]], atomGroup: 1, atomRank: 1)
33+
34+
define i32 @test1(i1 %cond, ptr %p) !dbg !5 {
35+
br i1 %cond, label %T1, label %F1
36+
37+
T1: ; preds = %0
38+
%v1 = call i32 @f1()
39+
br label %Merge
40+
41+
F1: ; preds = %0
42+
%v2 = call i32 @f2()
43+
br label %Merge
44+
45+
Merge: ; preds = %F1, %T1
46+
%A = phi i1 [ true, %T1 ], [ false, %F1 ]
47+
%B = phi i32 [ %v1, %T1 ], [ %v2, %F1 ]
48+
%C = add i32 %B, 1, !dbg !8
49+
store i32 %C, ptr %p, align 4, !dbg !9
50+
br i1 %A, label %T2, label %F2
51+
52+
T2: ; preds = %Merge
53+
call void @f3()
54+
ret i32 %B
55+
56+
F2: ; preds = %Merge
57+
ret i32 %B
58+
}
59+
60+
declare i32 @f1()
61+
declare i32 @f2()
62+
declare void @f3()
63+
64+
!llvm.dbg.cu = !{!0}
65+
!llvm.debugify = !{!2, !3}
66+
!llvm.module.flags = !{!4}
67+
68+
!0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: "debugify", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug)
69+
!1 = !DIFile(filename: "test.ll", directory: "/")
70+
!2 = !{i32 12}
71+
!3 = !{i32 0}
72+
!4 = !{i32 2, !"Debug Info Version", i32 3}
73+
!5 = distinct !DISubprogram(name: "test1", linkageName: "test1", scope: null, file: !1, line: 1, type: !6, scopeLine: 1, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0)
74+
!6 = !DISubroutineType(types: !7)
75+
!7 = !{}
76+
!8 = !DILocation(line: 8, column: 1, scope: !5, atomGroup: 1, atomRank: 2)
77+
!9 = !DILocation(line: 8, column: 1, scope: !5, atomGroup: 1, atomRank: 1)
78+

0 commit comments

Comments
 (0)