diff options
| author | Nick Lewycky <nicholas@mxc.ca> | 2008-01-28 03:48:02 +0000 |
|---|---|---|
| committer | Nick Lewycky <nicholas@mxc.ca> | 2008-01-28 03:48:02 +0000 |
| commit | 8ea81e8ba46486f512dd60d8334d5495e450655b (patch) | |
| tree | 7f5d3b490adea3f0f7c5cd7298b6b30a52dbb8cb /llvm/lib | |
| parent | aeb6b30f64ff48cd4a03e5a928d2824801dde174 (diff) | |
| download | bcm5719-llvm-8ea81e8ba46486f512dd60d8334d5495e450655b.tar.gz bcm5719-llvm-8ea81e8ba46486f512dd60d8334d5495e450655b.zip | |
Handle some more combinations of extend and icmp. Fixes PR1940.
llvm-svn: 46431
Diffstat (limited to 'llvm/lib')
| -rw-r--r-- | llvm/lib/Transforms/Scalar/InstructionCombining.cpp | 20 | ||||
| -rw-r--r-- | llvm/lib/VMCore/Instructions.cpp | 13 |
2 files changed, 25 insertions, 8 deletions
diff --git a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp index 5ba48572a5d..e56b5599717 100644 --- a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp @@ -5820,18 +5820,22 @@ Instruction *InstCombiner::visitICmpInstWithCastAndCast(ICmpInst &ICI) { if (RHSCIOp->getType() != LHSCIOp->getType()) return 0; - // If the signedness of the two compares doesn't agree (i.e. one is a sext + // If the signedness of the two casts doesn't agree (i.e. one is a sext // and the other is a zext), then we can't handle this. if (CI->getOpcode() != LHSCI->getOpcode()) return 0; - // Likewise, if the signedness of the [sz]exts and the compare don't match, - // then we can't handle this. - if (isSignedExt != isSignedCmp && !ICI.isEquality()) - return 0; - - // Okay, just insert a compare of the reduced operands now! - return new ICmpInst(ICI.getPredicate(), LHSCIOp, RHSCIOp); + // Deal with equality cases early. + if (ICI.isEquality()) + return new ICmpInst(ICI.getPredicate(), LHSCIOp, RHSCIOp); + + // A signed comparison of sign extended values simplifies into a + // signed comparison. + if (isSignedCmp && isSignedExt) + return new ICmpInst(ICI.getPredicate(), LHSCIOp, RHSCIOp); + + // The other three cases all fold into an unsigned comparison. + return new ICmpInst(ICI.getUnsignedPredicate(), LHSCIOp, RHSCIOp); } // If we aren't dealing with a constant on the RHS, exit early diff --git a/llvm/lib/VMCore/Instructions.cpp b/llvm/lib/VMCore/Instructions.cpp index 156eff169c1..b945a5a0dd7 100644 --- a/llvm/lib/VMCore/Instructions.cpp +++ b/llvm/lib/VMCore/Instructions.cpp @@ -2429,6 +2429,19 @@ ICmpInst::Predicate ICmpInst::getSignedPredicate(Predicate pred) { } } +ICmpInst::Predicate ICmpInst::getUnsignedPredicate(Predicate pred) { + switch (pred) { + default: assert(! "Unknown icmp predicate!"); + case ICMP_EQ: case ICMP_NE: + case ICMP_UGT: case ICMP_ULT: case ICMP_UGE: case ICMP_ULE: + return pred; + case ICMP_SGT: return ICMP_UGT; + case ICMP_SLT: return ICMP_ULT; + case ICMP_SGE: return ICMP_UGE; + case ICMP_SLE: return ICMP_ULE; + } +} + bool ICmpInst::isSignedPredicate(Predicate pred) { switch (pred) { default: assert(! "Unknown icmp predicate!"); |

