Multiply by 0 optimization

后端 未结 2 410
囚心锁ツ
囚心锁ツ 2021-01-07 20:42

Suppose i have:

double f(const double *r) {
    return 0*(r[0]*r[1]);
}

should compiler be able to optimize out the segment, or does it sti

2条回答
  •  终归单人心
    2021-01-07 21:03

    It isn't only inf and NaN that prevent the optimization there, it's also the sign - 0.0 * something negative is -0.0, otherwise it's 0.0, so you actually have to compute the sign of r[0]*r[1].

提交回复
热议问题