http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33512
--- Comment #14 from Kai Tietz <ktietz at gcc dot gnu.org> 2012-04-24 08:30:49 UTC --- Hmm, I have right now in my tree Index: tree-ssa-forwprop.c =================================================================== --- tree-ssa-forwprop.c (revision 186753) +++ tree-ssa-forwprop.c (working copy) @@ -1912,17 +1912,25 @@ /* Simplify (A & B) OP0 (C & B) to (A OP0 C) & B. */ if (def1_code == def2_code - && def1_code == BIT_AND_EXPR - && operand_equal_for_phi_arg_p (gimple_assign_rhs2 (def1), - gimple_assign_rhs2 (def2))) + && def1_code == BIT_AND_EXPR) { - tree b = gimple_assign_rhs2 (def1); - tree a = def1_arg1; - tree c = def2_arg1; - tree inner = fold_build2 (code, TREE_TYPE (arg2), a, c); + tree inner, a = NULL_TREE, b = NULL_TREE, c = NULL_TREE; + + if (operand_equal_for_phi_arg_p (def1_arg2, def2_arg2)) + { b = def1_arg2; a = def1_arg1; c = def2_arg1; } + else if (operand_equal_for_phi_arg_p (def1_arg1, def2_arg1)) + { b = def1_arg1; a = def1_arg2; c = def2_arg2; } + else if (operand_equal_for_phi_arg_p (def1_arg1, def2_arg2)) + { b = def1_arg1; a = def1_arg2; c = def2_arg1; } + else if (operand_equal_for_phi_arg_p (def1_arg2, def2_arg1)) + { b = def1_arg2; a = def1_arg1; c = def2_arg2; } + if (a && c) + inner = fold_build2 (code, TREE_TYPE (arg2), a, c); + if (!a || !b || !c) + ; /* If A OP0 C (this usually means C is the same as A) is 0 then fold it down correctly. */ - if (integer_zerop (inner)) + else if (integer_zerop (inner)) { gimple_assign_set_rhs_from_tree (gsi, inner); update_stmt (stmt); It has the advantage of handling also cases for (A & B) OP0 (C & B) to (A OP0 C) & B, (B & A) OP0 (C & B) to (A OP0 C) & B, (A & B) OP0 (B & C) to (A OP0 C) & B, and (B & A) OP0 (B & C) to (A OP0 C) & B. It bootstraps fine.