On Wed, Jul 13, 2011 at 11:52:25AM +0400, Ilya Enkovich wrote: > > However, it does not fix http://gcc.gnu.org/PR45671, which surprises me > > as it was marked as a duplicate of this one. Any thoughts on why this > > isn't sufficient to reassociate the linear chain of adds? > > > > Test case: > > > > int myfunction (int a, int b, int c, int d, int e, int f, int g, int h) > > { > > int ret; > > > > ret = a + b + c + d + e + f + g + h; > > return ret; > > > > } > > > > > > > > Reassociation does not work for signed integers because signed integer > is not wrap-around type in C. You can change it by passing -fwrapv > option but it will disable other useful optimization. Reassociation of > signed integers without this option is not a trivial question because > in that case you may introduce overflows and therefore undefined > behavior.
Well, if it is clearly a win to reassociate, you can always reassociate them by doing arithmetics in corresponding unsigned type and afterwards converting back to the signed type. Jakub