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

Roman Lebedev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Oct 19 13:23:06 PDT 2019


lebedev.ri created this revision.
lebedev.ri added reviewers: nikic, sanjoy.
lebedev.ri added a project: LLVM.
Herald added a subscriber: hiraditya.

Shift by more than bitwidth-1 produces poison.
Therefore if maximal shift amount that we are asked about is more than bitwidth-1,
the overflow will happen regardless of the value being shifted,
in other words there is no such value for which the overflow
[when shifting by more than bitwidth-1] does not happen.

For unsigned range not not overflow, we must not shift out any set bits,
and the actual limit for `x` can be computed by backtransforming
the maximal value we could ever get out of the `shl` - `-1` through
`lshr`. If the `x` is any larger than that then it will overflow.

Likewise for signed range, but just in signed domain..

This is based on the general idea outlined by @nikic in https://reviews.llvm.org/D68672#1714990


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D69217

Files:
  llvm/lib/IR/ConstantRange.cpp
  llvm/unittests/IR/ConstantRangeTest.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D69217.225765.patch
Type: text/x-patch
Size: 4895 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191019/87739b78/attachment.bin>


More information about the llvm-commits mailing list