https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121921
--- Comment #7 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The trunk branch has been updated by Andrew Pinski <[email protected]>: https://gcc.gnu.org/g:d3e963d1ccc3500654bec4e2ac94360e864ed343 commit r16-4261-gd3e963d1ccc3500654bec4e2ac94360e864ed343 Author: Andrew Pinski <[email protected]> Date: Sun Oct 5 09:08:15 2025 -0700 match: Extend `-(a ptrdiff b)` pattern by allowing a nop conversion between the neg and ptrdiff [PR121921] When I tried to fix this before I didn't realize there was already a pattern for `-(a ptrdiff b) -> (b ptrdiff a)`, I had added a complex pattern to match `ptr0 - (ptr0 - ptr1)`. But with there being a pattern for `-(a ptrdiff b)`, we just need to extend the pattern to support a nop conversion inbetween the negative and the ptrdiff. Also the check for TYPE_OVERFLOW_UNDEFINED was wrong, in the case of `-(a - b) -> (b - a)`, the check is !TYPE_OVERFLOW_SANITIZED so this pattern should use the same check. Bootstrapped and tested on x86_64-linux-gnu. Changes since v1: * v2: Use the old type of the pointer_diff rather than ssizetype. PR tree-optimization/121921 gcc/ChangeLog: * match.pd (`-(a ptrdiff b)`): Extend for a nop_convert between the neg and ptrdiff. gcc/testsuite/ChangeLog: * gcc.dg/pr121921-1.c: New test. Signed-off-by: Andrew Pinski <[email protected]>
