This is an update to my very old patch with the review comments addressed. Bootstrapped and regtested x86_64-redhat-linux, ppc64le-redhat-linux and s390x-redhat-linux.
v1: https://gcc.gnu.org/pipermail/gcc-patches/2020-June/548785.html Changes in v2: * Disable PHI biasing in the early pass instance in a separate patch. * Replace s390-specific tests with the generic tree-ssa ones. * Replace the fragile (op_rank & PHI_LOOP_BIAS) test with auto_bitmap biased_names. The review suggestion was to rather check whether op is defined by a loop-carried phi, but this would allow detecting only single assingments, and not assignment chains. Another alternative that would make the check less fragile was to use saturating addition in order to prevent overflows into the PHI_LOOP_BIAS bit, but auto_bitmap of SSA_NAMEs allows graceful processing of large basic blocks, and its memory overhead looks acceptable. * Restructure the code to make it a bit more readable. The overall logic is the same as in v1. I considered implementing an idea from [1], more specifically, detecting single-use chains in is_phi_for_stmt() so that swap_ops_for_binary_stmt() shifts the corresponding operand towards the end. These two functions actually seem to serve a very related purpose. However, for single-use chain detection we would still need to recursively traverse SSA_NAME_DEF_STMTs of operands, which propagate_rank() and friends already do. So this would not have resulted in a significant code simplification. [1] https://gcc.gnu.org/pipermail/gcc-patches/2020-June/549149.html Ilya Leoshkevich (3): reassoc: Do not bias loop-carried PHIs early reassoc: Propagate PHI_LOOP_BIAS along single uses reassoc: Test rank biasing gcc/passes.def | 4 +- gcc/testsuite/gcc.dg/tree-ssa/reassoc-46.c | 7 ++ gcc/testsuite/gcc.dg/tree-ssa/reassoc-46.h | 33 ++++++ gcc/testsuite/gcc.dg/tree-ssa/reassoc-47.c | 9 ++ gcc/testsuite/gcc.dg/tree-ssa/reassoc-48.c | 9 ++ gcc/testsuite/gcc.dg/tree-ssa/reassoc-49.c | 11 ++ gcc/testsuite/gcc.dg/tree-ssa/reassoc-50.c | 10 ++ gcc/testsuite/gcc.dg/tree-ssa/reassoc-51.c | 11 ++ gcc/tree-ssa-reassoc.c | 113 ++++++++++++++------- 9 files changed, 170 insertions(+), 37 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/reassoc-46.c create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/reassoc-46.h create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/reassoc-47.c create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/reassoc-48.c create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/reassoc-49.c create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/reassoc-50.c create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/reassoc-51.c -- 2.31.1