[llvm] [SimplifyCFG] Check whether the previous condition is true before making assume (PR #105986)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Aug 25 06:18:14 PDT 2024
https://github.com/GkvJwa created https://github.com/llvm/llvm-project/pull/105986
Fixes #105985
>From 11686c640dbecfa51447b5c93460f007fe90ffa1 Mon Sep 17 00:00:00 2001
From: GkvJwa <gkvjwa at gmail.com>
Date: Sun, 25 Aug 2024 21:16:12 +0800
Subject: [PATCH] [SimplifyCFG] Check whether the previous condition is true
before making assume
---
llvm/lib/Transforms/Utils/SimplifyCFG.cpp | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
index da4d57f808e9bf..32f76cfc5818d3 100644
--- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -7852,6 +7852,15 @@ static bool removeUndefIntroducingPredecessor(BasicBlock *BB,
Instruction *T = Predecessor->getTerminator();
IRBuilder<> Builder(T);
if (BranchInst *BI = dyn_cast<BranchInst>(T)) {
+ // Prevent multiple conditions cases
+ if (dyn_cast<CmpInst>(BI->getCondition()) &&
+ !pred_empty(Predecessor)) {
+ BranchInst *Pred_BI = dyn_cast<BranchInst>(
+ (*pred_begin(Predecessor))->getTerminator());
+ if (Pred_BI && dyn_cast<CmpInst>(BI->getCondition())) {
+ continue;
+ }
+ }
BB->removePredecessor(Predecessor);
// Turn unconditional branches into unreachables and remove the dead
// destination from conditional branches.
More information about the llvm-commits
mailing list