mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-08-04 22:28:27 +00:00
InstSimplify: Optimize signed icmp of -(zext V)
Summary: We know that -(zext V) will always be <= zero, simplify signed icmps that have these. Uncovered using http://www.cs.utah.edu/~regehr/souper/ Reviewers: nicholas Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D3754 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@208809 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -2280,6 +2280,28 @@ static Value *SimplifyICmpInst(unsigned Predicate, Value *LHS, Value *RHS,
|
||||
}
|
||||
}
|
||||
|
||||
// 0 - (zext X) pred C
|
||||
if (!CmpInst::isUnsigned(Pred) && match(LHS, m_Neg(m_ZExt(m_Value())))) {
|
||||
if (ConstantInt *RHSC = dyn_cast<ConstantInt>(RHS)) {
|
||||
if (RHSC->getValue().isStrictlyPositive()) {
|
||||
if (Pred == ICmpInst::ICMP_SLT)
|
||||
return ConstantInt::getTrue(RHSC->getContext());
|
||||
if (Pred == ICmpInst::ICMP_SGE)
|
||||
return ConstantInt::getFalse(RHSC->getContext());
|
||||
if (Pred == ICmpInst::ICMP_EQ)
|
||||
return ConstantInt::getFalse(RHSC->getContext());
|
||||
if (Pred == ICmpInst::ICMP_NE)
|
||||
return ConstantInt::getTrue(RHSC->getContext());
|
||||
}
|
||||
if (RHSC->getValue().isNonNegative()) {
|
||||
if (Pred == ICmpInst::ICMP_SLE)
|
||||
return ConstantInt::getTrue(RHSC->getContext());
|
||||
if (Pred == ICmpInst::ICMP_SGT)
|
||||
return ConstantInt::getFalse(RHSC->getContext());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// icmp pred (urem X, Y), Y
|
||||
if (LBO && match(LBO, m_URem(m_Value(), m_Specific(RHS)))) {
|
||||
bool KnownNonNegative, KnownNegative;
|
||||
|
Reference in New Issue
Block a user