[llvm] [SimplifyCFG] Simplify conditional branches on const icmp eq's (PR #73334)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 24 07:03:41 PST 2023
================
@@ -7325,6 +7333,18 @@ bool SimplifyCFGOpt::simplifyCondBranch(BranchInst *BI, IRBuilder<> &Builder) {
if (mergeConditionalStores(PBI, BI, DTU, DL, TTI))
return requestResimplify();
+ // Check if the condition is an equality between two constants. This can form
+ // due to other CFGSimplify steps, and may prevent further simplification if
+ // we don't deal with it here.
+ if (auto ICmp = dyn_cast<ICmpInst>(BI->getCondition()))
+ if (ICmp->getPredicate() == CmpInst::ICMP_EQ)
+ if (auto *LHS = dyn_cast<ConstantInt>(ICmp->getOperand(0)))
+ if (auto *RHS = dyn_cast<ConstantInt>(ICmp->getOperand(1))) {
----------------
nikic wrote:
Rather than implementing your own limited constant folding here, it would be better to call ConstantFoldCompareInstOperands.
https://github.com/llvm/llvm-project/pull/73334
More information about the llvm-commits
mailing list