[Bug tree-optimization/96779] Failure to optimize comparison of negative version of self
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96779 Andrew Pinski changed: What|Removed |Added Target Milestone|--- |12.0
[Bug tree-optimization/96779] Failure to optimize comparison of negative version of self
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96779 Jeffrey A. Law changed: What|Removed |Added Resolution|--- |FIXED CC||law at gcc dot gnu.org Status|ASSIGNED|RESOLVED --- Comment #7 from Jeffrey A. Law --- Should be fixed by Navid's patch on the trunk.
[Bug tree-optimization/96779] Failure to optimize comparison of negative version of self
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96779 --- Comment #6 from CVS Commits --- The master branch has been updated by Jeff Law : https://gcc.gnu.org/g:e888bea2384a0d8d29a6545c4f57f41cb49df0a6 commit r12-5458-ge888bea2384a0d8d29a6545c4f57f41cb49df0a6 Author: Navid Rahimi Date: Mon Nov 22 19:46:17 2021 -0500 Re: [PATCH] PR tree-optimization/96779 Adding a missing pattern to match.pd PR tree-optimization/96779 gcc/ * match.pd (-x == x) -> (x == 0): New optimization. gcc/testsuite * gcc.dg/tree-ssa/pr96779.c: Testcase for this optimization. * gcc.dg/tree-ssa/pr96779-disabled.c: Testcase for this optimization when -fwrapv passed.
[Bug tree-optimization/96779] Failure to optimize comparison of negative version of self
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96779 --- Comment #5 from navidrahimi --- And this is the behavior of different compilers for this optimization: https://compiler-explorer.com/z/ahdEzxxTv
[Bug tree-optimization/96779] Failure to optimize comparison of negative version of self
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96779 navidrahimi changed: What|Removed |Added CC||navidrahimi at microsoft dot com --- Comment #4 from navidrahimi --- Hi Andrew, I just used your code and added a check to check whether the type is wrapping type: (for cmp (eq ne) (simplify (cmp:c @0 (negate @0)) (if (ANY_INTEGRAL_TYPE_P (TREE_TYPE (@0)) && !TYPE_OVERFLOW_WRAPS (type)) (cmp:c @0 { build_zero_cst (TREE_TYPE(@0)); }) This should work.
[Bug tree-optimization/96779] Failure to optimize comparison of negative version of self
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96779 --- Comment #3 from Andrew Pinski --- (In reply to Andrew Pinski from comment #2) > This is simple, I will take. > (for cmp (eq ne) > (simplify > (cmp:c @0 (negate @0)) >(if (ANY_INTEGRAL_TYPE_P (TREE_TYPE (@0))) > (cmp:c @0 { build_zero_cst (TREE_TYPE(@0)); }) > > Should be enough. But it is wrong for wrapping types. For wrapping types: -a == a -> (a << 1) == a or (a + a) == 0 But this is worse on targets which have a pattern for -a CMP a (hint aarch64). So for wrapping types keep the -a == a is the best I think.
[Bug tree-optimization/96779] Failure to optimize comparison of negative version of self
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96779 Andrew Pinski changed: What|Removed |Added Status|NEW |ASSIGNED Keywords||easyhack Assignee|unassigned at gcc dot gnu.org |pinskia at gcc dot gnu.org --- Comment #2 from Andrew Pinski --- This is simple, I will take. (for cmp (eq ne) (simplify (cmp:c @0 (negate @0)) (if (ANY_INTEGRAL_TYPE_P (TREE_TYPE (@0))) (cmp:c @0 { build_zero_cst (TREE_TYPE(@0)); }) Should be enough.
[Bug tree-optimization/96779] Failure to optimize comparison of negative version of self
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96779 Richard Biener changed: What|Removed |Added Last reconfirmed||2020-08-25 Ever confirmed|0 |1 Status|UNCONFIRMED |NEW --- Comment #1 from Richard Biener --- Confirmed.