1

I am writing in C and compiling using clang. I am trying to unroll a loop. The loop is not unrolled and there is a 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]

You can find the results here: https://godbolt.org/z/4flN-k

int foo(int c)
{   
    size_t w = 0;
    size_t i = sizeof(size_t);

    #pragma unroll
    while(i--)
    {
        w = (w << 8) | c;
    }

    return w;
}

GCC can unroll the loop with -O3 and thus I assume that clang should also unroll it.

ilyamt
  • 49
  • 1
  • 7

1 Answers1

3

I do not know but it can if you use the same options:

https://godbolt.org/z/VYn0CA

enter image description here

The inly difference is the size of the integer

0___________
  • 60,014
  • 4
  • 34
  • 74