[clang] [Clang] Allow the value of unroll count to be zero in `#pragma GCC unroll` and `#pragma unroll` (PR #88666)

via cfe-commits cfe-commits at lists.llvm.org
Fri Apr 26 06:18:50 PDT 2024


alexfh wrote:

There's one more questionable effect of this commit (together with the fix in #89567). Some of our code started triggering "loop not unrolled" warnings. A reduced example is at https://godbolt.org/z/jG4xsGY7s
```
#include <cstddef>
#include <bit>

template <bool Flag>
int FailToBuild(int n) {
  constexpr int N = 100;
  auto init = [=]() { return Flag ? n : 0UL; };
  auto cond = [=](size_t ix) { return Flag ? ix != 0 : ix < 10; };
  auto iter = [=](size_t ix) {
    return Flag ? ix & ~(1ULL << std::countr_zero(ix)) : ix + 1;
  };
#pragma unroll Flag ? 1 : N
  for (size_t ix = init(); cond(ix); ix = iter(ix)) {
    n *= n;
  }
  return n;
}

int foo(int n) {
    return FailToBuild<true>(n);
}

int bar(int n) {
    return FailToBuild<false>(n);
}
```

`clang -std=c++20 -O3` started generating the following warning on this code after the commit:
```
<source>:13:3: warning: loop not unrolled: the optimizer was unable to perform the requested transformation; the transformation might be disabled or specified as part of an unsupported transformation ordering [-Wpass-failed=transform-warning]
   13 |   for (size_t ix = init(); cond(ix); ix = iter(ix)) {
```

It doesn't seem the generated code has actually changed, thus, the question is whether these are legit warnings that used to be missed, or vice versa?

https://github.com/llvm/llvm-project/pull/88666


More information about the cfe-commits mailing list