2011/10/26 Michael Matz <m...@suse.de>: > Hi, > > On Wed, 26 Oct 2011, Kai Tietz wrote: > >> well, if such a function is used as inline and we know for it that j has >> value != 2, then we have here a big difference. For your first example, >> we still have to do the memory access to *i, even if we are not >> interested in result. > > Actually we don't have to preserve memory accesses. The interesting case > is if the pointer has an invalid value. The behaviour of the access then > is undefined, and it's okay to not do it at all. In case the pointer does > point to an object the access (if it's value isn't needed) also isn't > necessary. IOW: in "void f(int *p) { int i = *p; }" we can always remove > the pointer read. So, I still maintain that the transformation on the > original example was okay. > > > Ciao, > Michael.
So you would mean that memory dereferencing shouldn't be considered as side-effect at all? So we would happily cause by code 'if (i && *i != 0) an crash, as memory-dereference has for you no side-effect? In you special case it might be valid that, if first (and C-fold-const doesn't know if the side-effect condition is really the first, as it might be a sub-sequence of a condition) condition might trap or not, to combine it. But branching has to cover the general cases. If you find a way to determine that left-hand operand in fold_const's branching code is really the left-most condition in chain, then we can add such a special case, but I don't see here an easy way to determine it. Regards, Kai Hmm, not sure