------- Additional Comments From nathan at gcc dot gnu dot org 2004-11-03 11:20 ------- What is happening is that convert_to_integer, which is used to convert the subtraction result to the type of 'x', reassociates the cast from (int)((long)ptr1 - (long)ptr2) to (int)ptr1 - (int)ptr2 As it thinks that's a win. Unfortunately this stops CSE noticing that the later subtraction is actually the same.
This is another example of premature tree optimization, and it should be addressed in the reworking of fold itself. I don't think this should be attempted at stage 3 -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16456