http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60418
--- Comment #21 from Jakub Jelinek <jakub at gcc dot gnu.org> --- Can you try if sorting on gimple_uid would help this or not? I think it would be something like: --- gcc/tree-ssa-reassoc.c.jj 2014-02-19 06:59:35.000000000 +0100 +++ gcc/tree-ssa-reassoc.c 2014-03-10 17:26:06.707683626 +0100 @@ -506,11 +506,17 @@ sort_by_operand_rank (const void *pa, co } /* Lastly, make sure the versions that are the same go next to each - other. We use SSA_NAME_VERSION because it's stable. */ + other. Prefer gimple_uid of def stmt, fall back to SSA_NAME_VERSION + if more stmts have the same uid. */ if ((oeb->rank - oea->rank == 0) && TREE_CODE (oea->op) == SSA_NAME && TREE_CODE (oeb->op) == SSA_NAME) { + unsigned int uida = gimple_uid (SSA_NAME_DEF_STMT (oea->op)); + unsigned int uidb = gimple_uid (SSA_NAME_DEF_STMT (oeb->op)); + if (uida && uidb && uida != uidb) + return uidb - uida; + if (SSA_NAME_VERSION (oeb->op) != SSA_NAME_VERSION (oea->op)) return SSA_NAME_VERSION (oeb->op) - SSA_NAME_VERSION (oea->op); else (make check RUNTESTFLAGS='--target_board=unix\{-m32,-m64\} dg.exp=*reassoc* tree-ssa.exp=*reassoc*' with it still passes, haven't tested it more than that).