From patchwork Tue Jun 28 10:04:26 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kai Tietz X-Patchwork-Id: 102345 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id B21DCB6F6B for ; Tue, 28 Jun 2011 20:04:48 +1000 (EST) Received: (qmail 23356 invoked by alias); 28 Jun 2011 10:04:47 -0000 Received: (qmail 23343 invoked by uid 22791); 28 Jun 2011 10:04:46 -0000 X-SWARE-Spam-Status: No, hits=-6.8 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, SPF_HELO_PASS, TW_TM, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx4-phx2.redhat.com (HELO mx4-phx2.redhat.com) (209.132.183.25) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 28 Jun 2011 10:04:27 +0000 Received: from mail06.corp.redhat.com (zmail06.collab.prod.int.phx2.redhat.com [10.5.5.45]) by mx4-phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p5SA4QoH002569; Tue, 28 Jun 2011 06:04:26 -0400 Date: Tue, 28 Jun 2011 06:04:26 -0400 (EDT) From: Kai Tietz To: Richard Guenther Cc: gcc-patches@gcc.gnu.org Message-ID: <940068552.809908.1309255466404.JavaMail.root@zmail06.collab.prod.int.phx2.redhat.com> In-Reply-To: Subject: Re: [patch tree-optimization]: Try to sink type-casts for binary and/or/xor operations MIME-Version: 1.0 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Ok, moved code out of special case for addresses. Bootstrapped for x86_64-pc-linux-gnu. Patch ok for apply? Regards, Kai Index: gcc-head/gcc/tree-ssa-forwprop.c =================================================================== --- gcc-head.orig/gcc/tree-ssa-forwprop.c +++ gcc-head/gcc/tree-ssa-forwprop.c @@ -1676,16 +1676,61 @@ simplify_bitwise_binary (gimple_stmt_ite } } + /* Try to fold (type) X op CST -> (type) (X op ((type-x) CST)). */ + if (TREE_CODE (arg2) == INTEGER_CST + && CONVERT_EXPR_CODE_P (def1_code) + && INTEGRAL_TYPE_P (def1_arg1) + && int_fits_type_p (arg2, TREE_TYPE (def1_arg1))) + { + gimple newop; + tree tem = create_tmp_reg (TREE_TYPE (def1_arg1), NULL); + newop = + gimple_build_assign_with_ops (code, tem, def1_arg1, + fold_convert_loc (gimple_location (stmt), + TREE_TYPE (def1_arg1), + arg2)); + tem = make_ssa_name (tem, newop); + gimple_assign_set_lhs (newop, tem); + gsi_insert_before (gsi, newop, GSI_SAME_STMT); + gimple_assign_set_rhs_with_ops_1 (gsi, NOP_EXPR, + tem, NULL_TREE, NULL_TREE); + update_stmt (gsi_stmt (*gsi)); + return true; + } + + /* Try to fold CST op (type) X -> (type) (((type-x) CST) op X). */ + if (TREE_CODE (arg1) == INTEGER_CST + && CONVERT_EXPR_CODE_P (def2_code) + && INTEGRAL_TYPE_P (def2_arg1) + && int_fits_type_p (arg1, TREE_TYPE (def2_arg1))) + { + gimple newop; + tree tem = create_tmp_reg (TREE_TYPE (def2_arg1), NULL); + newop = + gimple_build_assign_with_ops (code, tem, def2_arg1, + fold_convert_loc (gimple_location (stmt), + TREE_TYPE (def2_arg1), + arg1)); + tem = make_ssa_name (tem, newop); + gimple_assign_set_lhs (newop, tem); + gsi_insert_before (gsi, newop, GSI_SAME_STMT); + gimple_assign_set_rhs_with_ops_1 (gsi, NOP_EXPR, + tem, NULL_TREE, NULL_TREE); + update_stmt (gsi_stmt (*gsi)); + return true; + } + /* For bitwise binary operations apply operand conversions to the binary operation result instead of to the operands. This allows to combine successive conversions and bitwise binary operations. */ if (CONVERT_EXPR_CODE_P (def1_code) && CONVERT_EXPR_CODE_P (def2_code) && types_compatible_p (TREE_TYPE (def1_arg1), TREE_TYPE (def2_arg1)) - /* Make sure that the conversion widens the operands or that it - changes the operation to a bitfield precision. */ + /* Make sure that the conversion widens the operands, or has same + precision, or that it changes the operation to a bitfield + precision. */ && ((TYPE_PRECISION (TREE_TYPE (def1_arg1)) - < TYPE_PRECISION (TREE_TYPE (arg1))) + <= TYPE_PRECISION (TREE_TYPE (arg1))) || (GET_MODE_CLASS (TYPE_MODE (TREE_TYPE (arg1))) != MODE_INT) || (TYPE_PRECISION (TREE_TYPE (arg1))