[llvm] [InstCombine] Replace all dominated uses of condition with constants (PR #105510)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 26 14:00:38 PDT 2024
================
@@ -3705,6 +3705,20 @@ Instruction *InstCombinerImpl::visitBranchInst(BranchInst &BI) {
return nullptr;
}
+ // Replace all dominated uses of the condition with true/false
+ if (BI.getSuccessor(0) != BI.getSuccessor(1)) {
+ for (auto &U : make_early_inc_range(Cond->uses())) {
+ BasicBlockEdge Edge0(BI.getParent(), BI.getSuccessor(0));
+ if (DT.dominates(Edge0, U)) {
+ replaceUse(U, ConstantInt::getTrue(Cond->getType()));
+ continue;
+ }
+ BasicBlockEdge Edge1(BI.getParent(), BI.getSuccessor(1));
+ if (DT.dominates(Edge1, U))
+ replaceUse(U, ConstantInt::getFalse(Cond->getType()));
+ }
+ }
+
----------------
goldsteinn wrote:
Can we do the same thing with switches?
https://github.com/llvm/llvm-project/pull/105510
More information about the llvm-commits
mailing list