2013/6/18 Steve Ellcey <sell...@mips.com>: > On Mon, 2013-06-17 at 21:36 +0200, Oleg Endo wrote: > >> >> Sorry for not having an answer. I got curious, because just yesterday I >> was looking at this one >> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55190 >> and thought that this is related, although it doesn't seem to. >> I've tried the two functions of yours on SH and there it produces the >> same machine code with -O2. -O3 results in a call to memcpy, while >> -O3 -fno-tree-loop-distribute-patterns again results in the same code. >> >> Cheers, >> Oleg > > Thanks for the pointer. It made me realize I should try running my test > with -fno-ivopts. That got rid of the '-4' usage and I wound up getting > the code that I was after. I still hope someone can help me understand > why ivopts made the transformation it did though. I am afraid that just > turning off ivopts may have a larger affect then I am after. > > Steve Ellcey > sell...@mips.com > > > >
This may have something to do with sequence point concept. (C99 5.1.2.3, C99 Annex C) To my understanding, the following two statements are not equivalent if you take sequence point into consideration: (1) *d++ = *s++; (2) *d = *s; d++; s++; The case (2) has a sequence point after ';', which mean '++' is taken place after the expression *d=*s has been evaluated. But for the case (1), compiler is free to reorder evaluations, which may move the post-increments above the assignment and then ivopt convert it using -4 offset for memory reference. There remains space to discuss whether it is worth for ivopt to do such transformation. Apparently it is not good for your case, but it may be helpful to reduce register pressure for the target with few registers. Best regards, jasonwucj