While looking into PR 35429, I noticed this small missed optimization. If we have: typedef unsigned int1; int foo(int z0, int1 z1) { return z0 != 0 || z1 != 0; } int foo1(int z0, int1 z1) { return z0 == 0 && z1 == 0; } --- CUT --- Both of those should optimize as int is the same size as unsigned and we are comparing against 0. The same thing should happen with int and long on a ILP32 target.
Author: prathamesh3492 Date: Mon Nov 7 17:32:17 2016 New Revision: 241915 URL: https://gcc.gnu.org/viewcvs?rev=241915&root=gcc&view=rev Log: 2016-11-07 Prathamesh Kulkarni <prathamesh.kulkarni@linaro.org> PR middle-end/35691 * match.pd: Add following two patterns: (x == 0 & y == 0) -> (x | typeof(x)(y)) == 0. (x != 0 | y != 0) -> (x | typeof(x)(y)) != 0. testsuite/ * gcc.dg/pr35691-1.c: New test-case. * gcc.dg/pr35691-4.c: Likewise. Added: trunk/gcc/testsuite/gcc.dg/pr35691-1.c trunk/gcc/testsuite/gcc.dg/pr35691-2.c Modified: trunk/gcc/ChangeLog trunk/gcc/match.pd trunk/gcc/testsuite/ChangeLog
Fixed on targets when LOGICAL_OP_NON_SHORT_CIRCUIT is true. When LOGICAL_OP_NON_SHORT_CIRCUIT is false, the conversion of truth_andif_expr to bit_and_expr doesn't happen and the pattern added in r241915 doesn't get matched.
Author: jakub Date: Fri Sep 22 18:56:23 2017 New Revision: 253107 URL: https://gcc.gnu.org/viewcvs?rev=253107&root=gcc&view=rev Log: PR middle-end/35691 * match.pd: Simplify x == -1 & y == -1 into (x & y) == -1 and x != -1 | y != -1 into (x & y) != -1. * gcc.dg/pr35691-1.c: Use -fdump-tree-forwprop1-details instead of -fdump-tree-forwprop-details in dg-options. * gcc.dg/pr35691-2.c: Likewise. * gcc.dg/pr35691-3.c: New test. * gcc.dg/pr35691-4.c: New test. Added: trunk/gcc/testsuite/gcc.dg/pr35691-3.c trunk/gcc/testsuite/gcc.dg/pr35691-4.c Modified: trunk/gcc/ChangeLog trunk/gcc/match.pd trunk/gcc/testsuite/ChangeLog trunk/gcc/testsuite/gcc.dg/pr35691-1.c trunk/gcc/testsuite/gcc.dg/pr35691-2.c
(In reply to prathamesh3492 from comment #2) > Fixed on targets when LOGICAL_OP_NON_SHORT_CIRCUIT is true. > When LOGICAL_OP_NON_SHORT_CIRCUIT is false, the conversion of > truth_andif_expr to bit_and_expr doesn't happen and the pattern added in > r241915 doesn't get matched. Hmm, I thought ifcombine should do the "right thing" here ...
No, the infrastructure is in tree-ssa-reassoc.c, and I plan to look at it next week.
Author: jakub Date: Tue Sep 26 13:58:11 2017 New Revision: 253201 URL: https://gcc.gnu.org/viewcvs?rev=253201&root=gcc&view=rev Log: PR middle-end/35691 * tree-ssa-reassoc.c (update_range_test): Dump r->exp each time if it is different SSA_NAME. (optimize_range_tests_cmp_bitwise): New function. (optimize_range_tests): Call it. * gcc.dg/pr35691-5.c: New test. * gcc.dg/pr35691-6.c: New test. Added: trunk/gcc/testsuite/gcc.dg/pr35691-5.c trunk/gcc/testsuite/gcc.dg/pr35691-6.c Modified: trunk/gcc/ChangeLog trunk/gcc/testsuite/ChangeLog trunk/gcc/tree-ssa-reassoc.c
Can the bug be marked as resolved?
Yes.