From patchwork Fri Mar 25 11:52:54 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Froyd X-Patchwork-Id: 88377 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 7C3911007D2 for ; Fri, 25 Mar 2011 22:53:10 +1100 (EST) Received: (qmail 8526 invoked by alias); 25 Mar 2011 11:53:04 -0000 Received: (qmail 8517 invoked by uid 22791); 25 Mar 2011 11:53:02 -0000 X-SWARE-Spam-Status: No, hits=-1.7 required=5.0 tests=AWL, BAYES_00, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mail.codesourcery.com (HELO mail.codesourcery.com) (38.113.113.100) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 25 Mar 2011 11:52:58 +0000 Received: (qmail 22842 invoked from network); 25 Mar 2011 11:52:56 -0000 Received: from unknown (HELO codesourcery.com) (froydnj@127.0.0.2) by mail.codesourcery.com with ESMTPA; 25 Mar 2011 11:52:56 -0000 Date: Fri, 25 Mar 2011 07:52:54 -0400 From: Nathan Froyd To: gcc-patches@gcc.gnu.org Subject: [PATCH] small refactoring in fold-const.c Message-ID: <20110325115253.GB31947@nightcrawler> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) X-IsSubscribed: yes 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 The patch below just moves the pattern: x = EXPR_LOCATION (t) if (x == UNKNOWN_LOCATION) x = loc into its own function. Tested on x86_64-unknown-linux-gnu. OK to commit? * fold-const.c (expr_location_or): New function. (fold_truth_not_expr): Call it. diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 9baa9eb..35c1085 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -141,6 +141,15 @@ static tree fold_not_const (const_tree, tree); static tree fold_relational_const (enum tree_code, tree, tree, tree); static tree fold_convert_const (enum tree_code, tree, tree); +/* Return EXPR_LOCATION of T if it is not UNKNOWN_LOCATION. + Otherwise, return LOC. */ + +static location_t +expr_location_or (tree t, location_t loc) +{ + location_t tloc = EXPR_LOCATION (t); + return tloc != UNKNOWN_LOCATION ? tloc : loc; +} /* Similar to protected_set_expr_location, but never modify x in place, if location can and needs to be set, unshare it. */ @@ -3079,23 +3088,15 @@ fold_truth_not_expr (location_t loc, tree arg) return constant_boolean_node (integer_zerop (arg), type); case TRUTH_AND_EXPR: - loc1 = EXPR_LOCATION (TREE_OPERAND (arg, 0)); - loc2 = EXPR_LOCATION (TREE_OPERAND (arg, 1)); - if (loc1 == UNKNOWN_LOCATION) - loc1 = loc; - if (loc2 == UNKNOWN_LOCATION) - loc2 = loc; + loc1 = expr_location_or (TREE_OPERAND (arg, 0), loc); + loc2 = expr_location_or (TREE_OPERAND (arg, 1), loc); return build2_loc (loc, TRUTH_OR_EXPR, type, invert_truthvalue_loc (loc1, TREE_OPERAND (arg, 0)), invert_truthvalue_loc (loc2, TREE_OPERAND (arg, 1))); case TRUTH_OR_EXPR: - loc1 = EXPR_LOCATION (TREE_OPERAND (arg, 0)); - loc2 = EXPR_LOCATION (TREE_OPERAND (arg, 1)); - if (loc1 == UNKNOWN_LOCATION) - loc1 = loc; - if (loc2 == UNKNOWN_LOCATION) - loc2 = loc; + loc1 = expr_location_or (TREE_OPERAND (arg, 0), loc); + loc2 = expr_location_or (TREE_OPERAND (arg, 1), loc); return build2_loc (loc, TRUTH_AND_EXPR, type, invert_truthvalue_loc (loc1, TREE_OPERAND (arg, 0)), invert_truthvalue_loc (loc2, TREE_OPERAND (arg, 1))); @@ -3115,23 +3116,15 @@ fold_truth_not_expr (location_t loc, tree arg) TREE_OPERAND (arg, 1)); case TRUTH_ANDIF_EXPR: - loc1 = EXPR_LOCATION (TREE_OPERAND (arg, 0)); - loc2 = EXPR_LOCATION (TREE_OPERAND (arg, 1)); - if (loc1 == UNKNOWN_LOCATION) - loc1 = loc; - if (loc2 == UNKNOWN_LOCATION) - loc2 = loc; + loc1 = expr_location_or (TREE_OPERAND (arg, 0), loc); + loc2 = expr_location_or (TREE_OPERAND (arg, 1), loc); return build2_loc (loc, TRUTH_ORIF_EXPR, type, invert_truthvalue_loc (loc1, TREE_OPERAND (arg, 0)), invert_truthvalue_loc (loc2, TREE_OPERAND (arg, 1))); case TRUTH_ORIF_EXPR: - loc1 = EXPR_LOCATION (TREE_OPERAND (arg, 0)); - loc2 = EXPR_LOCATION (TREE_OPERAND (arg, 1)); - if (loc1 == UNKNOWN_LOCATION) - loc1 = loc; - if (loc2 == UNKNOWN_LOCATION) - loc2 = loc; + loc1 = expr_location_or (TREE_OPERAND (arg, 0), loc); + loc2 = expr_location_or (TREE_OPERAND (arg, 1), loc); return build2_loc (loc, TRUTH_ANDIF_EXPR, type, invert_truthvalue_loc (loc1, TREE_OPERAND (arg, 0)), invert_truthvalue_loc (loc2, TREE_OPERAND (arg, 1))); @@ -3144,12 +3137,8 @@ fold_truth_not_expr (location_t loc, tree arg) tree arg1 = TREE_OPERAND (arg, 1); tree arg2 = TREE_OPERAND (arg, 2); - loc1 = EXPR_LOCATION (TREE_OPERAND (arg, 1)); - loc2 = EXPR_LOCATION (TREE_OPERAND (arg, 2)); - if (loc1 == UNKNOWN_LOCATION) - loc1 = loc; - if (loc2 == UNKNOWN_LOCATION) - loc2 = loc; + loc1 = expr_location_or (TREE_OPERAND (arg, 1), loc); + loc2 = expr_location_or (TREE_OPERAND (arg, 2), loc); /* A COND_EXPR may have a throw as one operand, which then has void type. Just leave void operands @@ -3162,17 +3151,13 @@ fold_truth_not_expr (location_t loc, tree arg) } case COMPOUND_EXPR: - loc1 = EXPR_LOCATION (TREE_OPERAND (arg, 1)); - if (loc1 == UNKNOWN_LOCATION) - loc1 = loc; + loc1 = expr_location_or (TREE_OPERAND (arg, 1), loc); return build2_loc (loc, COMPOUND_EXPR, type, TREE_OPERAND (arg, 0), invert_truthvalue_loc (loc1, TREE_OPERAND (arg, 1))); case NON_LVALUE_EXPR: - loc1 = EXPR_LOCATION (TREE_OPERAND (arg, 0)); - if (loc1 == UNKNOWN_LOCATION) - loc1 = loc; + loc1 = expr_location_or (TREE_OPERAND (arg, 0), loc); return invert_truthvalue_loc (loc1, TREE_OPERAND (arg, 0)); CASE_CONVERT: @@ -3182,9 +3167,7 @@ fold_truth_not_expr (location_t loc, tree arg) /* ... fall through ... */ case FLOAT_EXPR: - loc1 = EXPR_LOCATION (TREE_OPERAND (arg, 0)); - if (loc1 == UNKNOWN_LOCATION) - loc1 = loc; + loc1 = expr_location_or (TREE_OPERAND (arg, 0), loc); return build1_loc (loc, TREE_CODE (arg), type, invert_truthvalue_loc (loc1, TREE_OPERAND (arg, 0))); @@ -3197,9 +3180,7 @@ fold_truth_not_expr (location_t loc, tree arg) return build1_loc (loc, TRUTH_NOT_EXPR, type, arg); case CLEANUP_POINT_EXPR: - loc1 = EXPR_LOCATION (TREE_OPERAND (arg, 0)); - if (loc1 == UNKNOWN_LOCATION) - loc1 = loc; + loc1 = expr_location_or (TREE_OPERAND (arg, 0), loc); return build1_loc (loc, CLEANUP_POINT_EXPR, type, invert_truthvalue_loc (loc1, TREE_OPERAND (arg, 0)));