[PATCH] D69217: [ConstantRange] makeGuaranteedNoWrapRegion(): `shl` support

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Oct 19 14:00:16 PDT 2019


nikic added inline comments.


================
Comment at: llvm/lib/IR/ConstantRange.cpp:276
+    if (ShAmtUMax.uge(BitWidth))
+      return getEmpty(BitWidth); // Shift by bitwidth or more always overflows.
+    if (Unsigned)
----------------
While an empty set here is conservatively correct, I believe that the more precise return value would be the range containing only zero `[0, 1)`. The shift amount is < the bitwidth by assumption (otherwise the result is poison), and `[0, 1)` is the result for the worst-case assumption of shift amount = bitwidth - 1.

Even more precise would be to intersect the incoming range with `[0, BitWidth)`, which may differ non-trivially from this approach for wrapped ranges. E.g. if you have a signed range `[INT_MIN, 5)`, the UMax will be `UINT_MAX`, but the intersection `[INT_MIN, 5) /\ [0, 32)` is `[0, 5)` and the UMax will be `4`, resulting in a much larger guaranteed nowrap region.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69217





More information about the llvm-commits mailing list