[PATCH] D19073: [ValueTracking] Improve isImpliedCondition for conditions with matching LHS operands and Immediate RHS operands.
Haicheng Wu via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 13 14:40:32 PDT 2016
haicheng added a subscriber: haicheng.
haicheng added a comment.
Hi Chad,
I think LazyValueInfo can figure out the branch direction in your test cases and then JumpThreading can optimize the CFG.
The related JumpThreading code is
JumpThreading.cpp
bool JumpThreading::ProcessBlock(BasicBlock *BB)
if (CmpInst *CondCmp = dyn_cast<CmpInst>(CondInst)) {
// If we're branching on a conditional, LVI might be able to determine
// it's value at the branch instruction. We only handle comparisons
// against a constant at this time.
// TODO: This should be extended to handle switches as well.
BranchInst *CondBr = dyn_cast<BranchInst>(BB->getTerminator());
Constant *CondConst = dyn_cast<Constant>(CondCmp->getOperand(1));
if (CondBr && CondConst && CondBr->isConditional()) {
LazyValueInfo::Tristate Ret =
LVI->getPredicateAt(CondCmp->getPredicate(), CondCmp->getOperand(0),
CondConst, CondBr);
if (Ret != LazyValueInfo::Unknown) {
unsigned ToRemove = Ret == LazyValueInfo::True ? 1 : 0;
unsigned ToKeep = Ret == LazyValueInfo::True ? 0 : 1;
CondBr->getSuccessor(ToRemove)->removePredecessor(BB, true);
BranchInst::Create(CondBr->getSuccessor(ToKeep), CondBr);
CondBr->eraseFromParent();
if (CondCmp->use_empty())
CondCmp->eraseFromParent();
else if (CondCmp->getParent() == BB) {
// If the fact we just learned is true for all uses of the
// condition, replace it with a constant value
auto *CI = Ret == LazyValueInfo::True ?
ConstantInt::getTrue(CondCmp->getType()) :
ConstantInt::getFalse(CondCmp->getType());
CondCmp->replaceAllUsesWith(CI);
CondCmp->eraseFromParent();
}
return true;
}
}
if (CondBr && CondConst && TryToUnfoldSelect(CondCmp, BB))
return true;
}
Best,
Haicheng
http://reviews.llvm.org/D19073
More information about the llvm-commits
mailing list