[PATCH] D28308: [SCEV] Model ashr(shl(x, n), m), where n > m, as mul(x, 2^(n-m))
Eli Friedman via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 4 12:26:41 PST 2017
efriedma added a comment.
Please upload patches with full context (`-U1000000`).
================
Comment at: lib/Analysis/ScalarEvolution.cpp:5276
BO->LHS->getType());
+ } else if (ConstantInt *LCI = dyn_cast<ConstantInt>(LOp1)) {
+ // %y = shl %x, n
----------------
Maybe reorganize the code to look more like this (rough outline)?
ConstantInt *LCI = dyn_cast<ConstantInt>(LOp1));
if (!LCI) break;
if (ashr greater than shl) break;
if (ashr less than than shl) {
// Multiply SCEV
}
return sext(trunc(scev));
================
Comment at: test/Analysis/ScalarEvolution/sext-mul.ll:4
+; CHECK: %12 = ashr exact i64 %11, 32
+; CHECK: --> {0,+,2}<%9> U: [0,-1) S: [-9223372036854775808,9223372036854775807) Exits: (-2 + (2 * (zext i32 %2 to i64)))<nsw> LoopDispositions: { %9: Computable }
+; CHECK: %13 = getelementptr inbounds i32, i32* %0, i64 %12
----------------
The loop induction variable (let's call it `i`) translates to `{0,+,1}<%9>`. `i*2` translates to `{0,+,2}<%9>`. `sext(trunc(i to i32) to i64)` `(sext i32 {0,+,1}<%9> to i64)`. `sext(trunc(i*2 to i32) to i64)` translates to `(sext i32 {0,+,2}<%9> to i64)`. `ashr(shl(i, 33), 32)` should also translate to `(sext i32 {0,+,2}<%9> to i64)`.
With your patch, `ashr(shl(i, 33), 32)` translates to `{0,+,2}<%9>`, which is wrong because the loop can iterate more that INT_MAX times.
Repository:
rL LLVM
https://reviews.llvm.org/D28308
More information about the llvm-commits
mailing list