[llvm] [SimplifyCFG] Simplify nested branches (PR #97067)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 28 08:54:27 PDT 2024
================
@@ -7468,6 +7468,91 @@ bool SimplifyCFGOpt::simplifyCondBranch(BranchInst *BI, IRBuilder<> &Builder) {
if (mergeConditionalStores(PBI, BI, DTU, DL, TTI))
return requestResimplify();
+ {
+ // Fold the following pattern:
+ // bb0:
+ // br i1 %cond1, label %bb1, label %bb2
+ // bb1:
+ // br i1 %cond2, label %bb3, label %bb4
+ // bb2:
+ // br i1 %cond2, label %bb4, label %bb3
+ // bb3:
+ // ...
+ // bb4:
+ // ...
+ // into
+ // bb0:
+ // %cond = xor i1 %cond1, %cond2
+ // br i1 %cond, label %bb4, label %bb3
+ // bb3:
+ // ...
+ // bb4:
+ // ...
+ // NOTE: %cond2 always dominates the terminator of bb0.
+
+ BasicBlock *BB1 = BI->getSuccessor(0);
+ BasicBlock *BB2 = BI->getSuccessor(1);
+ auto IsSimpleSuccessor = [BB](BasicBlock *Succ, BranchInst *&SuccBI) {
+ if (Succ == BB)
+ return false;
+ if (Succ->sizeWithoutDebug() > 1)
----------------
dtcxzyw wrote:
Compile-time impact looks bad :( I will fix this later.
https://llvm-compile-time-tracker.com/compare.php?from=ffc27c851d814c9ee92b2fdc597b7fb5a00f6d89&to=f65104016387813b5ceb2c99b17e06dcd1c51f8d&stat=instructions:u
https://github.com/llvm/llvm-project/pull/97067
More information about the llvm-commits
mailing list