Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a061998

Browse filesBrowse files
authored
[KeyInstr][JumpThreading] Remap atoms in blocks duplicated for threading (#133486)
1 parent 1ee9576 commit a061998
Copy full SHA for a061998

File tree

Expand file treeCollapse file tree

2 files changed

+83
-0
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+83
-0
lines changed

‎llvm/lib/Transforms/Scalar/JumpThreading.cpp

Copy file name to clipboardExpand all lines: llvm/lib/Transforms/Scalar/JumpThreading.cpp
+15Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2011,6 +2011,14 @@ void JumpThreadingPass::updateSSA(BasicBlock *BB, BasicBlock *NewBB,
20112011
}
20122012
}
20132013

2014+
static void remapSourceAtoms(ValueToValueMapTy &VM, BasicBlock::iterator Begin,
2015+
BasicBlock::iterator End) {
2016+
if (VM.AtomMap.empty())
2017+
return;
2018+
for (auto It = Begin; It != End; ++It)
2019+
RemapSourceAtom(&*It, VM);
2020+
}
2021+
20142022
/// Clone instructions in range [BI, BE) to NewBB. For PHI nodes, we only clone
20152023
/// arguments that come from PredBB. Return the map from the variables in the
20162024
/// source basic block to the variables in the newly created basic block.
@@ -2075,6 +2083,8 @@ void JumpThreadingPass::cloneInstructions(ValueToValueMapTy &ValueMapping,
20752083
PHINode *NewPN = PHINode::Create(PN->getType(), 1, PN->getName(), NewBB);
20762084
NewPN->addIncoming(PN->getIncomingValueForBlock(PredBB), PredBB);
20772085
ValueMapping[PN] = NewPN;
2086+
if (const DebugLoc &DL = PN->getDebugLoc())
2087+
mapAtomInstance(DL, ValueMapping);
20782088
}
20792089

20802090
// Clone noalias scope declarations in the threaded block. When threading a
@@ -2103,6 +2113,8 @@ void JumpThreadingPass::cloneInstructions(ValueToValueMapTy &ValueMapping,
21032113
adaptNoAliasScopes(New, ClonedScopes, Context);
21042114

21052115
CloneAndRemapDbgInfo(New, &*BI);
2116+
if (const DebugLoc &DL = New->getDebugLoc())
2117+
mapAtomInstance(DL, ValueMapping);
21062118

21072119
if (RetargetDbgValueIfPossible(New))
21082120
continue;
@@ -2330,6 +2342,9 @@ void JumpThreadingPass::threadThroughTwoBasicBlocks(BasicBlock *PredPredBB,
23302342
{DominatorTree::Insert, PredPredBB, NewBB},
23312343
{DominatorTree::Delete, PredPredBB, PredBB}});
23322344

2345+
// Remap source location atoms beacuse we're duplicating control flow.
2346+
remapSourceAtoms(ValueMapping, NewBB->begin(), NewBB->end());
2347+
23332348
updateSSA(PredBB, NewBB, ValueMapping);
23342349

23352350
// Clean up things like PHI nodes with single operands, dead instructions,
+68Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
; RUN: opt -S -passes=jump-threading,verify %s | FileCheck %s
2+
3+
;; Modified from llvm/test/Transforms/JumpThreading/thread-two-bbs.ll
4+
;;
5+
;; JumpThreading duplicates bb.cond2 to thread through bb.file to bb.f2 or exit.
6+
;;
7+
;; Check the duplicated instructions get remapped atom groups.
8+
9+
; CHECK: bb.cond2:
10+
; CHECK-NEXT: call void @f1()
11+
; CHECK-NEXT: %tobool1 = icmp eq i32 %cond2, 0, !dbg [[G1R2:!.*]]
12+
; CHECK-NEXT: br i1 %tobool1, label %exit, label %exit, !dbg [[G1R1:!.*]]
13+
14+
; 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:!.*]]
17+
18+
; CHECK: [[G1R2]] = !DILocation(line: 1, column: 1, scope: ![[#]], atomGroup: 1, atomRank: 2)
19+
; 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)
22+
23+
@a = global i32 0, align 4
24+
25+
define void @foo(i32 %cond1, i32 %cond2) !dbg !5 {
26+
entry:
27+
%tobool = icmp eq i32 %cond1, 0
28+
br i1 %tobool, label %bb.cond2, label %bb.f1
29+
30+
bb.f1: ; preds = %entry
31+
call void @f1()
32+
br label %bb.cond2
33+
34+
bb.cond2: ; preds = %bb.f1, %entry
35+
%ptr = phi ptr [ null, %bb.f1 ], [ @a, %entry ]
36+
%tobool1 = icmp eq i32 %cond2, 0, !dbg !9
37+
br i1 %tobool1, label %bb.file, label %exit, !dbg !10
38+
39+
bb.file: ; preds = %bb.cond2
40+
%cmp = icmp eq ptr %ptr, null
41+
br i1 %cmp, label %exit, label %bb.f2
42+
43+
bb.f2: ; preds = %bb.file
44+
call void @f2()
45+
br label %exit
46+
47+
exit: ; preds = %bb.f2, %bb.file, %bb.cond2
48+
ret void
49+
}
50+
51+
declare void @f1()
52+
53+
declare void @f2()
54+
55+
!llvm.dbg.cu = !{!0}
56+
!llvm.debugify = !{!2, !3}
57+
!llvm.module.flags = !{!4}
58+
59+
!0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: "debugify", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug)
60+
!1 = !DIFile(filename: "<stdin>", directory: "/")
61+
!2 = !{i32 16}
62+
!3 = !{i32 0}
63+
!4 = !{i32 2, !"Debug Info Version", i32 3}
64+
!5 = distinct !DISubprogram(name: "foo", linkageName: "foo", scope: null, file: !1, line: 1, type: !6, scopeLine: 1, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0)
65+
!6 = !DISubroutineType(types: !7)
66+
!7 = !{}
67+
!9 = !DILocation(line: 1, column: 1, scope: !5, atomGroup: 1, atomRank: 2)
68+
!10 = !DILocation(line: 1, column: 1, scope: !5, atomGroup: 1, atomRank: 1)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.