Why does Clang optimize away x * 1.0 but NOT x + 0.0?

前端 未结 2 826
你的背包
你的背包 2020-12-07 23:56

Why does Clang optimize away the loop in this code

#include 
#include 

static size_t const N = 1 << 27;
static double arr         


        
2条回答
  •  暖寄归人
    2020-12-08 00:30

    x += 0.0 isn't a NOOP if x is -0.0. The optimizer could strip out the whole loop anyway since the results aren't used, though. In general, it's hard to tell why an optimizer makes the decisions it does.

提交回复
热议问题