diff options
author | Sanjoy Das <sanjoy@playingwithpointers.com> | 2016-05-19 03:53:06 +0000 |
---|---|---|
committer | Sanjoy Das <sanjoy@playingwithpointers.com> | 2016-05-19 03:53:06 +0000 |
commit | 590614c1e19199a0e109dcef5a61128e5a62fede (patch) | |
tree | 177b3711b5acea68a1cbafc663f86658bcef37fd /llvm/lib | |
parent | 41133a3e961685ba0501631045fc6ef2d2a6a212 (diff) | |
download | bcm5719-llvm-590614c1e19199a0e109dcef5a61128e5a62fede.tar.gz bcm5719-llvm-590614c1e19199a0e109dcef5a61128e5a62fede.zip |
[ConstantRange] Add an getEquivalentICmp helper
Currently only its unit test uses it, but this will be used in a later
change to simplify some logic in the GuardWidening pass.
llvm-svn: 270018
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/IR/ConstantRange.cpp | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/llvm/lib/IR/ConstantRange.cpp b/llvm/lib/IR/ConstantRange.cpp index a2eb1517f57..309dfc33741 100644 --- a/llvm/lib/IR/ConstantRange.cpp +++ b/llvm/lib/IR/ConstantRange.cpp @@ -139,6 +139,32 @@ ConstantRange ConstantRange::makeExactICmpRegion(CmpInst::Predicate Pred, return makeAllowedICmpRegion(Pred, C); } +bool ConstantRange::getEquivalentICmp(CmpInst::Predicate &Pred, + APInt &RHS) const { + bool Success = false; + + if (isFullSet() || isEmptySet()) { + Pred = isEmptySet() ? CmpInst::ICMP_ULT : CmpInst::ICMP_UGE; + RHS = APInt(getBitWidth(), 0); + Success = true; + } else if (getLower().isMinSignedValue() || getLower().isMinValue()) { + Pred = + getLower().isMinSignedValue() ? CmpInst::ICMP_SLT : CmpInst::ICMP_ULT; + RHS = getUpper(); + Success = true; + } else if (getUpper().isMinSignedValue() || getUpper().isMinValue()) { + Pred = + getUpper().isMinSignedValue() ? CmpInst::ICMP_SGE : CmpInst::ICMP_UGE; + RHS = getLower(); + Success = true; + } + + assert((!Success || ConstantRange::makeExactICmpRegion(Pred, RHS) == *this) && + "Bad result!"); + + return Success; +} + ConstantRange ConstantRange::makeGuaranteedNoWrapRegion(Instruction::BinaryOps BinOp, const ConstantRange &Other, |