[all-commits] [llvm/llvm-project] 8a0e4a: [NFC][LoopIdiom] Add tests for 'arithmetic right-s...

Roman Lebedev via All-commits all-commits at lists.llvm.org
Tue May 25 04:31:24 PDT 2021


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

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

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


  Commit: f1c5f78d3813584f7796f8b84b92fa0725964c17
      https://github.com/llvm/llvm-project/commit/f1c5f78d3813584f7796f8b84b92fa0725964c17
  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/arithmetic-right-shift-until-zero.ll

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

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

This directly matches the existing 'logical right-shift until zero' idiom.
alive2 is happy with all the tests there.

Note that, again, much like with the original unsigned case,
we don't require the `val != 0` guard.

The old `detectShiftUntilZeroIdiom()` already supports this pattern,
the idea here is that the `val` must be positive (have at least one
leading zero), because otherwise the loop is non-terminating,
but since it is not `while(1)`, that would have been UB.


Compare: https://github.com/llvm/llvm-project/compare/1dee479ff632...f1c5f78d3813


More information about the All-commits mailing list