[llvm] r277538 - [InstCombine] replace dyn_casts with matches; NFCI
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 2 15:38:33 PDT 2016
Author: spatel
Date: Tue Aug 2 17:38:33 2016
New Revision: 277538
URL: http://llvm.org/viewvc/llvm-project?rev=277538&view=rev
Log:
[InstCombine] replace dyn_casts with matches; NFCI
Clean-up before changing this to allow folds for vectors.
Modified:
llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp
llvm/trunk/lib/Transforms/InstCombine/InstCombineInternal.h
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp?rev=277538&r1=277537&r2=277538&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp Tue Aug 2 17:38:33 2016
@@ -2200,19 +2200,20 @@ Instruction *InstCombiner::foldICmpWithC
return nullptr;
}
-/// Simplify icmp_eq and icmp_ne instructions with integer constant RHS.
-Instruction *InstCombiner::foldICmpEqualityWithConstant(ICmpInst &ICI,
- Instruction *LHSI,
- ConstantInt *RHS) {
- BinaryOperator *BO = dyn_cast<BinaryOperator>(LHSI);
- if (!BO || !ICI.isEquality())
+/// Simplify icmp_eq and icmp_ne instructions with binary operator LHS and
+/// integer constant RHS.
+Instruction *InstCombiner::foldICmpEqualityWithConstant(ICmpInst &ICI) {
+ // FIXME: If we use m_APInt() instead of m_ConstantInt(), it would enable
+ // vector types with constant splat vectors to be optimized too.
+ BinaryOperator *BO;
+ ConstantInt *RHS;
+ if (!ICI.isEquality() || !match(ICI.getOperand(0), m_BinOp(BO)) ||
+ !match(ICI.getOperand(1), m_ConstantInt(RHS)))
return nullptr;
const APInt &RHSV = RHS->getValue();
bool isICMP_NE = ICI.getPredicate() == ICmpInst::ICMP_NE;
- // If the first operand is (add|sub|and|or|xor|rem) with a constant, and
- // the second operand is a constant, simplify a bit.
switch (BO->getOpcode()) {
case Instruction::SRem:
// If we have a signed (X % (2^c)) == 0, turn it into an unsigned one.
@@ -2304,7 +2305,7 @@ Instruction *InstCombiner::foldICmpEqual
// If we have ((X & C) == C), turn it into ((X & C) != 0).
if (RHS == BOC && RHSV.isPowerOf2())
return new ICmpInst(isICMP_NE ? ICmpInst::ICMP_EQ : ICmpInst::ICMP_NE,
- LHSI, Constant::getNullValue(RHS->getType()));
+ BO, Constant::getNullValue(RHS->getType()));
// Don't perform the following transforms if the AND has multiple uses
if (!BO->hasOneUse())
@@ -3647,14 +3648,14 @@ Instruction *InstCombiner::visitICmpInst
// Since the RHS is a ConstantInt (CI), if the left hand side is an
// instruction, see if that instruction also has constants so that the
// instruction can be folded into the icmp
- if (Instruction *LHSI = dyn_cast<Instruction>(Op0)) {
+ if (Instruction *LHSI = dyn_cast<Instruction>(Op0))
if (Instruction *Res = foldICmpWithConstant(I, LHSI, CI))
return Res;
- if (Instruction *Res = foldICmpEqualityWithConstant(I, LHSI, CI))
- return Res;
- }
}
+ if (Instruction *Res = foldICmpEqualityWithConstant(I))
+ return Res;
+
if (Instruction *Res = foldICmpIntrinsicWithConstant(I))
return Res;
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineInternal.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineInternal.h?rev=277538&r1=277537&r2=277538&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineInternal.h (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineInternal.h Tue Aug 2 17:38:33 2016
@@ -583,8 +583,7 @@ private:
Instruction *foldICmpWithCastAndCast(ICmpInst &ICI);
Instruction *foldICmpWithConstant(ICmpInst &ICI, Instruction *LHS,
ConstantInt *RHS);
- Instruction *foldICmpEqualityWithConstant(ICmpInst &ICI, Instruction *LHS,
- ConstantInt *RHS);
+ Instruction *foldICmpEqualityWithConstant(ICmpInst &ICI);
Instruction *foldICmpIntrinsicWithConstant(ICmpInst &ICI);
Instruction *OptAndOp(Instruction *Op, ConstantInt *OpRHS,
More information about the llvm-commits
mailing list