Skip to content

Commit 3ab2247

Browse files
committed
[ConstantRange] Optimize icmp() implementation (NFC)
These are pretty hot code paths, so provide direct implementations for them, instead of going through makeSatisfyingICmpRegion().
1 parent f057130 commit 3ab2247

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

llvm/lib/IR/ConstantRange.cpp

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,36 @@ bool ConstantRange::getEquivalentICmp(CmpInst::Predicate &Pred,
241241

242242
bool ConstantRange::icmp(CmpInst::Predicate Pred,
243243
const ConstantRange &Other) const {
244-
return makeSatisfyingICmpRegion(Pred, Other).contains(*this);
244+
if (isEmptySet() || Other.isEmptySet())
245+
return true;
246+
247+
switch (Pred) {
248+
case CmpInst::ICMP_EQ:
249+
if (const APInt *L = getSingleElement())
250+
if (const APInt *R = Other.getSingleElement())
251+
return *L == *R;
252+
return false;
253+
case CmpInst::ICMP_NE:
254+
return inverse().contains(Other);
255+
case CmpInst::ICMP_ULT:
256+
return getUnsignedMax().ult(Other.getUnsignedMin());
257+
case CmpInst::ICMP_ULE:
258+
return getUnsignedMax().ule(Other.getUnsignedMin());
259+
case CmpInst::ICMP_UGT:
260+
return getUnsignedMin().ugt(Other.getUnsignedMax());
261+
case CmpInst::ICMP_UGE:
262+
return getUnsignedMin().uge(Other.getUnsignedMax());
263+
case CmpInst::ICMP_SLT:
264+
return getSignedMax().slt(Other.getSignedMin());
265+
case CmpInst::ICMP_SLE:
266+
return getSignedMax().sle(Other.getSignedMin());
267+
case CmpInst::ICMP_SGT:
268+
return getSignedMin().sgt(Other.getSignedMax());
269+
case CmpInst::ICMP_SGE:
270+
return getSignedMin().sge(Other.getSignedMax());
271+
default:
272+
llvm_unreachable("Invalid ICmp predicate");
273+
}
245274
}
246275

247276
/// Exact mul nuw region for single element RHS.

0 commit comments

Comments
 (0)