[Bug tree-optimization/16803] PowerPC - invariant code motion could be removed from loop.

nathan at gcc dot gnu dot org gcc-bugzilla@gcc.gnu.org
Fri Nov 12 09:24:00 GMT 2004


------- Additional Comments From nathan at gcc dot gnu dot org  2004-11-12 09:24 -------
We cannot generate better code, without having a different meaning for the
sign_extend action that occurs in the loop.
As zdenek points out, we cannot use dbra, because we cannot tell if the loop
will actually terminate -- because of the <= continuation condition.  on ppc64
ints are 32 bits and pointers are 64 bits.  the base address 'x' is a pointer
to an array that we cannot tell the bounds of -- x might point into the middle
of an array.  Therefore both negative and positive ints of any value might
be valid offsets.

If the loop is unbounded, then there is the possibility of wrap-around during
the increment of i.  What happens in this case is undefined.  We could therefore
remove the sign-extension from int->long, and optimize further on the basis that
undefined things never happen in a well-formed program.  Unfortunately we cannot
do this with the current RTL structure.  The sign-extend operation is used in
two different circumstances, (a) when it really is sign extending a shorter
(valid) value to a longer representation, and (b) when we're truncating a
possibly out-of-range value.  (b) is undefined, yet we do not represent that
undefinedness, and cannot distinguish it from (a), which is well defined.

I will add a meta-bug noting this problem with extend operations.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|nathan at gcc dot gnu dot   |unassigned at gcc dot gnu
                   |org                         |dot org
             Status|ASSIGNED                    |NEW


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



More information about the Gcc-bugs mailing list