diff options
author | Nick Lewycky <nicholas@mxc.ca> | 2011-03-01 08:15:50 +0000 |
---|---|---|
committer | Nick Lewycky <nicholas@mxc.ca> | 2011-03-01 08:15:50 +0000 |
commit | c9d20067cde7b2d0121e10f36ae24738ad827bba (patch) | |
tree | 03f2fbf9418aca917b61ae18fe6f6ec5f9958f09 /llvm/lib | |
parent | d95a81293b0366c63410e194572eafa6b4855a25 (diff) | |
download | bcm5719-llvm-c9d20067cde7b2d0121e10f36ae24738ad827bba.tar.gz bcm5719-llvm-c9d20067cde7b2d0121e10f36ae24738ad827bba.zip |
Optimize "icmp pred (urem X, Y), Y" --> true/false depending on pred. There's
more work to do here, "icmp ult (urem X, 10), 11" doesn't optimize away yet.
Fixes example 3 from PR9343!
llvm-svn: 126741
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/Analysis/InstructionSimplify.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp index 982dacb50bf..c23abb78089 100644 --- a/llvm/lib/Analysis/InstructionSimplify.cpp +++ b/llvm/lib/Analysis/InstructionSimplify.cpp @@ -1434,6 +1434,9 @@ static Value *SimplifyICmpInst(unsigned Predicate, Value *LHS, Value *RHS, return ConstantInt::getTrue(CI->getContext()); break; } + + // TODO: integer div and rem with constant RHS all produce values in a + // constant range. We should check whether the comparison is a tautology. } // Compare of cast, for example (zext X) != 0 -> X != 0 @@ -1644,6 +1647,21 @@ static Value *SimplifyICmpInst(unsigned Predicate, Value *LHS, Value *RHS, } } + if (LBO && match(LBO, m_URem(m_Value(), m_Specific(RHS)))) { + switch (Pred) { + default: + break; + case ICmpInst::ICMP_EQ: + case ICmpInst::ICMP_UGT: + case ICmpInst::ICMP_UGE: + return ConstantInt::getFalse(RHS->getContext()); + case ICmpInst::ICMP_NE: + case ICmpInst::ICMP_ULT: + case ICmpInst::ICMP_ULE: + return ConstantInt::getTrue(RHS->getContext()); + } + } + // If the comparison is with the result of a select instruction, check whether // comparing with either branch of the select always yields the same value. if (isa<SelectInst>(LHS) || isa<SelectInst>(RHS)) |