From patchwork Sun Jun 9 01:20:19 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Iyer, Balaji V" X-Patchwork-Id: 249998 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]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "localhost", Issuer "www.qmailtoaster.com" (not verified)) by ozlabs.org (Postfix) with ESMTPS id 6D8682C0096 for ; Sun, 9 Jun 2013 11:20:46 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:content-type:mime-version; q=dns; s=default; b=ZI2ZFaEp2oMtP+fSvmDY2z9yIA+lW6gYTuLqXtoRAUYy1GiN1m +AgrAPdBGRVlW6Eh3aJH6BEfx5YcBAd3DlLM1cPshtGmp+IW+Y+PaJIya79UbYcJ 1p39guLnqQSL83dycHtI6tncVpreJxdGWIL6KFqRZrjKV3+MW/pNqGc14= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:content-type:mime-version; s= default; bh=onWouSegS6MMjw+kBM2aKfcy95E=; b=IM/0atZ5zP/p++CwwvOh CLIC5Rok9/Ft7AJdEElisFotoHmnEb0+R78wx9MGBKADr+ZMWj326Es9o6f0D5aw AY4CvJWVjvInYqrzQuuUeZtO4Xtu3+Qn3n7x8XcbIGpOy5gkTeUHBzem1P8Qfmli GL72pmFa5Qzw42ikqFuhcR4= Received: (qmail 8288 invoked by alias); 9 Jun 2013 01:20:38 -0000 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 Received: (qmail 8243 invoked by uid 89); 9 Jun 2013 01:20:34 -0000 X-Spam-SWARE-Status: No, score=-6.4 required=5.0 tests=AWL, BAYES_00, RCVD_IN_HOSTKARMA_W, RCVD_IN_HOSTKARMA_WL, RP_MATCHES_RCVD, SPF_PASS, TW_TM autolearn=ham version=3.3.1 X-Spam-User: qpsmtpd, 2 recipients Received: from mga02.intel.com (HELO mga02.intel.com) (134.134.136.20) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Sun, 09 Jun 2013 01:20:32 +0000 Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga101.jf.intel.com with ESMTP; 08 Jun 2013 18:20:20 -0700 X-ExtLoop1: 1 Received: from fmsmsx106.amr.corp.intel.com ([10.19.9.37]) by orsmga001.jf.intel.com with ESMTP; 08 Jun 2013 18:20:20 -0700 Received: from fmsmsx101.amr.corp.intel.com ([169.254.1.135]) by FMSMSX106.amr.corp.intel.com ([169.254.6.10]) with mapi id 14.03.0123.003; Sat, 8 Jun 2013 18:20:20 -0700 From: "Iyer, Balaji V" To: "gcc-patches@gcc.gnu.org" CC: Jakub Jelinek , "mpolacek@gcc.gnu.org" Subject: [PATCH] Fix for PR c/57563 Date: Sun, 9 Jun 2013 01:20:19 +0000 Message-ID: MIME-Version: 1.0 X-Virus-Found: No Hello Everyone, Attached, please find a patch that will fix the bug reported in PR 57563. There are a couple issues that went wrong. First, in the test case, we have a double multiplied to a double. When -std=c99 flag is used, they get converted to long double. The way to fix this is to add a type cast to the array notation to the same type as identity variable and thus they will all be double. The second issue, was that a sec_reduce_mutating function takes in the address of a "mutating variable" (i.e. the variable that will hold the result), the array notation and a function pointer. For example, for the following code: int a[10], x = 0; void function_name (int *p, int r); __sec_reduce_mutating (&x, a[0:10], function_name); __sec_reduce_mutating should be converted to: for (ii =0; ii < 10; ii++) function_name (&x, a[ii]); In the test case I was not representing this correctly (as shown in the conversion above), but just computing the value that the function should do, thus making the test flaky. I made this fix in the test case. The other advantage of this change is that, in future I can change the what the function does (maybe with #defines and have multiple checks for different function body) and I don't have to change a lot of things. I tried the patch on x86 and x86_64 and it works fine. I am assuming -m32 on x86_64 should have the same behavior as x86. So, is this OK for trunk? Here are the Changelog entries: gcc/c/ChangeLog 2013-06-08 Balaji V. Iyer * c-array-notation.c (fix_builtin_array_notation_fn): Added a cast for all the usage of function parameter to match the identity var. gcc/testsuite/ChangeLog 2013-06-08 Balaji V. Iyer PR c/57563 * c-c++-common/cilk-plus/AN/builtin_fn_mutating.c (main): Fixed a bug in how we check __sec_reduce_mutating function's result. Thanks, Balaji V. Iyer. diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index 5fbb31f..caf2146 100644 Binary files a/gcc/c/ChangeLog and b/gcc/c/ChangeLog differ diff --git a/gcc/c/c-array-notation.c b/gcc/c/c-array-notation.c index b1040da..1914a24 100644 --- a/gcc/c/c-array-notation.c +++ b/gcc/c/c-array-notation.c @@ -133,7 +133,7 @@ fix_builtin_array_notation_fn (tree an_builtin_fn, tree *new_var) bool **count_down, **array_vector; location_t location = UNKNOWN_LOCATION; tree loop_with_init = alloc_stmt_list (); - + tree new_comp_expr = NULL_TREE, identity_expr = NULL_TREE; enum built_in_function an_type = is_cilkplus_reduce_builtin (CALL_EXPR_FN (an_builtin_fn)); if (an_type == BUILT_IN_NONE) @@ -483,10 +483,12 @@ fix_builtin_array_notation_fn (tree an_builtin_fn, tree *new_var) new_yes_expr = build_modify_expr (location, *new_var, TREE_TYPE (*new_var), NOP_EXPR, location, func_parm, TREE_TYPE (*new_var)); - new_expr = build_conditional_expr - (location, - build2 (LT_EXPR, TREE_TYPE (*new_var), *new_var, func_parm), false, - new_yes_expr, TREE_TYPE (*new_var), new_no_expr, TREE_TYPE (*new_var)); + new_comp_expr = build2 (LT_EXPR, TREE_TYPE (*new_var), *new_var, + build_c_cast (location, TREE_TYPE (*new_var), + func_parm)); + new_expr = build_conditional_expr (location, new_comp_expr, false, + new_yes_expr, TREE_TYPE (*new_var), + new_no_expr, TREE_TYPE (*new_var)); break; case BUILT_IN_CILKPLUS_SEC_REDUCE_MIN: if (TYPE_MAX_VALUE (new_var_type)) @@ -503,10 +505,12 @@ fix_builtin_array_notation_fn (tree an_builtin_fn, tree *new_var) new_yes_expr = build_modify_expr (location, *new_var, TREE_TYPE (*new_var), NOP_EXPR, location, func_parm, TREE_TYPE (*new_var)); - new_expr = build_conditional_expr - (location, - build2 (GT_EXPR, TREE_TYPE (*new_var), *new_var, func_parm), false, - new_yes_expr, TREE_TYPE (*new_var), new_no_expr, TREE_TYPE (*new_var)); + new_comp_expr = build2 (GT_EXPR, TREE_TYPE (*new_var), *new_var, + build_c_cast (location, TREE_TYPE (*new_var), + func_parm)); + new_expr = build_conditional_expr (location, new_comp_expr, false, + new_yes_expr, TREE_TYPE (*new_var), + new_no_expr, TREE_TYPE (*new_var)); break; case BUILT_IN_CILKPLUS_SEC_REDUCE_MAX_IND: new_var_init = build_modify_expr @@ -551,12 +555,13 @@ fix_builtin_array_notation_fn (tree an_builtin_fn, tree *new_var) append_to_statement_list (new_no_ind, &new_no_list); append_to_statement_list (new_no_expr, &new_no_list); + new_comp_expr = + build2 (LE_EXPR, TREE_TYPE (array_ind_value), array_ind_value, + build_c_cast (location, TREE_TYPE (array_ind_value), + func_parm)); new_expr = build_conditional_expr - (location, - build2 (LE_EXPR, TREE_TYPE (array_ind_value), array_ind_value, - func_parm), - false, - new_yes_list, TREE_TYPE (*new_var), new_no_list, TREE_TYPE (*new_var)); + (location, new_comp_expr, false, new_yes_list, TREE_TYPE (*new_var), + new_no_list, TREE_TYPE (*new_var)); break; case BUILT_IN_CILKPLUS_SEC_REDUCE_MIN_IND: new_var_init = build_modify_expr @@ -601,24 +606,34 @@ fix_builtin_array_notation_fn (tree an_builtin_fn, tree *new_var) append_to_statement_list (new_no_ind, &new_no_list); append_to_statement_list (new_no_expr, &new_no_list); + new_comp_expr = + build2 (GE_EXPR, TREE_TYPE (array_ind_value), array_ind_value, + build_c_cast (location, TREE_TYPE (array_ind_value), + func_parm)); new_expr = build_conditional_expr - (location, - build2 (GE_EXPR, TREE_TYPE (array_ind_value), array_ind_value, - func_parm), - false, - new_yes_list, TREE_TYPE (*new_var), new_no_list, TREE_TYPE (*new_var)); + (location, new_comp_expr, false, new_yes_list, TREE_TYPE (*new_var), + new_no_list, TREE_TYPE (*new_var)); break; case BUILT_IN_CILKPLUS_SEC_REDUCE: new_var_init = build_modify_expr (location, *new_var, TREE_TYPE (*new_var), NOP_EXPR, location, identity_value, new_var_type); - new_call_expr = build_call_expr (call_fn, 2, *new_var, func_parm); + new_call_expr = build_call_expr (call_fn, 2, *new_var, + build_c_cast (location, new_var_type, + func_parm)); new_expr = build_modify_expr (location, *new_var, TREE_TYPE (*new_var), NOP_EXPR, location, new_call_expr, TREE_TYPE (*new_var)); break; case BUILT_IN_CILKPLUS_SEC_REDUCE_MUTATING: - new_expr = build_call_expr (call_fn, 2, identity_value, func_parm); + if (TREE_CODE (TREE_TYPE (identity_value)) == POINTER_TYPE) + new_var_type = TREE_TYPE (TREE_TYPE (identity_value)); + identity_expr = TREE_OPERAND (identity_value, 0); + identity_value = build_fold_addr_expr (identity_expr); + TREE_USED (identity_expr) = 1; + new_expr = build_call_expr (call_fn, 2, identity_value, + build_c_cast (location, new_var_type, + func_parm)); break; default: gcc_unreachable (); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index b8fe362..6c6c50c 100644 Binary files a/gcc/testsuite/ChangeLog and b/gcc/testsuite/ChangeLog differ diff --git a/gcc/testsuite/c-c++-common/cilk-plus/AN/builtin_fn_mutating.c b/gcc/testsuite/c-c++-common/cilk-plus/AN/builtin_fn_mutating.c index 6635565..7c194c2 100644 --- a/gcc/testsuite/c-c++-common/cilk-plus/AN/builtin_fn_mutating.c +++ b/gcc/testsuite/c-c++-common/cilk-plus/AN/builtin_fn_mutating.c @@ -44,11 +44,11 @@ int main(void) max_value = array3[0] * array4[0]; for (ii = 0; ii < 10; ii++) if (array3[ii] * array4[ii] > max_value) { - max_value = array3[ii] * array4[ii]; max_index = ii; } - + for (ii = 0; ii < 10; ii++) + my_func (&max_value, array3[ii] * array4[ii]); #if HAVE_IO for (ii = 0; ii < 10; ii++)