Why does clang is unable to unroll a loop (that gcc unrolls)?

拟墨画扇 提交于 2020-01-07 23:21:24

问题


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:


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

https://godbolt.org/z/VYn0CA

The inly difference is the size of the integer



来源:https://stackoverflow.com/questions/55908053/why-does-clang-is-unable-to-unroll-a-loop-that-gcc-unrolls

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!