summaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/Utils/FunctionComparator.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/Transforms/Utils/FunctionComparator.cpp')
-rw-r--r--llvm/lib/Transforms/Utils/FunctionComparator.cpp29
1 files changed, 22 insertions, 7 deletions
diff --git a/llvm/lib/Transforms/Utils/FunctionComparator.cpp b/llvm/lib/Transforms/Utils/FunctionComparator.cpp
index 760341a29d8c..6d4026e8209d 100644
--- a/llvm/lib/Transforms/Utils/FunctionComparator.cpp
+++ b/llvm/lib/Transforms/Utils/FunctionComparator.cpp
@@ -83,6 +83,13 @@ int FunctionComparator::cmpAPInts(const APInt &L, const APInt &R) const {
return 0;
}
+int FunctionComparator::cmpConstantRanges(const ConstantRange &L,
+ const ConstantRange &R) const {
+ if (int Res = cmpAPInts(L.getLower(), R.getLower()))
+ return Res;
+ return cmpAPInts(L.getUpper(), R.getUpper());
+}
+
int FunctionComparator::cmpAPFloats(const APFloat &L, const APFloat &R) const {
// Floats are ordered first by semantics (i.e. float, double, half, etc.),
// then by value interpreted as a bitstring (aka APInt).
@@ -147,12 +154,22 @@ int FunctionComparator::cmpAttrs(const AttributeList L,
if (LA.getKindAsEnum() != RA.getKindAsEnum())
return cmpNumbers(LA.getKindAsEnum(), RA.getKindAsEnum());
- const ConstantRange &LCR = LA.getRange();
- const ConstantRange &RCR = RA.getRange();
- if (int Res = cmpAPInts(LCR.getLower(), RCR.getLower()))
+ if (int Res = cmpConstantRanges(LA.getRange(), RA.getRange()))
return Res;
- if (int Res = cmpAPInts(LCR.getUpper(), RCR.getUpper()))
+ continue;
+ } else if (LA.isConstantRangeListAttribute() &&
+ RA.isConstantRangeListAttribute()) {
+ if (LA.getKindAsEnum() != RA.getKindAsEnum())
+ return cmpNumbers(LA.getKindAsEnum(), RA.getKindAsEnum());
+
+ ArrayRef<ConstantRange> CRL = LA.getValueAsConstantRangeList();
+ ArrayRef<ConstantRange> CRR = RA.getValueAsConstantRangeList();
+ if (int Res = cmpNumbers(CRL.size(), CRR.size()))
return Res;
+
+ for (const auto &[L, R] : zip(CRL, CRR))
+ if (int Res = cmpConstantRanges(L, R))
+ return Res;
continue;
}
if (LA < RA)
@@ -441,9 +458,7 @@ int FunctionComparator::cmpConstants(const Constant *L,
if (InRangeL) {
if (!InRangeR)
return 1;
- if (int Res = cmpAPInts(InRangeL->getLower(), InRangeR->getLower()))
- return Res;
- if (int Res = cmpAPInts(InRangeL->getUpper(), InRangeR->getUpper()))
+ if (int Res = cmpConstantRanges(*InRangeL, *InRangeR))
return Res;
} else if (InRangeR) {
return -1;