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

Eli Friedman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 9 17:02:20 PST 2017


efriedma added inline comments.


================
Comment at: lib/Analysis/ScalarEvolution.cpp:5268
+          const SCEV *LOp0Trunc =
+              getTruncateExpr(getSCEV(L->getOperand(0)), TruncTy);
 
----------------
You have to check whether Amt == BitWidth before you call getTruncateExpr(); otherwise, you'll get an assertion failure in getTruncateExpr in edge cases like "ashr i32 %x, 0".


================
Comment at: lib/Analysis/ScalarEvolution.cpp:5280
+
+          // Hanlde below case:
+          // %y = shl %x, n
----------------
Typo: "Handle".


================
Comment at: lib/Analysis/ScalarEvolution.cpp:5292
+          uint64_t LShAmt = LCI->getZExtValue();
+          //TODO: when n < m, sext(udiv(trunc(x), 2^(m-n)))
+          if (AShrAmt > LShAmt)
----------------
This TODO is suggesting an incorrect transformation; udiv doesn't preserve the sign.


================
Comment at: test/Analysis/ScalarEvolution/sext-mul.ll:41
+  %21 = icmp eq i64 %20, %6
+  br i1 %21, label %7, label %9
+}
----------------
Maybe run opt -instnamer over the testcase, so it's easier to edit if we ever need to change it?


Repository:
  rL LLVM

https://reviews.llvm.org/D28308





More information about the llvm-commits mailing list