[all-commits] [llvm/llvm-project] 091422: [LSR] Fix wrapping bug in lsr-term-fold logic

Philip Reames via All-commits all-commits at lists.llvm.org
Mon Mar 20 13:47:41 PDT 2023

  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 091422adc1d7478b126a967c795414840c5c0c97
  Author: Philip Reames <preames at rivosinc.com>
  Date:   2023-03-20 (Mon, 20 Mar 2023)

  Changed paths:
    M llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
    M llvm/test/Transforms/LoopStrengthReduce/lsr-term-fold.ll

  Log Message:
  [LSR] Fix wrapping bug in lsr-term-fold logic

The existing logic was unsound, in two ways.

First, due to wrapping on the trip count computation, it could compute a value which convert a loop which exiting on iteration 256, to one which exited at 255. (With i8 trip counts.)

Second, it allowed rewriting when the trip count implies wrapping around the alternate IV. As a trivial example, it allowed rewriting an i128 exit test in terms of an i64 IV. This is obviously wrong.

Note that the test change is fairly minimal - i.e. only the targeted test - but that's only because I precommitted a change which switched the test from 32 to 64 bit pointers. For 32 bit point architectures with 32 bit primary inductions, this transform is almost always unsound to perform.

Differential Revision: https://reviews.llvm.org/D146429

More information about the All-commits mailing list