Skip to content

Commit b05914d

Browse files
committed
[StructurizeCFG] Using phi as a placeholder to avoid constant crash
1 parent b6be53d commit b05914d

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

llvm/lib/Transforms/Scalar/StructurizeCFG.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -278,8 +278,8 @@ class NearestCommonDominator {
278278

279279
class StructurizeCFG {
280280
Type *Boolean;
281-
ConstantInt *BoolTrue;
282-
ConstantInt *BoolFalse;
281+
Value *BoolTrue;
282+
Value *BoolFalse;
283283
Value *BoolPoison;
284284

285285
Function *Func;
@@ -1253,8 +1253,8 @@ void StructurizeCFG::init(Region *R) {
12531253
LLVMContext &Context = R->getEntry()->getContext();
12541254

12551255
Boolean = Type::getInt1Ty(Context);
1256-
BoolTrue = ConstantInt::getTrue(Context);
1257-
BoolFalse = ConstantInt::getFalse(Context);
1256+
BoolTrue = PHINode::Create(Boolean, 0);
1257+
BoolFalse = PHINode::Create(Boolean, 0);
12581258
BoolPoison = PoisonValue::get(Boolean);
12591259

12601260
this->UA = nullptr;
@@ -1330,6 +1330,9 @@ bool StructurizeCFG::run(Region *R, DominatorTree *DT) {
13301330
FlowSet.clear();
13311331
TermDL.clear();
13321332

1333+
BoolTrue->replaceAllUsesWith(ConstantInt::getTrue(Boolean));
1334+
BoolFalse->replaceAllUsesWith(ConstantInt::getFalse(Boolean));
1335+
13331336
return true;
13341337
}
13351338

0 commit comments

Comments
 (0)