https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69097
--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> --- Created attachment 37219 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=37219&action=edit gcc6-pr69097.patch Untested WIP patch. Looking for better name of the new function and better location. Furthermore, the optimization likely needs to be repeated somewhere in VRP, because only then it could apply to say x % -y being guarded with y != -1 or similar (where y is unmodified parameter, or something that doesn't get a new SSA_NAME). And to Mikael, yes, this is indeed related to PR50865, but that PR should have been marked as a 4+ regression (because it worked well in 3.4 and earlier; that way it wouldn't slip through for so many years), and the patch should have been posted to gcc-patches instead of only being added to the PR. That said, the conditionalizing on lang_hooks.name looks ugly, and the optimization is now in match.pd.