https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111495
Sam James <sjames at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |guojiufu at gcc dot gnu.org --- Comment #2 from Sam James <sjames at gcc dot gnu.org> --- 1aceceb1e2d6e86ce183c8cc448750fa03b6f79e is the first bad commit commit 1aceceb1e2d6e86ce183c8cc448750fa03b6f79e Author: Jiufu Guo <guoji...@linux.ibm.com> Date: Mon Sep 4 10:31:04 2023 +0800 Optimize '(X - N * M) / N' to 'X / N - M' if valid Integer expression "(X - N * M) / N" can be optimized to "X / N - M" with the below conditions: 1. There is no wrap/overflow/underflow. wrap/overflow/underflow breaks the arithmetic operation. 2. "X - N * M" and "X" are not of opposite sign. Here, the operation "/" would be "trunc_div", the fractional part is discarded. If "X - N * M" and "X" are in different signs, then trunc_div discards the fractional parts (of /N) in different directions. PR tree-optimization/108757 gcc/ChangeLog: * match.pd ((X - N * M) / N): New pattern. ((X + N * M) / N): New pattern. ((X + C) div_rshift N): New pattern. gcc/testsuite/ChangeLog: * gcc.dg/pr108757-1.c: New test. * gcc.dg/pr108757-2.c: New test. * gcc.dg/pr108757.h: New test. gcc/match.pd | 80 +++++++++++++ gcc/testsuite/gcc.dg/pr108757-1.c | 18 +++ gcc/testsuite/gcc.dg/pr108757-2.c | 19 ++++ gcc/testsuite/gcc.dg/pr108757.h | 233 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 350 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/pr108757-1.c create mode 100644 gcc/testsuite/gcc.dg/pr108757-2.c create mode 100644 gcc/testsuite/gcc.dg/pr108757.h bisect found first bad commit