Skip to content

Commit

Permalink
[DFAJumpThreading] Handle circular determinator (#78177)
Browse files Browse the repository at this point in the history
Fixes the buildbot failure in
#78134 (comment)
When we meet the path with single `determinator`, the determinator
actually takes itself as a predecessor. Thus, we need to let `Prev` be
the determinator when `PathBBs` has only one element.
  • Loading branch information
XChy authored Jan 16, 2024
1 parent 89cdd48 commit 2c0fc0f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
5 changes: 3 additions & 2 deletions llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -910,8 +910,9 @@ struct TransformDFA {
PathBBs.pop_front();

auto DetIt = llvm::find(PathBBs, Determinator);
auto Prev = std::prev(DetIt);
BasicBlock *PrevBB = *Prev;
// When there is only one BB in PathBBs, the determinator takes itself as a
// direct predecessor.
BasicBlock *PrevBB = PathBBs.size() == 1 ? *DetIt : *std::prev(DetIt);
for (auto BBIt = DetIt; BBIt != PathBBs.end(); BBIt++) {
BasicBlock *BB = *BBIt;
BlocksToClean.insert(BB);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,3 +267,38 @@ entry:
end:
ret void
}

define void @self-reference(i1 %c) {
; CHECK-LABEL: @self-reference(
; CHECK-NEXT: entry:
; CHECK-NEXT: br i1 [[C:%.*]], label [[DOTSPLIT_PREHEADER:%.*]], label [[DOTSPLIT_PREHEADER]]
; CHECK: .split.preheader:
; CHECK-NEXT: br label [[DOTSPLIT:%.*]]
; CHECK: .split:
; CHECK-NEXT: [[TMP0:%.*]] = phi i32 [ 0, [[DOTSPLIT_PREHEADER]] ]
; CHECK-NEXT: switch i32 [[TMP0]], label [[END:%.*]] [
; CHECK-NEXT: i32 -1, label [[END]]
; CHECK-NEXT: i32 0, label [[DOTSPLIT_JT4294967295:%.*]]
; CHECK-NEXT: ]
; CHECK: .split.jt4294967295:
; CHECK-NEXT: [[TMP1:%.*]] = phi i32 [ -1, [[DOTSPLIT]] ]
; CHECK-NEXT: br label [[END]]
; CHECK: end:
; CHECK-NEXT: ret void
;
entry:
br i1 %c, label %.split.preheader, label %.split.preheader

.split.preheader:
br label %.split

.split:
%0 = phi i32 [ 0, %.split.preheader ], [ -1, %.split ]
switch i32 %0, label %end [
i32 -1, label %end
i32 0, label %.split
]

end:
ret void
}

0 comments on commit 2c0fc0f

Please sign in to comment.