From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3545 invoked by alias); 24 Apr 2012 08:31:13 -0000 Received: (qmail 3535 invoked by uid 22791); 24 Apr 2012 08:31:10 -0000 X-SWARE-Spam-Status: No, hits=-4.3 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00,KHOP_THREADED,TW_TM X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 24 Apr 2012 08:30:55 +0000 From: "ktietz at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/33512] Simple bitwise simplification missed Date: Tue, 24 Apr 2012 08:31:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Keywords: missed-optimization, patch, TREE X-Bugzilla-Severity: enhancement X-Bugzilla-Who: ktietz at gcc dot gnu.org X-Bugzilla-Status: REOPENED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: pinskia at gcc dot gnu.org X-Bugzilla-Target-Milestone: 4.8.0 X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2012-04/txt/msg02093.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33512 --- Comment #14 from Kai Tietz 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.