llvm.org GIT mirror llvm / e2389da
[APSInt] Use APInt::compare and APInt::compareSigned to implement APSInt::compareValue APInt just got compare methods that return -1, 0, or 1 instead of just having ult/slt and eq. This patch uses these methods to implement APSInt::compareValues so that we don't have to call do an equal comparison and then possibly a second less than comparison. Differential Revision: https://reviews.llvm.org/D32381 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@301053 91177308-0d34-0410-b5e6-96231b3b80d8 Craig Topper 3 years ago
2 changed file(s) with 5 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
8989
9090 friend struct DenseMapAPIntKeyInfo;
9191
92 friend class APSInt;
93
9294 /// \brief Fast internal constructor
9395 ///
9496 /// This constructor is used only internally for speed of construction of
287287 /// \brief Compare underlying values of two numbers.
288288 static int compareValues(const APSInt &I1, const APSInt &I2) {
289289 if (I1.getBitWidth() == I2.getBitWidth() && I1.isSigned() == I2.isSigned())
290 return I1 == I2 ? 0 : I1 > I2 ? 1 : -1;
290 return I1.IsUnsigned ? I1.compare(I2) : I1.compareSigned(I2);
291291
292292 // Check for a bit-width mismatch.
293293 if (I1.getBitWidth() > I2.getBitWidth())
294294 return compareValues(I1, I2.extend(I1.getBitWidth()));
295 else if (I2.getBitWidth() > I1.getBitWidth())
295 if (I2.getBitWidth() > I1.getBitWidth())
296296 return compareValues(I1.extend(I2.getBitWidth()), I2);
297297
298298 // We have a signedness mismatch. Check for negative values and do an
307307 return 1;
308308 }
309309
310 return I1.eq(I2) ? 0 : I1.ugt(I2) ? 1 : -1;
310 return I1.compare(I2);
311311 }
312312
313313 static APSInt get(int64_t X) { return APSInt(APInt(64, X), false); }