https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70847
--- Comment #10 from Jakub Jelinek <jakub at gcc dot gnu.org> --- Note, the patch has been successfully bootstrapped/regtested on x86_64-linux and i686-linux. I don't think such shared trees should be occurring significantly that it would matter. But, if you want to handle those, your change makes no sense, because if cp_fold returns something other than its argument unmodified, then the subsequent subtree walking happens on the new tree, not the old one, but you stop the walking of the subtrees the second time. Another option would be to only special case SAVE_EXPR and TARGET_EXPR, use *walk_subtrees = 0; for it if it is already in the cache.