------- Comment #5 from tromey at gcc dot gnu dot org 2007-10-27 16:42 ------- I looked at this a little.
This test is a little bit funny because the '+' has undefined overflow but the '*' does not. Move the cast to make the '+' have defined overflow, and it works. What happens is that we call fold_sign_changed_comparison on the '==' expression (in the very first test case). This decides that the expression can be simplified by removing the casts to unsigned. Some earlier call has already hoisted the cast to unsigned to apply to the '*' tree as a whole, so stripping this means we are optimizing a signed multiply. Offhand I would say that it is not valid to convert an unsigned operation to a signed operation, because that changes overflow from defined to undefined. Going the other direction should generally be ok -- though, I suppose, sometimes miss an optimization. Removing the special case for EQ_EXPR and NE_EXPR from fold_sign_changed_comparison should fix this bug, but I don't know at what cost. Or, perhaps this test could be changed to look at whether arg0_inner is now a signed binary expression. Some advice from a fold expert would be appreciated. -- tromey at gcc dot gnu dot org changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |tromey at gcc dot gnu dot | |org Status|UNCONFIRMED |NEW Ever Confirmed|0 |1 Last reconfirmed|0000-00-00 00:00:00 |2007-10-27 16:42:51 date| | http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33779