[all-commits] [llvm/llvm-project] 8d85e9: [SCEV] Canonicalize X - urem X, Y patterns

Philip Reames via All-commits all-commits at lists.llvm.org
Tue Nov 16 11:59:42 PST 2021


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 8d85e945b20e8e84f18cc7c215920b0fb1d0e583
      https://github.com/llvm/llvm-project/commit/8d85e945b20e8e84f18cc7c215920b0fb1d0e583
  Author: Philip Reames <listmail at philipreames.com>
  Date:   2021-11-16 (Tue, 16 Nov 2021)

  Changed paths:
    M llvm/lib/Analysis/ScalarEvolution.cpp
    M llvm/test/Analysis/ScalarEvolution/urem-0.ll
    M llvm/test/CodeGen/Thumb2/LowOverheadLoops/fast-fp-loops.ll
    M llvm/test/CodeGen/Thumb2/LowOverheadLoops/mve-float-loops.ll
    M llvm/test/CodeGen/Thumb2/LowOverheadLoops/mve-tail-data-types.ll
    M llvm/test/Transforms/HardwareLoops/ARM/structure.ll
    M llvm/test/Transforms/LoopUnroll/runtime-loop5.ll

  Log Message:
  -----------
  [SCEV] Canonicalize X - urem X, Y patterns

There are multiple possible ways to represent the X - urem X, Y pattern. SCEV was not canonicalizing, and thus, depending on which you analyzed, you could get different results. The sub representation appears to produce strictly inferior results in practice, so I decided to canonicalize to the Y * X/Y version.

The motivation here is that runtime unroll produces the sub X - (and X, Y-1) pattern when Y is a power of two. SCEV is thus unable to recognize that an unrolled loop exits because we don't figure out that the new unrolled step evenly divides the trip count of the unrolled loop. After instcombine runs, we convert the the andn form which SCEV recognizes, so essentially, this is just fixing a nasty pass ordering dependency.

The ARM loop hardware interaction in the test diff is opague to me, but the comments in the review from others knowledge of the infrastructure appear to indicate these are improvements in loop recognition, not regressions.

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




More information about the All-commits mailing list