[Bug middle-end/31862] Loop IM and other optimizations harmful for -fopenmp

davids at webmaster dot com gcc-bugzilla@gcc.gnu.org
Wed Feb 25 17:54:00 GMT 2009



------- Comment #20 from davids at webmaster dot com  2009-02-25 17:53 -------
I don't like this either:

  tmp = var;
  modified = false;
  for (i = 0; i < 100; i++)
    {
      if (i > x)
        tmp = i, modified = true;
    }
  if (modified)
    var = tmp;

This can be a pessimization as well. If 'modified' is almost always false, the
'tmp = var;' can force a cache unshare for no reason. If this code is not
performance critical, the optimization is pointless. If it is, the
pessimization can be significant.

IMO, these kinds of optimizations are not worth doing. Almost any optimization
that can introduce an additional memory access risks a net performance loss in
some use cases. The compiler cannot determine the use case by static code
inspection.

Now, in this case, the 'tmp = var;' is obviously superfluous, you can just
eliminate it, so this isn't a good example of what I'm talking about. But in
general, an optimization should not *add* a memory operation the code did not
request unless you can show that it will always remove at least one operation
of comparable cost. Otherwise it can be a net performance loss all the time in
some use cases.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31862



More information about the Gcc-bugs mailing list