[llvm] f30a7df - [NFCI][SimplifyCFG] simplifyCondBranch(): assert that branch is non-tautological

Roman Lebedev via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 12 10:03:38 PDT 2021


Author: Roman Lebedev
Date: 2021-08-12T20:03:09+03:00
New Revision: f30a7dff8a5b32919951dcbf92e4a9d56c4679ff

URL: https://github.com/llvm/llvm-project/commit/f30a7dff8a5b32919951dcbf92e4a9d56c4679ff
DIFF: https://github.com/llvm/llvm-project/commit/f30a7dff8a5b32919951dcbf92e4a9d56c4679ff.diff

LOG: [NFCI][SimplifyCFG] simplifyCondBranch(): assert that branch is non-tautological

We really shouldn't deal with a conditional branch that can be trivially
constant-folded into an unconditional branch.

Indeed, barring failure to trigger BB reprocessing, that should be true,
so let's assert as much, and hope the assertion never fires.
If it does, we have a bug to fix.

Added: 
    

Modified: 
    llvm/lib/Transforms/Utils/SimplifyCFG.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
index 482316c6111f..5cd7cd71d264 100644
--- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -6394,6 +6394,11 @@ static BasicBlock *allPredecessorsComeFromSameSource(BasicBlock *BB) {
 }
 
 bool SimplifyCFGOpt::simplifyCondBranch(BranchInst *BI, IRBuilder<> &Builder) {
+  assert(
+      !isa<ConstantInt>(BI->getCondition()) &&
+      BI->getSuccessor(0) != BI->getSuccessor(1) &&
+      "Tautological conditional branch should have been eliminated already.");
+
   BasicBlock *BB = BI->getParent();
   if (!Options.SimplifyCondBranch)
     return false;


        


More information about the llvm-commits mailing list