https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83726
--- Comment #3 from Wilco <wilco at gcc dot gnu.org> --- This is related with PR82964/82974, looks like same underlying issue. I have a patch which changes the constraint, and that fixes this issue too. It's not obvious to me whether legitimate_constant_p should be a subset of the constraint or not. For rematerialization to work, it needs to return true for any constants that can be cheaply rematerialized. That includes literal loads, ie. constants that don't match immediate constraints.