On Thu, 13 Mar 2025, Konstantinos Eleftheriou wrote: > Testcases for match.pd patterns > `((a ^ b) & c) cmp d | a != b -> (0 cmp d | a != b)` and > `(a ^ b) cmp c | a != b -> (0 cmp c | a != b)` were failing on some targets, > like PowerPC. > > This patch adds an implemenetation for the optimization in reassoc. Doing so, > we can now handle cases where the related conditions appear in an AND > expression too. Also, we can optimize cases where we have intermediate > expressions between the related ones in the AND/OR expression on some targets. > This is not handled on targets like PowerPC, where each condition of the > AND/OR expression is placed into a different basic block. > > Bootstrapped/regtested on x86 and AArch64. > > PR tree-optimization/116860 > > gcc/ChangeLog: > > * tree-ssa-reassoc.cc (solve_expr): New function. > (find_terminal_nodes): New function. > (get_terminal_nodes): New function. > (optimize_cmp_xor_exprs): New function. > (optimize_range_tests): Call optimize_cmp_xor_exprs. > > gcc/testsuite/ChangeLog: > > * gcc.dg/tree-ssa/fold-xor-and-or.c: Renamed to fold-xor-and-or-1.c. > * gcc.dg/tree-ssa/fold-xor-and-or-1.c: > Add new test cases, remove logical-op-non-short-circuit=1. > * gcc.dg/tree-ssa/fold-xor-or.c: Likewise. > * gcc.dg/tree-ssa/fold-xor-and-or-2.c: New test.
Sniping from the sideline, sorry: Please don't modify existing tests, just add new tests (in new files) unless there's something wrong with the existing test. (I.e. dropping --param logical-op-non-short-circuit=1 is fine if you fixed the general case, but adding or removing code or renaming the test, isn't.) brgds, H-P