[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:51:00 PST 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-transforms

Author: None (u4f3)

<details>
<summary>Changes</summary>

close #<!-- -->126534 

---
Full diff: https://github.com/llvm/llvm-project/pull/127780.diff


1 Files Affected:

- (modified) llvm/lib/Transforms/Scalar/StructurizeCFG.cpp (+7-4) 


``````````diff
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;
 }
 

``````````

</details>


https://github.com/llvm/llvm-project/pull/127780


More information about the llvm-commits mailing list