From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 35978 invoked by alias); 30 Oct 2015 13:15:29 -0000 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 Received: (qmail 35944 invoked by uid 89); 30 Oct 2015 13:15:27 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.2 required=5.0 tests=AWL,BAYES_00,KAM_LAZY_DOMAIN_SECURITY,RCVD_IN_DNSWL_LOW,RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: smtp.ispras.ru Received: from smtp.ispras.ru (HELO smtp.ispras.ru) (83.149.199.79) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 30 Oct 2015 13:15:25 +0000 Received: from [10.10.3.121] (unknown [83.149.199.91]) by smtp.ispras.ru (Postfix) with ESMTP id 0BB0820514; Fri, 30 Oct 2015 16:15:22 +0300 (MSK) Date: Fri, 30 Oct 2015 13:27:00 -0000 From: Alexander Monakov To: Bernd Schmidt cc: gcc-patches@gcc.gnu.org, Jakub Jelinek , Dmitry Melnik Subject: Re: [gomp4 04/14] nvptx: fix output of _Bool global variables In-Reply-To: <5631FF4A.5070401@redhat.com> Message-ID: References: <1445366076-16082-1-git-send-email-amonakov@ispras.ru> <1445366076-16082-5-git-send-email-amonakov@ispras.ru> <5626A898.5000703@redhat.com> <5630FE4D.8040803@redhat.com> <56310812.6090402@redhat.com> <56310D12.7040904@redhat.com> <56311014.9000502@redhat.com> <5631FF4A.5070401@redhat.com> User-Agent: Alpine 2.20 (LNX 67 2015-01-07) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-SW-Source: 2015-10/txt/msg03394.txt.bz2 On Thu, 29 Oct 2015, Bernd Schmidt wrote: > On 10/28/2015 08:29 PM, Alexander Monakov wrote: > > > Anything wrong with the simple fix: pick an integer type with the largest > > size > > dividing the original struct type size? > > Try it and run it through the testsuite. The following patch passes testing with make -k check-c DEJAGNU=.../dejagnu.exp RUNTESTFLAGS=--target_board=nvptx-none-run with no new regressions, and fixes 1 test: -FAIL: gcc.dg/compat/struct-align-1 c_compat_x_tst.o-c_compat_y_tst.o execute OK? Thanks. Alexander nvptx: fix chunk size selection for structure types * config/nvptx/nvptx.c (nvptx_ptx_type_for_output): New. Handle COMPLEX_TYPE like ARRAY_TYPE. Drop special handling of scalar types. Fix handling of structure types by choosing integer type that divides original size evenly. Split out from and use it... (init_output_initializer): ...here. diff --git a/gcc/config/nvptx/nvptx.c b/gcc/config/nvptx/nvptx.c index b541666..3a0cac2 100644 --- a/gcc/config/nvptx/nvptx.c +++ b/gcc/config/nvptx/nvptx.c @@ -1692,6 +1692,29 @@ nvptx_assemble_decl_end (void) fprintf (asm_out_file, ";\n"); } +/* Return a type suitable to output initializers for TYPE. */ +static const_tree +nvptx_ptx_type_for_output (const_tree type) +{ + /* Avoid picking a larger type than the underlying type. */ + if (TREE_CODE (type) == ARRAY_TYPE + || TREE_CODE (type) == COMPLEX_TYPE) + type = TREE_TYPE (type); + int sz = int_size_in_bytes (type); + if (sz < 0) + return char_type_node; + /* Size of the output type must divide that of original type. Initializers + with pointers to objects need a pointer-sized type. These requirements + may be contradictory for packed structs, but giving priority to first at + least allows to output some initializers correctly. Here we pick largest + suitable integer type without deeper inspection. */ + return (sz % 8 || !TARGET_ABI64 + ? (sz % 4 + ? (sz % 2 ? char_type_node : short_integer_type_node) + : integer_type_node) + : long_integer_type_node); +} + /* Start a declaration of a variable of TYPE with NAME to FILE. IS_PUBLIC says whether this will be externally visible. Here we just write the linker hint and decide on the chunk size @@ -1705,15 +1728,7 @@ init_output_initializer (FILE *file, const char *name, const_tree type, assemble_name_raw (file, name); fputc ('\n', file); - if (TREE_CODE (type) == ARRAY_TYPE) - type = TREE_TYPE (type); - int sz = int_size_in_bytes (type); - if ((TREE_CODE (type) != INTEGER_TYPE - && TREE_CODE (type) != ENUMERAL_TYPE - && TREE_CODE (type) != REAL_TYPE) - || sz < 0 - || sz > HOST_BITS_PER_WIDE_INT) - type = ptr_type_node; + type = nvptx_ptx_type_for_output (type); decl_chunk_size = int_size_in_bytes (type); decl_chunk_mode = int_mode_for_mode (TYPE_MODE (type)); decl_offset = 0;