https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64910
--- Comment #1 from Jeffrey A. Law <law at redhat dot com> --- Here's the hack that I was playing with which shows the better code sequence: diff --git a/gcc/tree-ssa-reassoc.c b/gcc/tree-ssa-reassoc.c index 9952222..4515a4d 100644 --- a/gcc/tree-ssa-reassoc.c +++ b/gcc/tree-ssa-reassoc.c @@ -3476,6 +3476,18 @@ swap_ops_for_binary_stmt (vec<operand_entry_t> ops, oe1->op = temp.op; oe1->rank = temp.rank; } + else if (TREE_CODE (oe1->op) != INTEGER_CST + && TREE_CODE (oe2->op) != INTEGER_CST + && TREE_CODE (oe3->op) == INTEGER_CST) + { + struct operand_entry temp = *oe3; + oe3->op = oe2->op; + oe3->rank = oe2->rank; + oe2->op = oe1->op; + oe2->rank = oe1->rank; + oe1->op = temp.op; + oe1->rank = temp.rank; + } } /* If definition of RHS1 or RHS2 dominates STMT, return the later of those