[PATCH] D28308: [SCEV] Model ashr(shl(x, n), m) as mul(x, 2^(n-m)) when n > m

Sanjoy Das via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 2 15:24:23 PST 2017


sanjoy requested changes to this revision.
sanjoy added a comment.
This revision now requires changes to proceed.

Did you consider doing this same thing in two more general steps (with separate tests for each case):

- Lower `ashr X C` as `sext(trunc(udiv(X, 1 << C)))`, irrespective of what `X` is
- Add a separate rule that `(A mul (1 << C0)) udiv (1 << C1)` is `sext(trunc(A mul (1 << (C0 - C1))))` if `C0 > C1`



================
Comment at: lib/Analysis/ScalarEvolution.cpp:5299
+          Type *TruncTy = IntegerType::get(getContext(), TruncToWidth);
+          Type *SExtTy = BO->LHS->getType();
+          Value *LShOp1 = L->getOperand(1);
----------------
`LShOp1` is somewhat ambiguous -- how about `ShlOp1` (unique since there is only one `Shl` in context)?


================
Comment at: lib/Analysis/ScalarEvolution.cpp:5316
+
+          uint64_t LShAmt = LCI->getZExtValue();
+          // When n < m, we cannot use sext(udiv(trunc(x), 2^(m-n))) since
----------------
Please call this `ShlAmt`, and please call `LCI` `ShlAmtCI` or something like that.


================
Comment at: test/Analysis/ScalarEvolution/sext-mul.ll:13
+; CHECK:Loop %bb7: max backedge-taken count is -1
+; CHECK:Loop %bb7: Predicated backedge-taken count is (-1 + (zext i32 %arg2 to i64))<nsw>
+
----------------
Please add some target test cases here (i.e. ones that check specific SCEV expressions for the patterns you want SCEV to catch).


Repository:
  rL LLVM

https://reviews.llvm.org/D28308





More information about the llvm-commits mailing list