[all-commits] [llvm/llvm-project] 980e01: [NFC][LoopIdiom] Add tests for 'left-shift until z...

Roman Lebedev via All-commits all-commits at lists.llvm.org
Tue May 25 05:27:18 PDT 2021


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 980e0107a169b686bb480e751337f487d819a32c
      https://github.com/llvm/llvm-project/commit/980e0107a169b686bb480e751337f487d819a32c
  Author: Roman Lebedev <lebedev.ri at gmail.com>
  Date:   2021-05-25 (Tue, 25 May 2021)

  Changed paths:
    M llvm/test/Transforms/LoopIdiom/X86/arithmetic-right-shift-until-zero.ll
    A llvm/test/Transforms/LoopIdiom/X86/left-shift-until-zero.ll
    M llvm/test/Transforms/LoopIdiom/X86/logical-right-shift-until-zero.ll

  Log Message:
  -----------
  [NFC][LoopIdiom] Add tests for 'left-shift until zero' idiom


  Commit: 8f4db14d1c8f12cade77873f8815497026d21f95
      https://github.com/llvm/llvm-project/commit/8f4db14d1c8f12cade77873f8815497026d21f95
  Author: Roman Lebedev <lebedev.ri at gmail.com>
  Date:   2021-05-25 (Tue, 25 May 2021)

  Changed paths:
    M llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp
    M llvm/test/Transforms/LoopIdiom/X86/left-shift-until-zero.ll

  Log Message:
  -----------
  [LoopIdiom] Support 'left-shift until zero' idiom

This adds support for the "count active bits" pattern, i.e.:
```
int countBits(unsigned val) {
    int cnt = 0;
    for( ; (val << cnt) != 0; ++cnt)
        ;
    return cnt;
}
```
but a somewhat more general one:
```
int countBits(unsigned val, int start, int off) {
    int cnt;
    for (cnt = start; val << (cnt + off); cnt++)
        ;
    return cnt;
}
```

alive2 is happy with all the tests there.

Note that, again, much like with the right-shift cases,
we don't require the `val != 0` guard.

This is the last pattern that was supported by
`detectShiftUntilZeroIdiom()`, which now becomes obsolete.


Compare: https://github.com/llvm/llvm-project/compare/b0d68c714141...8f4db14d1c8f


More information about the All-commits mailing list