PPC: Add some missing V_SET0 patterns
[oota-llvm.git] / lib / Support / BlockFrequency.cpp
index 6e4d6b1b33c016f655bb144e06459bb8d5f82eda..5e45e46cf9743d73bb5f44f221dba936aa7f8571 100644 (file)
@@ -47,9 +47,11 @@ static uint64_t div96bit(uint64_t W[2], uint32_t D) {
   uint64_t x = W[1];
   unsigned i;
 
+  assert(x != 0 && "This is really a 64-bit division");
+
   // This long division algorithm automatically saturates on overflow.
   for (i = 0; i < 64 && x; ++i) {
-    uint32_t t = (int)x >> 31;
+    uint32_t t = -((x >> 31) & 1); // Splat bit 31 to bits 0-31.
     x = (x << 1) | (y >> 63);
     y = y << 1;
     if ((x | t) >= D) {
@@ -71,7 +73,7 @@ void BlockFrequency::scale(uint32_t N, uint32_t D) {
   uint64_t MulRes = (MulHi << 32) + MulLo;
 
   // If the product fits in 64 bits, just use built-in division.
-  if (MulHi <= UINT32_MAX && MulRes <= MulLo) {
+  if (MulHi <= UINT32_MAX && MulRes >= MulLo) {
     Frequency = MulRes / D;
     return;
   }