[PATCH] D48853: [SCEV] Add zext(C + x + ...) -> D + zext(C-D + x + ...)<nuw> transform

Roman Tereshin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 2 16:27:28 PDT 2018


rtereshin added a comment.

To further entertain the idea, let's notice that the upper limit is not always the constant part of the expression. If it's `x * 4 + 6` we can only subtract 0, 1, or 2.
Of course, we could use `GetMinTrailingZeros(x * 4) = 2`, turn this into a 0000 0011 mask, apply the mask to the constant part (0000 0110), get 10 (2) as the maximum safe subtrahend.

But what if there is more than 2 terms? For instance, the expression is `6 + 20 * %x + 24 * %y`. Do I need to rebuild an `add` from `20 * %x` and `24 * %y` just to apply `GetMinTrailingZeros` to the result?

Or I could extract the part of the `GetMinTrailingZeros` that handles `add` as a separate method so it could be used here. Do you think any of it is a better solution that applying `computeKnownBits` directly?


Repository:
  rL LLVM

https://reviews.llvm.org/D48853





More information about the llvm-commits mailing list