From patchwork Sun Mar 11 19:55:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Koenig X-Patchwork-Id: 884279 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-474565-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=netcologne.de Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="s6xrmG+o"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3zzsLg15ldz9sQp for ; Mon, 12 Mar 2018 06:56:08 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=qT67McS91AhcTpfQ8ebPLsMGwP5tpeYrDHZYwse+4luBnqWilg fmkHoKsaE1xWN4twj8a2/V+JRrGyils+/gEoocTBtT4CtyPsGqSb28tJuVrpoLkX QOy7MEKv1M9GRAeS5JbnyGaaTLa3KRj7mViy607PL62ByJ/Zu17qShXOQ= 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:to :from:subject:message-id:date:mime-version:content-type; s= default; bh=DXn4cgHosyWJIK2mTwPNlbzILNk=; b=s6xrmG+o3HI5nWMbTamH Zme+RZhgI85TgenptHGDBoPyAlkgl05dQCvq06HVPUqbFB8lcLLPNcQoqBEVFeNj J3xkGnKWR33r4341TE8i9ukmmenZ/RPqxezJpDufkJpYQeJmcfag3EivbrDdqE0v qWou3exDT3JF+DdCGJcVrVI= Received: (qmail 62794 invoked by alias); 11 Mar 2018 19:56:01 -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 62765 invoked by uid 89); 11 Mar 2018 19:56:00 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.9 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_LOW, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=UD:tr, corner, sk:transfo, 57059 X-Spam-User: qpsmtpd, 2 recipients X-HELO: cc-smtpout3.netcologne.de Received: from cc-smtpout3.netcologne.de (HELO cc-smtpout3.netcologne.de) (89.1.8.213) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 11 Mar 2018 19:55:58 +0000 Received: from cc-smtpin1.netcologne.de (cc-smtpin1.netcologne.de [89.1.8.201]) by cc-smtpout3.netcologne.de (Postfix) with ESMTP id 59B8E12801; Sun, 11 Mar 2018 20:55:55 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by cc-smtpin1.netcologne.de (Postfix) with ESMTP id 4DEE511D87; Sun, 11 Mar 2018 20:55:55 +0100 (CET) Received: from [78.35.154.218] (helo=cc-smtpin1.netcologne.de) by localhost with ESMTP (eXpurgate 4.1.9) (envelope-from ) id 5aa589cb-029d-7f0000012729-7f000001b28f-1 for ; Sun, 11 Mar 2018 20:55:55 +0100 Received: from [192.168.178.68] (xdsl-78-35-154-218.netcologne.de [78.35.154.218]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by cc-smtpin1.netcologne.de (Postfix) with ESMTPSA; Sun, 11 Mar 2018 20:55:53 +0100 (CET) To: "fortran@gcc.gnu.org" , gcc-patches From: Thomas Koenig Subject: [patch, fortran] Some more corrections to zero-size simplification Message-ID: <5dcd57ba-c720-c519-221e-44686d98e791@netcologne.de> Date: Sun, 11 Mar 2018 20:55:53 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 Hello world, the attached patch fixes a few corner cases of a corner case in simplification, i.e. empty arrays where array intrinsics can actually have a non-empty array result. Regression-tested. OK for trunk? Regards Thomas 2017-06-11 Thomas Koenig PR fortran/66128 * simplify.c (simplify_transformation): Return default result for empty array argument. (gfc_simplify_all): Remove special-case handling for zerosize. (gfc_simplify_any): Likewise. (gfc_simplify_count): Likewise. (gfc_simplify_iall): Likewise. (gfc_simplify_iany): Likewise. (gfc_simplify_iparity): Likewise. (gfc_simplify_minval): Likewise. (gfc_simplify_maxval): Likewise. (gfc_simplify_norm2): Likewise. (gfc_simplify_product): Likewise. (gfc_simplify_sum): Likewise. 2017-06-11 Thomas Koenig PR fortran/66128 * gfortran.dg/zero_sized_9.f90: New test. Index: simplify.c =================================================================== --- simplify.c (Revision 258433) +++ simplify.c (Arbeitskopie) @@ -689,8 +689,11 @@ simplify_transformation (gfc_expr *array, gfc_expr int init_val, transformational_op op) { gfc_expr *result; + bool size_zero; - if (!is_constant_array_expr (array) + size_zero = gfc_is_size_zero_array (array); + + if (!(is_constant_array_expr (array) || size_zero) || !gfc_is_constant_expr (dim)) return NULL; @@ -703,6 +706,9 @@ simplify_transformation (gfc_expr *array, gfc_expr array->ts.kind, &array->where); init_result_expr (result, init_val, array); + if (size_zero) + return result; + return !dim || array->rank == 1 ? simplify_transformation_to_scalar (result, array, mask, op) : simplify_transformation_to_array (result, array, dim, mask, op, NULL); @@ -976,9 +982,6 @@ gfc_simplify_aint (gfc_expr *e, gfc_expr *k) gfc_expr * gfc_simplify_all (gfc_expr *mask, gfc_expr *dim) { - if (gfc_is_size_zero_array (mask)) - return gfc_get_logical_expr (mask->ts.kind, &mask->where, true); - return simplify_transformation (mask, dim, NULL, true, gfc_and); } @@ -1068,9 +1071,6 @@ gfc_simplify_and (gfc_expr *x, gfc_expr *y) gfc_expr * gfc_simplify_any (gfc_expr *mask, gfc_expr *dim) { - if (gfc_is_size_zero_array (mask)) - return gfc_get_logical_expr (mask->ts.kind, &mask->where, false); - return simplify_transformation (mask, dim, NULL, false, gfc_or); } @@ -1966,15 +1966,11 @@ gfc_expr * gfc_simplify_count (gfc_expr *mask, gfc_expr *dim, gfc_expr *kind) { gfc_expr *result; + bool size_zero; - if (gfc_is_size_zero_array (mask)) - { - int k; - k = kind ? mpz_get_si (kind->value.integer) : gfc_default_integer_kind; - return gfc_get_int_expr (k, NULL, 0); - } + size_zero = gfc_is_size_zero_array (mask); - if (!is_constant_array_expr (mask) + if (!(is_constant_array_expr (mask) || size_zero) || !gfc_is_constant_expr (dim) || !gfc_is_constant_expr (kind)) return NULL; @@ -1987,6 +1983,9 @@ gfc_simplify_count (gfc_expr *mask, gfc_expr *dim, init_result_expr (result, 0, NULL); + if (size_zero) + return result; + /* Passing MASK twice, once as data array, once as mask. Whenever gfc_count is called, '1' is added to the result. */ return !dim || mask->rank == 1 ? @@ -3265,9 +3264,6 @@ do_bit_and (gfc_expr *result, gfc_expr *e) gfc_expr * gfc_simplify_iall (gfc_expr *array, gfc_expr *dim, gfc_expr *mask) { - if (gfc_is_size_zero_array (array)) - return gfc_get_int_expr (array->ts.kind, NULL, -1); - return simplify_transformation (array, dim, mask, -1, do_bit_and); } @@ -3287,9 +3283,6 @@ do_bit_ior (gfc_expr *result, gfc_expr *e) gfc_expr * gfc_simplify_iany (gfc_expr *array, gfc_expr *dim, gfc_expr *mask) { - if (gfc_is_size_zero_array (array)) - return gfc_get_int_expr (array->ts.kind, NULL, 0); - return simplify_transformation (array, dim, mask, 0, do_bit_ior); } @@ -3730,9 +3723,6 @@ do_bit_xor (gfc_expr *result, gfc_expr *e) gfc_expr * gfc_simplify_iparity (gfc_expr *array, gfc_expr *dim, gfc_expr *mask) { - if (gfc_is_size_zero_array (array)) - return gfc_get_int_expr (array->ts.kind, NULL, 0); - return simplify_transformation (array, dim, mask, 0, do_bit_xor); } @@ -5040,43 +5030,6 @@ gfc_min (gfc_expr *op1, gfc_expr *op2) gfc_expr * gfc_simplify_minval (gfc_expr *array, gfc_expr* dim, gfc_expr *mask) { - if (gfc_is_size_zero_array (array)) - { - gfc_expr *result; - int i; - - i = gfc_validate_kind (array->ts.type, array->ts.kind, false); - result = gfc_get_constant_expr (array->ts.type, array->ts.kind, - &array->where); - switch (array->ts.type) - { - case BT_INTEGER: - mpz_set (result->value.integer, gfc_integer_kinds[i].huge); - break; - - case BT_REAL: - mpfr_set (result->value.real, gfc_real_kinds[i].huge, GFC_RND_MODE); - break; - - case BT_CHARACTER: - /* If ARRAY has size zero and type character, the result has the - value of a string of characters of length LEN (ARRAY), with - each character equal to CHAR(n - 1, KIND (ARRAY)), where n is - the number of characters in the collating sequence for - characters with the kind type parameter of ARRAY. */ - gfc_error ("MINVAL(string) at %L is not implemented, yet!", - &array->where); - gfc_free_expr (result); - return &gfc_bad_expr; - break; - - default: - gcc_unreachable (); - } - - return result; - } - return simplify_transformation (array, dim, mask, INT_MAX, gfc_min); } @@ -5096,42 +5049,6 @@ gfc_max (gfc_expr *op1, gfc_expr *op2) gfc_expr * gfc_simplify_maxval (gfc_expr *array, gfc_expr* dim, gfc_expr *mask) { - if (gfc_is_size_zero_array (array)) - { - gfc_expr *result; - int i; - - i = gfc_validate_kind (array->ts.type, array->ts.kind, false); - result = gfc_get_constant_expr (array->ts.type, array->ts.kind, - &array->where); - switch (array->ts.type) - { - case BT_INTEGER: - mpz_set (result->value.integer, gfc_integer_kinds[i].min_int); - break; - - case BT_REAL: - mpfr_set (result->value.real, gfc_real_kinds[i].huge, GFC_RND_MODE); - mpfr_neg (result->value.real, result->value.real, GFC_RND_MODE); - break; - - case BT_CHARACTER: - /* If ARRAY has size zero and type character, the result has the - value of a string of characters of length LEN (ARRAY), with - each character equal to CHAR (0, KIND (ARRAY)). */ - gfc_error ("MAXVAL(string) at %L is not implemented, yet!", - &array->where); - gfc_free_expr (result); - return &gfc_bad_expr; - break; - - default: - gcc_unreachable (); - } - - return result; - } - return simplify_transformation (array, dim, mask, INT_MIN, gfc_max); } @@ -5777,16 +5694,11 @@ gfc_expr * gfc_simplify_norm2 (gfc_expr *e, gfc_expr *dim) { gfc_expr *result; + bool size_zero; - if (gfc_is_size_zero_array (e)) - { - gfc_expr *result; - result = gfc_get_constant_expr (e->ts.type, e->ts.kind, &e->where); - mpfr_set_ui (result->value.real, 0, GFC_RND_MODE); - return result; - } + size_zero = gfc_is_size_zero_array (e); - if (!is_constant_array_expr (e) + if (!(is_constant_array_expr (e) || size_zero) || (dim != NULL && !gfc_is_constant_expr (dim))) return NULL; @@ -5793,6 +5705,9 @@ gfc_simplify_norm2 (gfc_expr *e, gfc_expr *dim) result = transformational_result (e, dim, e->ts.type, e->ts.kind, &e->where); init_result_expr (result, 0, NULL); + if (size_zero) + return result; + if (!dim || e->rank == 1) { result = simplify_transformation_to_scalar (result, e, NULL, @@ -6042,33 +5957,6 @@ gfc_simplify_precision (gfc_expr *e) gfc_expr * gfc_simplify_product (gfc_expr *array, gfc_expr *dim, gfc_expr *mask) { - if (gfc_is_size_zero_array (array)) - { - gfc_expr *result; - - result = gfc_get_constant_expr (array->ts.type, array->ts.kind, - &array->where); - switch (array->ts.type) - { - case BT_INTEGER: - mpz_set_ui (result->value.integer, 1); - break; - - case BT_REAL: - mpfr_set_ui (result->value.real, 1, GFC_RND_MODE); - break; - - case BT_COMPLEX: - mpc_set_ui (result->value.complex, 1, GFC_MPC_RND_MODE); - break; - - default: - gcc_unreachable (); - } - - return result; - } - return simplify_transformation (array, dim, mask, 1, gfc_multiply); } @@ -7386,33 +7274,6 @@ gfc_simplify_sqrt (gfc_expr *e) gfc_expr * gfc_simplify_sum (gfc_expr *array, gfc_expr *dim, gfc_expr *mask) { - if (gfc_is_size_zero_array (array)) - { - gfc_expr *result; - - result = gfc_get_constant_expr (array->ts.type, array->ts.kind, - &array->where); - switch (array->ts.type) - { - case BT_INTEGER: - mpz_set_ui (result->value.integer, 0); - break; - - case BT_REAL: - mpfr_set_ui (result->value.real, 0, GFC_RND_MODE); - break; - - case BT_COMPLEX: - mpc_set_ui (result->value.complex, 0, GFC_MPC_RND_MODE); - break; - - default: - gcc_unreachable (); - } - - return result; - } - return simplify_transformation (array, dim, mask, 0, gfc_add); }