Skip to content

Commit 266f6f2

Browse files
shiltianIanWood1
authored andcommitted
Revert "[StructurizeCFG] Refactor insertConditions. NFC. (llvm#115476)" (llvm#136370)
1 parent 100b6bf commit 266f6f2

File tree

2 files changed

+29
-18
lines changed

2 files changed

+29
-18
lines changed

llvm/lib/Transforms/Scalar/StructurizeCFG.cpp

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -612,25 +612,28 @@ void StructurizeCFG::insertConditions(bool Loops) {
612612
BasicBlock *SuccTrue = Term->getSuccessor(0);
613613
BasicBlock *SuccFalse = Term->getSuccessor(1);
614614

615-
BBPredicates &Preds = Loops ? LoopPreds[SuccFalse] : Predicates[SuccTrue];
615+
PhiInserter.Initialize(Boolean, "");
616+
PhiInserter.AddAvailableValue(Loops ? SuccFalse : Parent, Default);
616617

617-
if (Preds.size() == 1 && Preds.begin()->first == Parent) {
618-
auto &PI = Preds.begin()->second;
619-
Term->setCondition(PI.Pred);
620-
CondBranchWeights::setMetadata(*Term, PI.Weights);
621-
} else {
622-
PhiInserter.Initialize(Boolean, "");
623-
PhiInserter.AddAvailableValue(Loops ? SuccFalse : Parent, Default);
618+
BBPredicates &Preds = Loops ? LoopPreds[SuccFalse] : Predicates[SuccTrue];
624619

625-
NearestCommonDominator Dominator(DT);
626-
Dominator.addBlock(Parent);
620+
NearestCommonDominator Dominator(DT);
621+
Dominator.addBlock(Parent);
627622

628-
for (auto [BB, PI] : Preds) {
629-
assert(BB != Parent);
630-
PhiInserter.AddAvailableValue(BB, PI.Pred);
631-
Dominator.addAndRememberBlock(BB);
623+
PredInfo ParentInfo{nullptr, std::nullopt};
624+
for (auto [BB, PI] : Preds) {
625+
if (BB == Parent) {
626+
ParentInfo = PI;
627+
break;
632628
}
629+
PhiInserter.AddAvailableValue(BB, PI.Pred);
630+
Dominator.addAndRememberBlock(BB);
631+
}
633632

633+
if (ParentInfo.Pred) {
634+
Term->setCondition(ParentInfo.Pred);
635+
CondBranchWeights::setMetadata(*Term, ParentInfo.Weights);
636+
} else {
634637
if (!Dominator.resultIsRememberedBlock())
635638
PhiInserter.AddAvailableValue(Dominator.result(), Default);
636639

llvm/test/Transforms/StructurizeCFG/simple-structurizecfg-crash.ll

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
1-
; RUN: opt -S -passes=structurizecfg %s -o -
2-
; REQUIRES: asserts
3-
; XFAIL: *
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
2+
; RUN: opt -S -passes=structurizecfg %s -o - | FileCheck %s
43

54
; Issue tracking: https://github.com/llvm/llvm-project/issues/126534.
6-
; FIXME: This test is expected to crash. Generate checklines after the crash is fixed.
75

86
define void @foo() {
7+
; CHECK-LABEL: define void @foo() {
8+
; CHECK-NEXT: [[ENTRY:.*:]]
9+
; CHECK-NEXT: br label %[[COND_FALSE:.*]]
10+
; CHECK: [[COND_TRUE:.*]]:
11+
; CHECK-NEXT: br label %[[COND_END:.*]]
12+
; CHECK: [[COND_FALSE]]:
13+
; CHECK-NEXT: br i1 false, label %[[COND_TRUE]], label %[[COND_END]]
14+
; CHECK: [[COND_END]]:
15+
; CHECK-NEXT: ret void
16+
;
917
entry:
1018
br i1 false, label %cond.true, label %cond.false
1119

0 commit comments

Comments
 (0)