[PATCH] D32672: [ConstantRange] Remove costly udivrem from ConstantRange::truncate

Craig Topper via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Apr 29 19:16:34 PDT 2017


craig.topper added inline comments.


================
Comment at: lib/IR/ConstantRange.cpp:579
+    if (Upper.getActiveBits() > DstTySize ||
+        Upper.countTrailingOnes() == DstTySize)
       return ConstantRange(DstTySize, /*isFullSet=*/true);
----------------
Note this countTrailingOnes check isn't strictly necessary. If Upper is equal to MaxValue(DstTy), Union will be FullSet. We could continue on and trust unionWith to return FullSet.


================
Comment at: lib/IR/ConstantRange.cpp:592
   // Chop off the most significant bits that are past the destination bitwidth.
-  if (LowerDiv.uge(MaxValue)) {
-    APInt Div(getBitWidth(), 0);
-    APInt::udivrem(LowerDiv, MaxBitValue, Div, LowerDiv);
-    UpperDiv -= MaxBitValue * Div;
+  if (LowerDiv.getActiveBits() > DstTySize) {
+    // Mask to just the signficant bits and subtract from LowerDiv/UpperDiv.
----------------
Note the original code used uge, but I believe ugt was sufficient. Thus I've only implemented the equivalent of ugt with the getActiveBits check here.


https://reviews.llvm.org/D32672





More information about the llvm-commits mailing list