Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions llvm/lib/Transforms/Scalar/StructurizeCFG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -971,6 +971,10 @@ void StructurizeCFG::changeExit(RegionNode *Node, BasicBlock *NewExit,
SubRegion->replaceExit(NewExit);
} else {
BasicBlock *BB = Node->getNodeAs<BasicBlock>();
for (BasicBlock *Succ : successors(BB)) {
if (Succ != NewExit)
Predicates[Succ].erase(BB);
}
Comment on lines +974 to +977
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably should move this into killTerminator where the actual successor removal occurs

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does it mean that we indeed need to update Predicates here? I thought the no-update was on purpose.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What makes you think it's on purpose?

The predicates collects branch conditions used in the CFG, so it makes sense to me that you would need to adjust those when the CFG changes

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, alright. It has been sitting there for 10+ years so my first reaction is, probably it was designed in that way...

killTerminator(BB);
BranchInst *Br = BranchInst::Create(NewExit, BB);
Br->setDebugLoc(TermDL[BB]);
Expand Down
26 changes: 26 additions & 0 deletions llvm/test/Transforms/StructurizeCFG/simple-structurizecfg-crash.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
; RUN: opt -S -passes=structurizecfg %s -o - | FileCheck %s

define void @foo() {
; CHECK-LABEL: define void @foo() {
; CHECK-NEXT: [[ENTRY:.*:]]
; CHECK-NEXT: br label %[[COND_FALSE:.*]]
; CHECK: [[COND_TRUE:.*]]:
; CHECK-NEXT: br label %[[COND_END:.*]]
; CHECK: [[COND_FALSE]]:
; CHECK-NEXT: br i1 false, label %[[COND_TRUE]], label %[[COND_END]]
; CHECK: [[COND_END]]:
; CHECK-NEXT: ret void
;
entry:
br i1 false, label %cond.true, label %cond.false

cond.true: ; preds = %entry
br label %cond.end

cond.false: ; preds = %entry
br label %cond.end

cond.end: ; preds = %cond.false, %cond.true
ret void
}
Loading