[PATCH] D56837: [IRCE] Support narrow latch condition for wide range checks

Max Kazantsev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 22 00:52:11 PST 2019


mkazantsev marked an inline comment as done.
mkazantsev added inline comments.


================
Comment at: lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp:1398
   IntegerType *IVTy =
-      cast<IntegerType>(MainLoopStructure.IndVarBase->getType());
 
----------------
reames wrote:
> I can't justify this change to myself.  Can you explain why this is correct?
Without this patch, the type of IndVarBase always matches with the type of range (and types of all range checks being affected). With this patch, we are dealing with something like:

  for (i64 i = 0; trunc i64 i to i32 <s i32 n; i++) {
    if (i < i64 bound) deopt();
  }

IVbase here is a `i32` AddRec for ` trunc i64 i to i32`, and range and SR are i64 ranges containing safe iteration bounds.

In this case, `ExitMainLoopAt` would be `smin(sext i32 n to i64, i64 bound)` which is basically a `i64` value that doesn't exceed `i32 max`. We can trunc it to `i32` and its value will not change. We would just make more truncations.

Basically, it doesn't matter. All values involved would also fit into the narrow type range. Using wider type has two benefits:
- It gives us less truncs that are only needed for comparisons;
- further transforms can completely get rid of the narrow type in the main loop (IVSimplify can then prove that `sext(trunc(iv))` on latch check is a noop and we can use IV instead).




CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D56837/new/

https://reviews.llvm.org/D56837





More information about the llvm-commits mailing list