diff options
author | Nikita Popov <npopov@redhat.com> | 2024-07-03 15:51:39 +0200 |
---|---|---|
committer | Nikita Popov <npopov@redhat.com> | 2024-07-03 18:10:22 +0200 |
commit | 3ab2247d10673419609333a33bca0eca8a56bf3d (patch) | |
tree | 913ca6656873d375b9f73320958584149b61d020 /llvm/lib/IR/ConstantRange.cpp | |
parent | f057130b169fe551b1fec6633fadba26ef19bcdd (diff) | |
download | llvm-3ab2247d10673419609333a33bca0eca8a56bf3d.zip llvm-3ab2247d10673419609333a33bca0eca8a56bf3d.tar.gz llvm-3ab2247d10673419609333a33bca0eca8a56bf3d.tar.bz2 |
[ConstantRange] Optimize icmp() implementation (NFC)
These are pretty hot code paths, so provide direct implementations
for them, instead of going through makeSatisfyingICmpRegion().
Diffstat (limited to 'llvm/lib/IR/ConstantRange.cpp')
-rw-r--r-- | llvm/lib/IR/ConstantRange.cpp | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/llvm/lib/IR/ConstantRange.cpp b/llvm/lib/IR/ConstantRange.cpp index 50de975..0ead677 100644 --- a/llvm/lib/IR/ConstantRange.cpp +++ b/llvm/lib/IR/ConstantRange.cpp @@ -241,7 +241,36 @@ bool ConstantRange::getEquivalentICmp(CmpInst::Predicate &Pred, bool ConstantRange::icmp(CmpInst::Predicate Pred, const ConstantRange &Other) const { - return makeSatisfyingICmpRegion(Pred, Other).contains(*this); + if (isEmptySet() || Other.isEmptySet()) + return true; + + switch (Pred) { + case CmpInst::ICMP_EQ: + if (const APInt *L = getSingleElement()) + if (const APInt *R = Other.getSingleElement()) + return *L == *R; + return false; + case CmpInst::ICMP_NE: + return inverse().contains(Other); + case CmpInst::ICMP_ULT: + return getUnsignedMax().ult(Other.getUnsignedMin()); + case CmpInst::ICMP_ULE: + return getUnsignedMax().ule(Other.getUnsignedMin()); + case CmpInst::ICMP_UGT: + return getUnsignedMin().ugt(Other.getUnsignedMax()); + case CmpInst::ICMP_UGE: + return getUnsignedMin().uge(Other.getUnsignedMax()); + case CmpInst::ICMP_SLT: + return getSignedMax().slt(Other.getSignedMin()); + case CmpInst::ICMP_SLE: + return getSignedMax().sle(Other.getSignedMin()); + case CmpInst::ICMP_SGT: + return getSignedMin().sgt(Other.getSignedMax()); + case CmpInst::ICMP_SGE: + return getSignedMin().sge(Other.getSignedMax()); + default: + llvm_unreachable("Invalid ICmp predicate"); + } } /// Exact mul nuw region for single element RHS. |