/// information is sufficient to prove this comparison. Even for local
/// conditions, this can sometimes prove conditions instcombine can't by
/// exploiting range information.
-static bool processCmp(CmpInst *C, LazyValueInfo *LVI) {
- Value *Op0 = C->getOperand(0);
- Constant *Op1 = dyn_cast<Constant>(C->getOperand(1));
- if (!Op1) return false;
+static bool processCmp(CmpInst *Cmp, LazyValueInfo *LVI) {
+ Value *Op0 = Cmp->getOperand(0);
+ auto *C = dyn_cast<Constant>(Cmp->getOperand(1));
+ if (!C)
+ return false;
// As a policy choice, we choose not to waste compile time on anything where
// the comparison is testing local values. While LVI can sometimes reason
// the block local query for uses from terminator instructions, but that's
// handled in the code for each terminator.
auto *I = dyn_cast<Instruction>(Op0);
- if (I && I->getParent() == C->getParent())
+ if (I && I->getParent() == Cmp->getParent())
return false;
LazyValueInfo::Tristate Result =
- LVI->getPredicateAt(C->getPredicate(), Op0, Op1, C);
- if (Result == LazyValueInfo::Unknown) return false;
+ LVI->getPredicateAt(Cmp->getPredicate(), Op0, C, Cmp);
+ if (Result == LazyValueInfo::Unknown)
+ return false;
++NumCmps;
- if (Result == LazyValueInfo::True)
- C->replaceAllUsesWith(ConstantInt::getTrue(C->getContext()));
- else
- C->replaceAllUsesWith(ConstantInt::getFalse(C->getContext()));
- C->eraseFromParent();
-
+ Constant *TorF = ConstantInt::get(Type::getInt1Ty(Cmp->getContext()), Result);
+ Cmp->replaceAllUsesWith(TorF);
+ Cmp->eraseFromParent();
return true;
}
/// that cannot fire no matter what the incoming edge can safely be removed. If
/// a case fires on every incoming edge then the entire switch can be removed
/// and replaced with a branch to the case destination.
-static bool processSwitch(SwitchInst *SI, LazyValueInfo *LVI, DominatorTree *DT) {
+static bool processSwitch(SwitchInst *SI, LazyValueInfo *LVI,
+ DominatorTree *DT) {
DomTreeUpdater DTU(*DT, DomTreeUpdater::UpdateStrategy::Lazy);
Value *Cond = SI->getCondition();
BasicBlock *BB = SI->getParent();