Quantcast
Channel: Intel® C++ Compiler
Viewing all articles
Browse latest Browse all 1616

Missed optimization opportunity

$
0
0

Hey all,

I just noticed a missed performance opportunity:

#include <cmath>
int main()
{
  const double C[2] = { 1., 0. };
  double v = C[1]  * cos(.42 * argc);
  return v;
}

This will call cos even though the result will always be 0. Now compare this to this code:

#include <cmath>
int main()
{
  double v = 0. * cos(.42 * argc);
  return v;
}

Here, the call to cos is properly optimized away. This is what I'd expect from the first code as well.


Viewing all articles
Browse latest Browse all 1616

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>