forked from OSchip/llvm-project
[InstCombine] replace dyn_casts with matches; NFCI
Clean-up before changing this to allow folds for vectors. llvm-svn: 277538
This commit is contained in:
parent
f981e30b45
commit
ab50a93888
|
@ -2200,19 +2200,20 @@ Instruction *InstCombiner::foldICmpWithConstant(ICmpInst &ICI,
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Simplify icmp_eq and icmp_ne instructions with integer constant RHS.
|
/// Simplify icmp_eq and icmp_ne instructions with binary operator LHS and
|
||||||
Instruction *InstCombiner::foldICmpEqualityWithConstant(ICmpInst &ICI,
|
/// integer constant RHS.
|
||||||
Instruction *LHSI,
|
Instruction *InstCombiner::foldICmpEqualityWithConstant(ICmpInst &ICI) {
|
||||||
ConstantInt *RHS) {
|
// FIXME: If we use m_APInt() instead of m_ConstantInt(), it would enable
|
||||||
BinaryOperator *BO = dyn_cast<BinaryOperator>(LHSI);
|
// vector types with constant splat vectors to be optimized too.
|
||||||
if (!BO || !ICI.isEquality())
|
BinaryOperator *BO;
|
||||||
|
ConstantInt *RHS;
|
||||||
|
if (!ICI.isEquality() || !match(ICI.getOperand(0), m_BinOp(BO)) ||
|
||||||
|
!match(ICI.getOperand(1), m_ConstantInt(RHS)))
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
const APInt &RHSV = RHS->getValue();
|
const APInt &RHSV = RHS->getValue();
|
||||||
bool isICMP_NE = ICI.getPredicate() == ICmpInst::ICMP_NE;
|
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()) {
|
switch (BO->getOpcode()) {
|
||||||
case Instruction::SRem:
|
case Instruction::SRem:
|
||||||
// If we have a signed (X % (2^c)) == 0, turn it into an unsigned one.
|
// If we have a signed (X % (2^c)) == 0, turn it into an unsigned one.
|
||||||
|
@ -2304,7 +2305,7 @@ Instruction *InstCombiner::foldICmpEqualityWithConstant(ICmpInst &ICI,
|
||||||
// If we have ((X & C) == C), turn it into ((X & C) != 0).
|
// If we have ((X & C) == C), turn it into ((X & C) != 0).
|
||||||
if (RHS == BOC && RHSV.isPowerOf2())
|
if (RHS == BOC && RHSV.isPowerOf2())
|
||||||
return new ICmpInst(isICMP_NE ? ICmpInst::ICMP_EQ : ICmpInst::ICMP_NE,
|
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
|
// Don't perform the following transforms if the AND has multiple uses
|
||||||
if (!BO->hasOneUse())
|
if (!BO->hasOneUse())
|
||||||
|
@ -3647,13 +3648,13 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
|
||||||
// Since the RHS is a ConstantInt (CI), if the left hand side is an
|
// 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, see if that instruction also has constants so that the
|
||||||
// instruction can be folded into the icmp
|
// 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))
|
if (Instruction *Res = foldICmpWithConstant(I, LHSI, CI))
|
||||||
return Res;
|
return Res;
|
||||||
if (Instruction *Res = foldICmpEqualityWithConstant(I, LHSI, CI))
|
}
|
||||||
|
|
||||||
|
if (Instruction *Res = foldICmpEqualityWithConstant(I))
|
||||||
return Res;
|
return Res;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Instruction *Res = foldICmpIntrinsicWithConstant(I))
|
if (Instruction *Res = foldICmpIntrinsicWithConstant(I))
|
||||||
return Res;
|
return Res;
|
||||||
|
|
|
@ -583,8 +583,7 @@ private:
|
||||||
Instruction *foldICmpWithCastAndCast(ICmpInst &ICI);
|
Instruction *foldICmpWithCastAndCast(ICmpInst &ICI);
|
||||||
Instruction *foldICmpWithConstant(ICmpInst &ICI, Instruction *LHS,
|
Instruction *foldICmpWithConstant(ICmpInst &ICI, Instruction *LHS,
|
||||||
ConstantInt *RHS);
|
ConstantInt *RHS);
|
||||||
Instruction *foldICmpEqualityWithConstant(ICmpInst &ICI, Instruction *LHS,
|
Instruction *foldICmpEqualityWithConstant(ICmpInst &ICI);
|
||||||
ConstantInt *RHS);
|
|
||||||
Instruction *foldICmpIntrinsicWithConstant(ICmpInst &ICI);
|
Instruction *foldICmpIntrinsicWithConstant(ICmpInst &ICI);
|
||||||
|
|
||||||
Instruction *OptAndOp(Instruction *Op, ConstantInt *OpRHS,
|
Instruction *OptAndOp(Instruction *Op, ConstantInt *OpRHS,
|
||||||
|
|
Loading…
Reference in New Issue