[llvm-commits] [llvm] r143106 - /llvm/trunk/lib/Support/BlockFrequency.cpp
Benjamin Kramer
benny.kra at googlemail.com
Thu Oct 27 09:38:50 PDT 2011
Author: d0k
Date: Thu Oct 27 11:38:50 2011
New Revision: 143106
URL: http://llvm.org/viewvc/llvm-project?rev=143106&view=rev
Log:
BlockFrequency: Use a smarter overflow check.
This trades one 64 bit div for one 64 bit mul and some arithmetic.
Modified:
llvm/trunk/lib/Support/BlockFrequency.cpp
Modified: llvm/trunk/lib/Support/BlockFrequency.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/BlockFrequency.cpp?rev=143106&r1=143105&r2=143106&view=diff
==============================================================================
--- llvm/trunk/lib/Support/BlockFrequency.cpp (original)
+++ llvm/trunk/lib/Support/BlockFrequency.cpp Thu Oct 27 11:38:50 2011
@@ -70,8 +70,13 @@
assert(n <= d && "Probability must be less or equal to 1.");
- // If we can overflow use 96-bit operations.
- if (n > 0 && Frequency > UINT64_MAX / n) {
+ // Calculate Frequency * n.
+ uint64_t mulLo = (Frequency & UINT32_MAX) * n;
+ uint64_t mulHi = (Frequency >> 32) * n;
+ uint64_t mulRes = (mulHi << 32) + mulLo;
+
+ // If there was overflow use 96-bit operations.
+ if (mulHi > UINT32_MAX || mulRes < mulLo) {
// 96-bit value represented as W[1]:W[0].
uint64_t W[2];
@@ -82,8 +87,7 @@
return *this;
}
- Frequency *= n;
- Frequency /= d;
+ Frequency = mulRes / d;
return *this;
}
More information about the llvm-commits
mailing list