[llvm] [SimplifyCFG] Simplify conditional branches on const icmp eq's (PR #73334)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 24 07:30:04 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))) {
----------------
yonillasky wrote:
I was only trying to deal with the pattern that SimplifyCFG creates for itself - not general constant folding. But, point taken...
Anyway - need to decide if I leave it here or this logic needs to move to where PHIs are simplified...
https://github.com/llvm/llvm-project/pull/73334
More information about the llvm-commits
mailing list