[PATCH] D64869: [SCEV] get more accurate range for AddExpr with NW flag

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Sep 7 04:28:51 PDT 2019


nikic added a comment.

Can you please split off the ConstantRange addition into a separate revision?



================
Comment at: llvm/lib/IR/ConstantRange.cpp:853
+      return ConstantRange(getUnsignedMin() + Other.getUnsignedMin(),
+                           getUnsignedMax() + Other.getUnsignedMax() + 1);
+    } else { // OverflowResult::MayOverflow
----------------
You can use `getNonEmpty(A, B)` here to avoid the explicit check for full range. Similar below.


================
Comment at: llvm/lib/IR/ConstantRange.cpp:862
+                           APInt::getMinValue(getBitWidth()));
+    }
+  } else {
----------------
I think that this whole code can be somewhat simplified. I have an unfinished implementation of add nuw lying around that looks like this:

```
APInt LMin = L.getUnsignedMin(), LMax = L.getUnsignedMax();
APInt RMin = R.getUnsignedMin(), RMax = R.getUnsignedMax();
bool Overflow;
APInt NewMin = LMin.uadd_ov(RMin, Overflow);
if (Overflow)
  return ConstantRange::getEmpty(L.getBitWidth());
APInt NewMax = LMax.uadd_sat(RMax);
return ConstantRange::getNonEmpty(NewMin, std::move(NewMax) + 1);
```


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64869/new/

https://reviews.llvm.org/D64869





More information about the llvm-commits mailing list