https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116282
--- Comment #3 from Jeffrey A. Law <law at gcc dot gnu.org> --- So yes, this is a problem with the const costing giving two different answers at different times. That in turn causes the relevant pattern to match at one point and fail to match at another. It's a bit of a tangled web, but I think I've got it sorted out and I'm doing internal testing of a patch now. As I mentioned earlier I think this will also affect Raphael's recent submission, though in a very minor way. There's other questions to work through with that submission, but it is worth noting.