[llvm] [StructurizeCFG] Using phi as a placeholder to avoid constant crash (PR #127780)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 19 02:50:00 PST 2025
https://github.com/u4f3 created https://github.com/llvm/llvm-project/pull/127780
close #126534
>From b05914d2c30abc2f4bd896c7a8e7921834182c49 Mon Sep 17 00:00:00 2001
From: u4f3 <ricoafoat at gmail.com>
Date: Wed, 19 Feb 2025 18:38:17 +0800
Subject: [PATCH] [StructurizeCFG] Using phi as a placeholder to avoid constant
crash
---
llvm/lib/Transforms/Scalar/StructurizeCFG.cpp | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/llvm/lib/Transforms/Scalar/StructurizeCFG.cpp b/llvm/lib/Transforms/Scalar/StructurizeCFG.cpp
index b1f742b838f2a..2ff602c5880b3 100644
--- a/llvm/lib/Transforms/Scalar/StructurizeCFG.cpp
+++ b/llvm/lib/Transforms/Scalar/StructurizeCFG.cpp
@@ -278,8 +278,8 @@ class NearestCommonDominator {
class StructurizeCFG {
Type *Boolean;
- ConstantInt *BoolTrue;
- ConstantInt *BoolFalse;
+ Value *BoolTrue;
+ Value *BoolFalse;
Value *BoolPoison;
Function *Func;
@@ -1253,8 +1253,8 @@ void StructurizeCFG::init(Region *R) {
LLVMContext &Context = R->getEntry()->getContext();
Boolean = Type::getInt1Ty(Context);
- BoolTrue = ConstantInt::getTrue(Context);
- BoolFalse = ConstantInt::getFalse(Context);
+ BoolTrue = PHINode::Create(Boolean, 0);
+ BoolFalse = PHINode::Create(Boolean, 0);
BoolPoison = PoisonValue::get(Boolean);
this->UA = nullptr;
@@ -1330,6 +1330,9 @@ bool StructurizeCFG::run(Region *R, DominatorTree *DT) {
FlowSet.clear();
TermDL.clear();
+ BoolTrue->replaceAllUsesWith(ConstantInt::getTrue(Boolean));
+ BoolFalse->replaceAllUsesWith(ConstantInt::getFalse(Boolean));
+
return true;
}
More information about the llvm-commits
mailing list