[llvm] r278944 - [InstCombine] clean up foldICmpOrConstant(); NFCI
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 17 09:30:43 PDT 2016
Author: spatel
Date: Wed Aug 17 11:30:43 2016
New Revision: 278944
URL: http://llvm.org/viewvc/llvm-project?rev=278944&view=rev
Log:
[InstCombine] clean up foldICmpOrConstant(); NFCI
1. Change variable names
2. Use local variables to reduce code
3. Use ? instead of if/else
4. Use the APInt variable instead of 'RHS' so the removal of the FIXME code will be direct
Modified:
llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp?rev=278944&r1=278943&r2=278944&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp Wed Aug 17 11:30:43 2016
@@ -1879,40 +1879,38 @@ Instruction *InstCombiner::foldICmpAndCo
return nullptr;
}
-Instruction *InstCombiner::foldICmpOrConstant(ICmpInst &ICI, Instruction *LHSI,
- const APInt *RHSV) {
+/// Fold icmp (or X, Y), C.
+Instruction *InstCombiner::foldICmpOrConstant(ICmpInst &Cmp, Instruction *Or,
+ const APInt *C) {
// FIXME: This check restricts all folds under here to scalar types.
- ConstantInt *RHS = dyn_cast<ConstantInt>(ICI.getOperand(1));
+ ConstantInt *RHS = dyn_cast<ConstantInt>(Cmp.getOperand(1));
if (!RHS)
return nullptr;
- if (RHS->isOne()) {
+ ICmpInst::Predicate Pred = Cmp.getPredicate();
+ if (*C == 1) {
// icmp slt signum(V) 1 --> icmp slt V, 1
Value *V = nullptr;
- if (ICI.getPredicate() == ICmpInst::ICMP_SLT &&
- match(LHSI, m_Signum(m_Value(V))))
+ if (Pred == ICmpInst::ICMP_SLT && match(Or, m_Signum(m_Value(V))))
return new ICmpInst(ICmpInst::ICMP_SLT, V,
ConstantInt::get(V->getType(), 1));
}
- if (!ICI.isEquality() || !RHS->isNullValue() || !LHSI->hasOneUse())
+ if (!Cmp.isEquality() || *C != 0 || !Or->hasOneUse())
return nullptr;
Value *P, *Q;
- if (match(LHSI, m_Or(m_PtrToInt(m_Value(P)), m_PtrToInt(m_Value(Q))))) {
+ if (match(Or, m_Or(m_PtrToInt(m_Value(P)), m_PtrToInt(m_Value(Q))))) {
// Simplify icmp eq (or (ptrtoint P), (ptrtoint Q)), 0
// -> and (icmp eq P, null), (icmp eq Q, null).
- Value *ICIP = Builder->CreateICmp(ICI.getPredicate(), P,
- Constant::getNullValue(P->getType()));
- Value *ICIQ = Builder->CreateICmp(ICI.getPredicate(), Q,
- Constant::getNullValue(Q->getType()));
- Instruction *Op;
- if (ICI.getPredicate() == ICmpInst::ICMP_EQ)
- Op = BinaryOperator::CreateAnd(ICIP, ICIQ);
- else
- Op = BinaryOperator::CreateOr(ICIP, ICIQ);
- return Op;
+ Constant *NullVal = ConstantInt::getNullValue(P->getType());
+ Value *CmpP = Builder->CreateICmp(Pred, P, NullVal);
+ Value *CmpQ = Builder->CreateICmp(Pred, Q, NullVal);
+ auto LogicOpc = Pred == ICmpInst::Predicate::ICMP_EQ ? Instruction::And
+ : Instruction::Or;
+ return BinaryOperator::Create(LogicOpc, CmpP, CmpQ);
}
+
return nullptr;
}
More information about the llvm-commits
mailing list