From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3328 invoked by alias); 13 Jul 2011 07:34:03 -0000 Received: (qmail 3319 invoked by uid 22791); 13 Jul 2011 07:34:02 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW X-Spam-Check-By: sourceware.org Received: from mail-qy0-f182.google.com (HELO mail-qy0-f182.google.com) (209.85.216.182) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 13 Jul 2011 07:33:48 +0000 Received: by mail-qy0-f182.google.com with SMTP id 38so3380865qyk.20 for ; Wed, 13 Jul 2011 00:33:48 -0700 (PDT) MIME-Version: 1.0 Received: by 10.229.247.203 with SMTP id md11mr628173qcb.268.1310542428289; Wed, 13 Jul 2011 00:33:48 -0700 (PDT) Received: by 10.229.38.195 with HTTP; Wed, 13 Jul 2011 00:33:48 -0700 (PDT) Date: Wed, 13 Jul 2011 07:35:00 -0000 Message-ID: Subject: [patch 4/8 tree-optimization]: Bitwise or logic for fold_binary_loc. From: Kai Tietz To: GCC Patches Cc: Richard Guenther Content-Type: text/plain; charset=ISO-8859-1 X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org X-SW-Source: 2011-07/txt/msg00988.txt.bz2 Hello, This patch adds support to fold_binary_loc for one-bit precision typed bitwise-or expression. ChangeLog 2011-07-13 Kai Tietz * fold-const.c (fold_binary_loc): Add support for one-bit bitwise-or optimizeation. Bootstrapped and regression tested with prior patches of this series for x86_64-pc-linux-gnu. Ok for apply? Regards, Kai Index: gcc/gcc/fold-const.c =================================================================== --- gcc.orig/gcc/fold-const.c 2011-07-13 08:23:29.000000000 +0200 +++ gcc/gcc/fold-const.c 2011-07-13 08:59:04.011620200 +0200 @@ -10688,6 +10688,52 @@ fold_binary_loc (location_t loc, return omit_one_operand_loc (loc, type, t1, arg0); } + if (TYPE_PRECISION (type) == 1 && INTEGRAL_TYPE_P (type)) + { + /* If arg0 is constant zero, drop it. */ + if (TREE_CODE (arg0) == INTEGER_CST && integer_zerop (arg0)) + return non_lvalue_loc (loc, fold_convert_loc (loc, type, arg1)); + if (TREE_CODE (arg0) == INTEGER_CST && ! integer_zerop (arg0)) + return omit_one_operand_loc (loc, type, arg0, arg1); + + /* !X | X is always true. ~X | X is always true. */ + if ((TREE_CODE (arg0) == TRUTH_NOT_EXPR + || TREE_CODE (arg0) == BIT_NOT_EXPR) + && operand_equal_p (TREE_OPERAND (arg0, 0), arg1, 0)) + return omit_one_operand_loc (loc, type, integer_one_node, arg1); + /* X | !X is always true. X | ~X is always true. */ + if ((TREE_CODE (arg1) == TRUTH_NOT_EXPR + || TREE_CODE (arg1) == BIT_NOT_EXPR) + && operand_equal_p (arg0, TREE_OPERAND (arg1, 0), 0)) + return omit_one_operand_loc (loc, type, integer_one_node, arg0); + + /* (X & !Y) | (!X & Y) is X ^ Y */ + if (TREE_CODE (arg0) == BIT_AND_EXPR + && TREE_CODE (arg1) == BIT_AND_EXPR) + { + tree a0, a1, l0, l1, n0, n1; + + a0 = fold_convert_loc (loc, type, TREE_OPERAND (arg1, 0)); + a1 = fold_convert_loc (loc, type, TREE_OPERAND (arg1, 1)); + + l0 = fold_convert_loc (loc, type, TREE_OPERAND (arg0, 0)); + l1 = fold_convert_loc (loc, type, TREE_OPERAND (arg0, 1)); + + n0 = fold_build1_loc (loc, TRUTH_NOT_EXPR, type, l0); + n1 = fold_build1_loc (loc, TRUTH_NOT_EXPR, type, l1); + + if ((operand_equal_p (n0, a0, 0) + && operand_equal_p (n1, a1, 0)) + || (operand_equal_p (n0, a1, 0) + && operand_equal_p (n1, a0, 0))) + return fold_build2_loc (loc, BIT_XOR_EXPR, type, l0, n1); + } + + tem = fold_truth_andor (loc, code, type, arg0, arg1, op0, op1); + if (tem) + return tem; + } + /* Canonicalize (X & C1) | C2. */ if (TREE_CODE (arg0) == BIT_AND_EXPR && TREE_CODE (arg1) == INTEGER_CST