From 8242c82de4c0544c33e809a2b42e7885f2b7f48e Mon Sep 17 00:00:00 2001 From: Sanjay Patel Date: Thu, 29 Nov 2018 14:41:21 +0000 Subject: [PATCH] [CVP] tidy processCmp(); NFC 1. The variables were confusing: 'C' typically refers to a constant, but here it was the Cmp. 2. Formatting violations. 3. Simplify code to return true/false constant. llvm-svn: 347868 --- .../Scalar/CorrelatedValuePropagation.cpp | 28 +++++++++++----------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp b/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp index 826df6c..d010570 100644 --- a/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp +++ b/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp @@ -273,10 +273,11 @@ static bool processMemAccess(Instruction *I, LazyValueInfo *LVI) { /// 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(C->getOperand(1)); - if (!Op1) return false; +static bool processCmp(CmpInst *Cmp, LazyValueInfo *LVI) { + Value *Op0 = Cmp->getOperand(0); + auto *C = dyn_cast(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 @@ -284,20 +285,18 @@ static bool processCmp(CmpInst *C, LazyValueInfo *LVI) { // the block local query for uses from terminator instructions, but that's // handled in the code for each terminator. auto *I = dyn_cast(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; } @@ -308,7 +307,8 @@ static bool processCmp(CmpInst *C, LazyValueInfo *LVI) { /// 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(); -- 2.7.4