为什么clang无法展开循环(gcc展开)? [英] Why does clang is unable to unroll a loop (that gcc unrolls)?

查看:289
本文介绍了为什么clang无法展开循环(gcc展开)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用C编写并使用clang进行编译。我正在尝试展开一个循环。



循环未展开:优化器无法执行请求的转换;循环未展开。该转换可能被禁用或被指定为不支持的转换命令的一部分[-Wpass-failed = transform-warning]



您可以在此处找到结果:



唯一的区别是整数的大小


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.

解决方案

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

这篇关于为什么clang无法展开循环(gcc展开)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆