]> granicus.if.org Git - llvm/commitdiff
[ConstantRange] Rewrite shl to avoid repeated calls to getUnsignedMax and avoid creat...
authorCraig Topper <craig.topper@gmail.com>
Tue, 9 May 2017 07:04:04 +0000 (07:04 +0000)
committerCraig Topper <craig.topper@gmail.com>
Tue, 9 May 2017 07:04:04 +0000 (07:04 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@302510 91177308-0d34-0410-b5e6-96231b3b80d8

lib/IR/ConstantRange.cpp

index 6801ed4fb51122c20e0b784daf3a0b012b0cedb2..a33d062dbeaa1723ce48552961d18e30de54e2ac 100644 (file)
@@ -892,16 +892,20 @@ ConstantRange::shl(const ConstantRange &Other) const {
   if (isEmptySet() || Other.isEmptySet())
     return ConstantRange(getBitWidth(), /*isFullSet=*/false);
 
-  APInt min = getUnsignedMin().shl(Other.getUnsignedMin());
-  APInt max = getUnsignedMax().shl(Other.getUnsignedMax());
+  APInt max = getUnsignedMax();
+  APInt Other_umax = Other.getUnsignedMax();
 
-  // there's no overflow!
-  APInt Zeros(getBitWidth(), getUnsignedMax().countLeadingZeros());
-  if (Zeros.ugt(Other.getUnsignedMax()))
-    return ConstantRange(std::move(min), std::move(max) + 1);
+  // there's overflow!
+  if (Other_umax.uge(max.countLeadingZeros()))
+    return ConstantRange(getBitWidth(), /*isFullSet=*/true);
 
   // FIXME: implement the other tricky cases
-  return ConstantRange(getBitWidth(), /*isFullSet=*/true);
+
+  APInt min = getUnsignedMin();
+  min <<= Other.getUnsignedMin();
+  max <<= Other_umax;
+
+  return ConstantRange(std::move(min), std::move(max) + 1);
 }
 
 ConstantRange