[all-commits] [llvm/llvm-project] 6478f3: [SCEV] Support single-cond range check idiom in ap...

Florian Hahn via All-commits all-commits at lists.llvm.org
Fri Jun 25 02:26:04 PDT 2021


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 6478f3fb78b3e7cddb642dce0f39d5d4a976af1e
      https://github.com/llvm/llvm-project/commit/6478f3fb78b3e7cddb642dce0f39d5d4a976af1e
  Author: Florian Hahn <flo at fhahn.com>
  Date:   2021-06-25 (Fri, 25 Jun 2021)

  Changed paths:
    M llvm/lib/Analysis/ScalarEvolution.cpp
    M llvm/test/Analysis/ScalarEvolution/max-backedge-taken-count-guard-info.ll

  Log Message:
  -----------
  [SCEV] Support single-cond range check idiom in applyLoopGuards.

This patch extends applyLoopGuards to detect a single-cond range check
idiom that InstCombine generates.

It extends applyLoopGuards to detect conditions of the form
(-C1 + X < C2). InstCombine will create this form when combining two
checks of the form (X u< C2 + C1) and (X >=u C1).

In practice, this enables us to correctly compute a tight trip count
bounds for code as in the function below. InstCombine will fold the
minimum iteration check created by LoopRotate with the user check (< 8).

    void unsigned_check(short *pred, unsigned width) {
        if (width < 8) {
            for (int x = 0; x < width; x++)
                pred[x] = pred[x] * pred[x];
        }
    }

As a consequence, LLVM creates dead vector loops for the code above,
e.g. see https://godbolt.org/z/cb8eTcqET

https://alive2.llvm.org/ce/z/SHHW4d

Reviewed By: nikic

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




More information about the All-commits mailing list