Why does clang is unable to unroll a loop (that gc

2019-09-21 09:49发布

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.

1条回答
趁早两清
2楼-- · 2019-09-21 10:21

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

查看更多
登录 后发表回答