[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 08:36:35 PDT 2024
https://github.com/GkvJwa updated https://github.com/llvm/llvm-project/pull/105986
>From ef85b6718b84aeefea28301c0e2a338317ed5625 Mon Sep 17 00:00:00 2001
From: GkvJwa <gkvjwa at gmail.com>
Date: Sun, 25 Aug 2024 23:36:11 +0800
Subject: [PATCH] [SimplifyCFG] Check whether the previous condition is true
before making assume
---
llvm/lib/Transforms/Utils/SimplifyCFG.cpp | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
index da4d57f808e9bf..33556628d7a7e3 100644
--- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -7852,6 +7852,16 @@ static bool removeUndefIntroducingPredecessor(BasicBlock *BB,
Instruction *T = Predecessor->getTerminator();
IRBuilder<> Builder(T);
if (BranchInst *BI = dyn_cast<BranchInst>(T)) {
+ // Prevent more complex conditionals
+ if (BI->isConditional() && dyn_cast<CmpInst>(BI->getCondition()) &&
+ !pred_empty(Predecessor)) {
+ BranchInst *Pred_BI = dyn_cast<BranchInst>(
+ (*pred_begin(Predecessor))->getTerminator());
+ if (Pred_BI && BI->isConditional() &&
+ 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